Angular 刷新绑定上的角度2未定义
应用程序组件:Angular 刷新绑定上的角度2未定义,angular,angular2-template,Angular,Angular2 Template,应用程序组件: @RouteConfig([ {path:'/', name: 'Dashboard', component: DashboardComponent, useAsDefault: true}, {path:'/model/:id', name: 'ModelDetail', component: ModelDetailComponent}, ]) 访客可直接访问: 在呈现“ModelDetailComponent”之前,我们需要加载类ngOnInit()中的所有模型
@RouteConfig([
{path:'/', name: 'Dashboard', component: DashboardComponent, useAsDefault: true},
{path:'/model/:id', name: 'ModelDetail', component: ModelDetailComponent},
])
访客可直接访问:
在呈现“ModelDetailComponent”之前,我们需要加载类ngOnInit()中的所有模型
模板:
<h1>{{model.name}}</h1>
<model-list [model]="model"></model-list> //nested compnent that also use the model.
我想你要找的是钩子。它将允许您在解析数据之前等待组件渲染(类似于Angular 1.x resolve功能) 有关更多详细信息,请参阅。只需使用
<h1>{{model?.name}}</h1>
我想是的,但如果不能繁殖,这是很困难的。如果你能提供一个Plunker,我可以验证这是否真的解决了你的问题。目前这只是一个猜测。你试过我的建议吗?它是有效的,但问题是我必须在“RouteConfig”上用于特定URL的每个组件上都这样做!问题是每个组件在呈现组件之前都需要json文档。因此,我必须明确地在每个组件中添加“if switch”,我认为这仍然是使组件异步兼容的最佳方法。通常不是每个异步调用都是由导航和路由更改引起的。是的,它将等待页面加载,直到数据到达,我想这首先是你的问题,对吗?@JamalJames cool,请将我的解决方案标记为答案,如果它解决了你的问题,我刚才做了@YanivEfraim@JamalJames酷!您可以在“V”符号上标记,以便人们知道这是您的正确答案(:
public model:IModel;
<h1>{{model?.name}}</h1>
@Component({
selector: 'my-component',
template' `
<div *ngIf="model">
<h1>{{model.name}}</h1>`})
<div>
class MyComponent { }