我在这个网站上看到了很多关于这个问题的类似问题,但它们要么太具体(使用Django、Python、Spring等),要么太过时了。
我正在使用Angular 5和Bootstrap,使用Chrome进行调试,但是我的GET请求没有得到,或者给我任何错误,或者做任何事情,真的。在零输出的情况下,我不确定我做错了什么。
我的.ts文件代码:
onNameKeyUp(event:any) {
this.id = event.target.value; //sets input to the object's id
this.found = false;
}
getProf() {
this.httpClient.get(`api_url/${this.id}`)
.subscribe(
(data:any[]) => {
if(data.length) {
this.name = data[0].name;
this.id = data[0].id;
this.found = true;
}
}
)
}我的component.html代码:
<input type="text" (keyup)="onNameKeyUp($event)">
<button type="button" (click)="getProf()">Get Profile</button>
<div *ngIf="found">
<div>{{this.name}}'s id is {{this.id}}</div>
</div>https://stackoverflow.com/questions/51199235
复制相似问题