我有一个非常简单的问题,我无法将一个简单的布尔值转换为 TypeScript中的字符串值.
我一直漫游文档,我找不到任何有用的东西,当然我试图使用该toString()方法,但它似乎没有在bool上实现.
编辑:我几乎没有JavaScript知识,并且使用C#/ Java背景来到TypeScript.
我一直在玩Angular 2 Quickstart.如何在Angular 2中使用/导入http模块?
我看过Angular 2 Todo的.js,但它没有使用http模块.
我已经在package.json中添加"ngHttp": "angular/http",了dependencies,因为我听说Angular 2有点模块化
所以,我正在通过打字稿在他们的网站上关注角度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) 我在本地计算机上运行了独立的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) 我希望每个人都做得很好.我最近开始使用angular 4.4,我一直试图将数据发布到我的api服务器,但不幸的是它没有用.我花了两天时间,但仍然没有成功.并且已经尝试过6-7篇甚至来自angular.io的文章.我已经尝试了Http和Httpclient模块,但似乎没有任何工作.
问题是,每当我尝试将数据发布到我的服务器时,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¶m2=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
我有下面的代码:
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) 缺少必需的参数:在 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 时,它运行良好
angular ×5
javascript ×2
angular-http ×1
casting ×1
forms ×1
http ×1
http-post ×1
input ×1
ionic2 ×1
java ×1
keycloak ×1
login ×1
typescript ×1