首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular alternative $http

Angular alternative $http
EN

Stack Overflow用户
提问于 2015-03-31 13:12:53
回答 2查看 11.5K关注 0票数 13

在发送请求的AngularJS中,我使用内置的$http服务。

我应该使用什么来向Angular中的服务器发送请求?我找不到任何涵盖这个主题的文件。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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就是一个例子...

代码语言:javascript
复制
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);
  }
}
票数 5
EN

Stack Overflow用户

发布于 2015-07-22 10:41:38

简单的http get示例:

代码语言:javascript
复制
http.get('./friends.json').map((res: Response) => res.json()).subscribe(res => this.result = res);

这里有一个可用的示例:http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29361027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档