如何使用angular2(ts)进行AJAX调用? [英] How to make AJAX call with angular2(ts)?

查看:156
本文介绍了如何使用angular2(ts)进行AJAX调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用angular2(ts)进行AJAX调用? 我在angularjs.org上阅读了该教程.但是关于AJAX却一无所获. 因此,我真的很想知道如何使用angular2(ts)进行AJAX调用.

How to make AJAX call with angular2(ts)? I read the tutorial on angularjs.org. But there is nothing about AJAX. So I really want to know how to make AJAX call with angular2(ts).

推荐答案

您将需要查看 api http模块的文档. http 类可以使用AJAX为您获取资源.有关更多示例,请参见Angular HttpClient指南.

import { Component } from '@angular/core';
import { Http } from '@angular/http';

@Component({
  selector: 'http-app',
  templateUrl: 'people.html'
})
class PeopleComponent {
  constructor(http: Http) {
    http.get('people.json')
      // Call map on the response observable to get the parsed people object
      .map(res => res.json())
      // Subscribe to the observable to get the parsed people object and attach it to the
      // component
      .subscribe(people => this.people = people);
  }
}

这篇关于如何使用angular2(ts)进行AJAX调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆