在LandingComponent上找不到指令注释

时间:2016-07-20 09:52:45

标签: angular

import { Component } from 'angular2/core'; 

import { Router } from 'angular2/router';    

import { RouteConfig } from 'angular2/router';   

import { ROUTER_DIRECTIVES } from 'angular2/router';   

import { LandingComponent } from './landing.component';     

@RouteConfig([    

  {path: '/landing', name: 'Landing', component: LandingComponent}, 

  {path: '/*other', name: 'Other', redirectTo: ['Landing']}    

])         

@Component({     

  selector: 'cwf',    

  templateUrl: 'app/template/index.template.html',  

  directives: [ROUTER_DIRECTIVES]     

})    

export class AppComponent {    

  constructor(private _router:Router){

  }     

  browserObject = BrowserDetect;

  navigator =  navigator.javaEnabled() ? "enabled" : "disabled";  

  listBrowser = BrowserDetect.supportedBrowser;    

  ngOnInit(){    

    let timer = Observable.timer(2000); 

    timer.subscribe(this.navigate);   

  };    

  navigate = () => {  

    this._router.navigate(['Landing']);  

  };      

}

// Landing...    

import { Component } from 'angular2/core';

@Component({

  selector: 'landing',

  templateUrl: 'app/template/landing.template.html'

});

export class LandingComponent {


}

2 个答案:

答案 0 :(得分:1)

我认为这是因为您的代码中;位于@Component类的LandingComponent装饰器之后:

import { Component } from 'angular2/core';

@Component({
  selector: 'landing',
  templateUrl: 'app/template/landing.template.html'
}); // <-----
export class LandingComponent {

}

删除它应该可以解决您的问题......

答案 1 :(得分:0)

;末尾有一个多余的@Component(...); /* <<<=== */ export class LandingComponent { }。装饰者与他们正在装饰的班级之间必须没有;

同样在https://stackoverflow.com/a/38454820/217408

回答