我正在使用beta-0和hashlocationstrategy,但是当我输入这个url localhost /#/ searchh时,我的配置中没有注册, 和错误显示
EXCEPTION: TypeError: Cannot read property 'toUrlPath' of null
routeconfig:
@RouteConfig([
{path: '/' , name: 'Home', component: HomeComponent },
{path: '/search', name: 'Search', component: SearchComponent },
{ path: '/project/:id', name: 'Project', component: ProjectComponent },
])
即使我在我的' /'中使用redirectTo路径,它仍然显示消息,什么是错的?
更多的问题是进入/#/ project / 1232132,这比我有的多,似乎显示模板,但空的细节,因为我只有3个项目,它应该工作/#/ project / 3,如何我能解决这个问题吗?在ng2中创建错误页面? 错误信息是
EXCEPTION: TypeError: Cannot read property 'title' of undefined in [{{project.title}} in ProjectComponent@0:52]
答案 0 :(得分:1)
EXCEPTION:TypeError:无法读取ProjectComponent @ 0中的[{{project.title}}中未定义的属性'title':52]
我用ngIf解决了它:
<h2 *ngIf="project">{{project.title}}</h2>
编辑: 或者如Günter和Pardeep建议的那样,你可以用elvis算子来做到这一点:
<h2>{{project?.title}}</h2>