Angular4 Exception: Can't bind to 'ngClass' since it isn't a known property of 'input'
Since RegisterComponent
was declared in RegisterRouter
(what's the name for module?) module then you have to import CommonModule
there:
@NgModule({
imports: [
RouterModule.forChild(routes),
FormsModule,
ReactiveFormsModule,
CommonModule <================== this line
],
declarations: [
RegisterComponent // this component wants to have access to built-in directives
],
exports: [RouterModule]
})
export class RegisterRouter { }
For anyone who's still having these issue even after importing CommonModule
I had a library that I just could not get to compile. I had several modules.. which were importing other smaller/components:
One of the components in one of my smaller modules had [ngClass] in it.. it would cause lib to not compile and throw Can't bind to 'ngClass' since it isn't a known property of 'div'
Apparently... i was exporting all my components for that modules... but not the module itself in the public-api.ts
file (the module that did the import of CommonModule):
export * from './lib/af-layout/af-layout.module'; // <==== THAT WAS MISSING
export * from './lib/af-layout/components/af-layout-header/af-layout-header.component';
It took me a long time to find that.. as the error was directing me towards CommonModule not being imported.. not that an export was missing.
Lazy Loading Share module issue common solution:
Both module must import
CommonModule
In shared module:
@NgModule({
imports: [CommonModule],
...
})
Module where you want to use component:
@NgModule({
imports: [CommonModule, ...],
...
})