当我通过点击链接导航到我的控件时,页面(绑定属性)有时不会更新。通常这是我第一次点击链接。后续点击工作正常。浏览器报告没有错误。代码中的断点显示代码正常执行 这闻起来像是时间问题。我正在处理正确的事件吗?可能与:https://github.com/angular/angular/issues/7576
有关当我通过在浏览器中键入或粘贴网址导航到我的控件时,页面永远不会更新。浏览器报告没有错误。代码中的断点显示代码正常执行。
blogDetail.ts
@Component({
selector: 'blog-blog-detail',
templateUrl: './app/blog/blogDetail.html'
})
export class BlogDetail {
PostRoot = this.sessionService.PostRoot;
private Post: ContentItem;
private Content: string;
constructor(private sessionService: SessionService, private blogService: BlogService) {
this.Post = new ContentItem();
this.Content = "";
}
routerOnActivate(data: RouteSegment)
{
let slug = data.getParam('slug');
if (slug === null || typeof slug === 'undefined')
return;
this.blogService.GetContentItemBySlug(slug, this.sessionService.CurrentSite.ID).subscribe(x => {
this.Post = x;
this.blogService.GetPostHtml(this.sessionService.PostRoot + this.Post.URL).subscribe((h: string) => {
this.Content = h;
});
});
}
}
blogDetail.html
<div>
<h1>this is blog detail</h1>
{{Post.Title}}
<div [innerHTML]="[Content]"></div>
</div>
根据Arpits修订评论:
routerOnActivate(data: RouteSegment)
{
let slug = data.getParam('slug');
if (slug === null || typeof slug === 'undefined')
return;
this.Post = this.blogService.GetContentItemBySlug(slug, this.sessionService.CurrentSite.ID);
//.subscribe(x => {
// this.Post = x;
// this.blogService.GetPostHtml(this.sessionService.PostRoot + this.Post.URL).subscribe((h: string) => {
// this.Content = h;
// });
//});
this.Post.subscribe(x => { // null error here
this.Content = this.blogService.GetPostHtml(this.sessionService.PostRoot + x.URL);
});
}