无法读取null的属性“出口" [英] Cannot read property 'outlets' of null
本文介绍了无法读取null的属性“出口"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下一个问题:Cannot read property 'outlets' of null
.我的项目可以运行,但是一段时间后它停止工作,但是我没有更改代码.请帮帮我.
更新
我的带有路由器插座的组件:
I have next problem : Cannot read property 'outlets' of null
. My project works, but after some time it stopped working, but i didn't change my code. Help me please.
Update
My component with router-outlet:
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: '
<nav-menu></nav-menu>
<router-outlet></router-outlet>
<footer-component></footer-component>
',
})
export class AppComponent {}
app.module:
app.module:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { LocationStrategy, PathLocationStrategy, APP_BASE_HREF } from '@angular/common';
import { HttpModule } from '@angular/http';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
//+components
@NgModule({
imports:
[
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forRoot([
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'blog', component: BlogComponent },
{ path: '2016/:link', component: BlogArticleFullComponent },
{
path: 'admin', component: AdminComponent,
children: [
{ path: 'new', component: NewArticleComponent },
{ path: 'new-writer', component: NewWriterComponent },
{ path: 'new-tag', component: NewTagComponent }
] },
{ path: '**', redirectTo: '', pathMatch: 'full'}
])
],
declarations:
[//components
],
bootstrap:
[
AppComponent
],
providers:
[
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: LocationStrategy, useClass: PathLocationStrategy }
]
})
export class AppModule { }
P.S.因为有stackoverflow``-是代码,所以对引号有引号.
P.S. There is ' quote against ` because stackoverflow ``-is code.
推荐答案
供以后参考:将[routerLink]
与看起来像['/foo', null]
的数组一起使用时,出现此错误.通过提供一个对象而不是null
对其进行了修复.
For future reference: I got this error when using [routerLink]
with an array which looked like ['/foo', null]
. Fixed it by supplying an object instead of null
.
这篇关于无法读取null的属性“出口"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文