gpt4 book ai didi

angular - 如何使用 angular2(ts) 进行 AJAX 调用?

转载 作者:太空宇宙 更新时间:2023-11-04 02:08:47 24 4
gpt4 key购买 nike

如何使用 angular2(ts) 进行 AJAX 调用?我阅读了 angularjs.org 上的教程。但AJAX方面却没有任何内容。所以我真的很想知道如何使用 angular2(ts) 进行 AJAX 调用。

最佳答案

您将需要查看api docs for the http modulehttp类可以使用AJAX为您获取资源。请参阅 Angular HttpClient Guide了解更多示例。

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);
}
}

关于angular - 如何使用 angular2(ts) 进行 AJAX 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43200008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com