With Angular 2.1.0+ It seems this is the same except you should import the BrowserModule in your app module and import CommonModule in others (you can't import BrowserModule twice with routes lazy-loading).bash
With Angular 2 rc5 : This version introduced NgModules, you need to import BrowserModule in your module(s) in order to use ngFor, and ngIf:app
import { NgModule } from "@angular/core"
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
exports: [VoteTakerComponent],
imports: [BrowserModule],
})
export class VoteTakerModule {
}
複製代碼
The problem is that you forgot to add RouterModule to your NgModule component. In the RC this was added to the @Component({directives: [ROUTER_DIRECTIVES]}), however, this is now moved into @NgModule({ imports: [RouterModule]}).ui
So, you will get the RouterLink either this way, or via direct import into imports property of @NgModule.this
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { JueJin } from '../juejin/juejin.component'
export const routes: Routes = [
{ path: 'juejin', component: JueJin },
];
@NgModule({
exports: [RouterModule]
})
export class AppRoutingModule { }
複製代碼