【发布时间】:2020-04-19 11:45:05
【问题描述】:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
enableProdMode();
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
values: any = {};
constructor(private http: HttpClient) { }
ngOnInit() {
this.getValues();
console.log(this.values);
}
getValues()
{
this.http.get('http://localhost:5000/api/values').subscribe(Response => { this.values = Response},error => {console.log(error);
});
}
}
我可以从 HTTP 响应中获取值。但我无法将这些值存储在“值”对象中。得到空数组。
【问题讨论】:
标签: angular typescript tslint