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).
You will want to look at the api docs for the http module. The http class can get resources for you using AJAX. See the Angular HttpClient Guide for more examples.
http
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); } }
2.1m questions
2.1m answers
60 comments
57.0k users