在发送请求的AngularJS中,我使用内置的$http服务。
我应该使用什么来向Angular中的服务器发送请求?我找不到任何涵盖这个主题的文件。
发布于 2015-06-22 23:16:37
编辑:现在在Angular 2 website上有一个新的http服务的api preview
目前在Angular 2中有一个基本的http service,但现在它非常简约。该软件是alpha版本,并且很可能会发生变化,因此您可能只想使用fetch API,实现您自己的XMLHttpRequest,或者使用像jQuery这样的库。目前,Angular 2HttpAPI基本上与fetch API相同。考虑到fetch不太可能发生变化,我建议直接使用它。
如果你想使用Angular 2服务,here就是一个例子...
import {bootstrap, Component, View, NgFor, Inject} from 'angular2/angular2';
import {Http, httpInjectables} from 'angular2/http';
@Component({selector: 'http-app'})
@View({
directives: [NgFor],
template: `
<h1>people</h1>
<ul class="people">
<li *ng-for="#person of people">
hello, {{person.name}}
</li>
</ul>
`
})
export class HttpCmp {
people: Object;
constructor(http: Http) {
http.get('./people.json').toRx().map(res => res.json()).subscribe(people => this.people = people);
}
}发布于 2015-07-22 10:41:38
简单的http get示例:
http.get('./friends.json').map((res: Response) => res.json()).subscribe(res => this.result = res);这里有一个可用的示例:http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http
https://stackoverflow.com/questions/29361027
复制相似问题