Angular2 報錯集合--持續更新

  1. Can't bind to 'ng-forOf' since it isn't a known native property

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 {

}
複製代碼
  1. Can't bind to 'routerLink' since it isn't a known property of 'a' [duplicate]

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 { }
複製代碼
相關文章
相關標籤/搜索