是的,还有其他类似的问题,但我的场景是不同的,因为我的应用程序的结构。
基本上,我收到了这个错误:
例外:模板解析错误:无法绑定到'routerLink‘,因为它不是已知的原生属性(menuItems的“or=”#item;menuItems;
我决定把路由器声明基本上放在所有涉及的文件中,以确保这不会缺少声明的指令。
我的应用程序结构是这样的:
app.component :在我的路由器出口所在的html中调用一个主模板.navbar.component -是放置路由器链路的位置,并导致错误。
room.component -如果成功的话,应该调用的组件。
app.component -代码:
import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {RouterOutlet} from 'angular2/router';
import {RouterLink} from 'angular2/router';
import {NavBarComponent} from './components/navBar/navbar.component';
import {RoomsComponent} from './components/rooms/rooms.component';
@Component({
selector: 'my-app',
directives : [NavBarComponent,RoomsComponent,ROUTER_DIRECTIVES],
templateUrl : 'app/templates/master.html'
})
@RouteConfig([
{path:'/rooms', name: 'Rooms', component: RoomsComponent, useAsDefault: true}
])
export class AppComponent { }navbar.component -代码:
import {Component} from 'angular2/core';
import {RouterLink} from 'angular2/router';
import {RouterOutlet} from 'angular2/router';
@Component({
selector: 'nav-bar',
template : `<ul>
<li *ngFor="#item of menuItems; #i=index"><a
[ngClass]="{active: activeIndex ==i}" (click)= "navigateTo(i)"
[routerLink]="['Rooms']"> {{item.label}}</a></li>
<div class="exit"><i class="material-icons md-48">exit_to_app</i> </div>
</ul>
`,
})
export class NavBarComponent {
menuItems = [
{
label : 'Rooms',
pointsTo : 'Rooms'
},
{
label : 'Bookings',
pointsTo : 'Bookings'
},
{
label : 'Favourites',
pointsTo : 'Favourites'
}
];
activeIndex = 0;
constructor() {
this.navigateTo = function(ndx){
this.activeIndex = ndx;
}
}
}rooms.component -代码
import {Component} from 'angular2/core';
import {Router, RouteParams} from 'angular2/router';
import {RouterOutlet} from 'angular2/router';
import {RouterLink} from 'angular2/router';
@Component({
selector : 'rooms',
template : `
<h1>I'm the room !</h1>`,
})
export class RoomsComponent {
}master.html -代码:
<div class="appContainer">
<div class="appTop">
<div class="logo">
<logo></logo>
</div>
<div class="navBar">
<nav-bar></nav-bar>
</div>
<div class="mobileMenu">
mobile menu
</div>
</div>
<div class="appContent">
<div class="searchArea">
Search
</div>
<div class="subjectArea">
<router-outlet></router-outlet>
</div>
</div>
</div>main.ts -代码:
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {AppComponent} from './app.component';
bootstrap(AppComponent, [ROUTER_PROVIDERS]);发布于 2016-03-04 11:07:22
export class NavBarComponent {丢失了ROUTER_DIRECTIVES
@Component({
selector: 'nav-bar',
directives : [ROUTER_DIRECTIVES],
template : `<ul>
<li *ngFor="#item of menuItems; #i=index"><a
[ngClass]="{active: activeIndex ==i}" (click)= "navigateTo(i)"
[routerLink]="['Rooms']"> {{item.label}}</a></li>
<div class="exit"><i class="material-icons md-48">exit_to_app</i> </div>
</ul>
`,
})
export class NavBarComponent {就像你在AppComponent里有
https://stackoverflow.com/questions/35794306
复制相似问题