加载数据的角度代码
constructor(private http: HttpClient , private _title: Title,
private _meta: Meta) {
this.facts = this.http.get('https://non-ssr-angular.firebaseio.com/facts.json');
this.posts = this.http.get(`${this.baseURL}/api/post/ByMemberAsync/0/None`);
}
列出返回API的代码
<ul>
<li *ngFor="let fact of facts | async">
{{fact.text}}
</li>
</ul>
<ul>
<li *ngFor="let post of posts | async">
{{post.title}}
</li>
</ul>
<!-- end snippet ->
When I view source through the browser it shows list only from (https://non-ssr-angular.firebaseio.com/facts.json) and wen API response show empty.
Output
<!-- begin snippet: js hide: false console: true babel: false -->
&#13;
请帮助任何人解决问题
答案 0 :(得分:0)
你能尝试这样吗,你可能会在视图源中获得元素
<ul *ngIf="posts">
<li *ngFor="let post of posts | async">
{{post?.title}}
</li>
</ul>
答案 1 :(得分:0)
确保
你app.module.ts中的
import { HttpClientModule} from '@angular/common/http'
@NgModule({
declarations: [
...
],
imports: [
....
HttpClientModule,
],
providers: [...],
bootstrap: [AppComponent]
})
在你的component.ts
中import {HttpClient} from '@angular/common/http';
...
export class myComponent {
facts:any;
posts:any;
constructor(..){}
它为我工作:Angular CLI版本(1.6.6)
答案 2 :(得分:0)
if (name_list.includes(text_to_be_checked) ) {}