当我点击以下锚标记
时 <h4><a [routerLink]="['/demo/article',article._id]">{{article.articletitle}}</a></h4>
,将显示一篇文章(位于另一个ts.file中),但有时无法显示,在某些情况下会刷新显示。我认为这是因为ngonint()只在刷新后显示?我不确定我的问题.....任何人都可以建议帮助..........
article.ts,
route.params.subscribe(p => { this.id = p['id'] });
ngOnInit():any{
this.showarticles = true;
this.showform = false;
var headers = new Headers();
headers.append('Content-Type', 'application/json')
this.http.get(this.header1+'api/auth/getarticlebyid/'+this.id,{ headers: headers })
.subscribe(
response => {
if (response.json().error_code == 0) {
this.articles = response.json().result;
} else {
this.toastr.error('Old Password is not correct');
}
});
我的模板,
<div class="col-sm-12 nopadding topmargin-lg" *ngFor = 'let article of articles'>
<div class="form-group">
<div class="heading-block nobottommargin noborder">
<h4>{{article.articletitle}}</h4>
<span>{{article.articledescription}}</span>
<h5 class="nobottommargin">{{article.tags}}</h5>
</div>
</div>