无法读取 null 的属性“插座" [英] Cannot read property 'outlets' of null
本文介绍了无法读取 null 的属性“插座"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下一个问题:无法读取 null 的属性 'outlets'
.我的项目有效,但一段时间后它停止工作,但我没有更改我的代码.请帮帮我.
更新
我的带有路由器插座的组件:
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 {}
应用模块:
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 { }
附言' 引用了 ` 因为 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屋!
查看全文