相关疑难解决方法(0)

TypeScript:将bool转换为字符串值

我有一个非常简单的问题,我无法将一个简单的布尔值转换为 TypeScript中的字符串值.

我一直漫游文档,我找不到任何有用的东西,当然我试图使用该toString()方法,但它似乎没有在bool上实现.


编辑:我几乎没有JavaScript知识,并且使用C#/ Java背景来到TypeScript.

casting type-conversion typescript

52
推荐指数
3
解决办法
6万
查看次数

Angular 2:如何使用/导入http模块?

我一直在玩Angular 2 Quickstart.如何在Angular 2中使用/导入http模块?
我看过Angular 2 Todo的.js,但它没有使用http模块.

我已经在package.json中添加"ngHttp": "angular/http",dependencies,因为我听说Angular 2有点模块化

angular2-http angular

42
推荐指数
6
解决办法
8万
查看次数

使用带有角度2的http rest apis

所以,我正在通过打字稿在他们的网站上关注角度2指南,并且我陷入了http api集成.我正在尝试创建一个简单的应用程序,可以通过soundcloud api搜索一首歌,但是我很难实现和理解如何开始,而且在线资源以很多不同的方式完成它(我相信快速的角度2语法更改)早些时候).

所以目前我的项目看起来像这样

app
  components
    home
      home.component.ts
      ...
    search
      search.component.ts
      ...
    app.ts
    ...
  services
    soundcloud.ts
  bootstrap.ts
index.html
Run Code Online (Sandbox Code Playgroud)

在示例中没有任何花哨的东西,主要文件将是

app.ts

import {Component, View} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';

import {HomeComponent} from './home/home.component';
import {SearchComponent} from './search/search.component';

@Component({
    selector: 'app',
    templateUrl: 'app/components/app.html',
    directives: [ROUTER_DIRECTIVES]
})

@RouteConfig([
  {path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true},
  {path: '/search', name: 'Search', component: SearchComponent}
])

export class App { }
Run Code Online (Sandbox Code Playgroud)

bootstrap.ts

    import {App}     from './components/app';
import {bootstrap}        from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router'; …
Run Code Online (Sandbox Code Playgroud)

javascript http angular

32
推荐指数
2
解决办法
5万
查看次数

Keycloak缺少表单参数:grant_type

我在本地计算机上运行了独立的keycloak。

我创建了一个名为“ spring-test”的新领域,然后创建了一个名为“ login-app”的新客户端

根据其余文档:

POST: http://localhost:8080/auth/realms/spring-test/protocol/openid-connect/token

{
    "client_id": "login-app",
    "username": "user123",
    "password": "pass123",
    "grant_type": "password"
}
Run Code Online (Sandbox Code Playgroud)

应该给我jwt令牌,但是我收到了错误的请求并做出了回应

{
    "error": "invalid_request",
    "error_description": "Missing form parameter: grant_type"
}
Run Code Online (Sandbox Code Playgroud)

我假设我的配置中缺少某些内容。

编辑:我正在使用json正文,但它应该是形式url编码:以下正文有效:

token_type_hint:access_token&token:{token}&client_id:{client_id}&client_secret:{client_secret}
Run Code Online (Sandbox Code Playgroud)

java authentication login keycloak

15
推荐指数
4
解决办法
7423
查看次数

Angular 4 Http POST无效

我希望每个人都做得很好.我最近开始使用angular 4.4,我一直试图将数据发布到我的api服务器,但不幸的是它没有用.我花了两天时间,但仍然没有成功.并且已经尝试过6-7篇甚至来自angular.io的文章.我已经尝试了HttpHttpclient模块,但似乎没有任何工作.

问题是,每当我尝试将数据发布到我的服务器时,Angular都会生成http OPTIONS类型请求而不是 POST.

this.http.post('http://myapiserver.com', {email: 'adam@example.com'}).subscribe(
    res => {
        const response = res.text();
    }
);
Run Code Online (Sandbox Code Playgroud)

我也试图发送请求的自定义选项,但仍然没有成功.

const headers = new Headers({ 'Content-Type': 'x-www-form-urlencoded' });
const options = new RequestOptions({ headers: headers });
options.method = RequestMethod.Post;
options.body = {name: 'Adam Smith'};
//options.body = JSON.stringify({name: 'Adam Smith'}); // i also tried this
//options.body = 'param1=something&param2=somethingelse'; // i also tried this
Run Code Online (Sandbox Code Playgroud)

我使用的是ASP.NET核心2.0,但由于它不起作用我也试过简单的PHP代码,这里是php的服务器端代码.它也没有用.

<?php
print_r($_POST);
?>
Run Code Online (Sandbox Code Playgroud)

注意:Cors也在服务器上启用.另外,我也试过简单的get请求,它的工作非常好.

我真的很感激一些帮助.

提前致谢

javascript http-post angular-http angular angular-httpclient

6
推荐指数
2
解决办法
3万
查看次数

更新作为 Angular2 中 formArray 中的文件输入的 formControl

我有下面的代码:

import { Component, OnInit, ElementRef } from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'

@Component({
  selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  showSort: boolean = false;
  form: FormGroup;
  name: FormControl;
  sortSelf: FormControl;
  sortItem: FormArray;
  locationItems: FormArray;

  constructor(private _fb: FormBuilder, private _elementRef: ElementRef ) {
  }

  ngOnInit(): void {
    this.sortItem = this._fb.array([this.initSort()]);

    this.form = this._fb.group({
      sortItem: this.sortItem
    });
  }

  initSort() {
    return this._fb.group({
      locationPicture: new FormControl('', []),
      locationItems: this._fb.array([
        this.initSortItems() …
Run Code Online (Sandbox Code Playgroud)

forms input angular

5
推荐指数
1
解决办法
1万
查看次数

缺少必需的参数:在 ionic2 中访问 google 令牌时 grant_type

缺少必需的参数:在 ionic2 中访问 google 令牌时 grant_type

错误:-

{
  "error" : "invalid_request",
  "error_description" : "Required parameter is missing: grant_type"
}
Run Code Online (Sandbox Code Playgroud)

代码

    let creds=JSON.stringify({
        'client_id':'251059024984-8113pdtb11gm8m4evdq59stlpvcab8cn.apps.googleusercontent.com',
        'client_secret':'uVWZt_Vd5mMLXGQDo7lmAIUe',
        'redirect_uri':'http://localhost/callback',
        'grant_type':'authorization_code',
        'code':data
    });
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    console.log(data)


    this.http.post('https://accounts.google.com/o/oauth2/token',creds,{headers: headers}).map(res => res.json()).subscribe(data => {
        console.log(data)
    },(error)=>{
        console.log('error in', error);
    })
Run Code Online (Sandbox Code Playgroud)

当我检查 Postman 中的 api 时,它运行良好

在此处输入图片说明

ionic-framework ionic2 angular

4
推荐指数
1
解决办法
2574
查看次数