여기에 각도가 있고 완전히 빠진 것에 익숙하지 않습니다. 필자는 docs를 따르는 요청을하고 이전 게시물의 도움을 얻기 위해 구성 요소를 설정했습니다 :) 이제 결과를 템플릿에 전달하는 방법이 누락 되었습니까? 각도 HttpClient 결과를 템플릿에 전달하는 방법
이
내 구성 요소입니다import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-emails',
templateUrl: './emails.component.html',
styleUrls: ['./emails.component.scss']
})
export class EmailsComponent implements OnInit {
test = 'test';
results: string[];
constructor(private http: HttpClient) { }
ngOnInit() {
interface ItemsResponse {
results: string[];
}
this.http.get<ItemsResponse>('assets/api/email_list.json').subscribe(data => {
this.results = data['results'];
console.log(this.results);
});
}
}
내 템플릿은 매우 간단하다 :
<p>results</p>
<p>{{test}}</p>
<p>
{{results}}
</p>
각도에 AngularJS와 학습에서의 전환을 만드는 것은 나를 벽에 머리를 쾅하고있다 보인다 이리!
JSON 형식 :
[
{
"pk": "wGR",
"created": "2017-10-07T01:42:25.110747Z",
"email_domain": "domain.com",
"sender_name": null,
"sender_email": "jobsearch[email protected]",
"has_user_viewed": false,
"is_shielded": false
}
]
를? 즉, 정의되지 않은 문제를 피하기 위해 결과를 빈 배열로 초기화해야합니다 :'results : string [] = []'. 즉,이 템플릿 자체는 그다지 효과가 없을 것입니다. 원래 목표는 무엇입니까? 어쨌든 템플릿은 자동으로 업데이트됩니다 ** **이 경우에는 걱정할 필요가 없습니다. – briosheje
콘솔이 정의되지 않은 것으로 표시되고 있습니다 ... –
1 결과 : 배열 2 : {{결과 | json}} 응답 json 배열을 얻을 것이다. 단지 실행하는 것입니다. –