- I've created npm package
sezam-shareds - Install package to new Project
- Added component from this package:
<sezam-overflow [show]="true"></sezam-overflow>to component in project - An error occurs in browser console:
core.js:9847 NG0303: Can't bind to 'ngIf' since it isn't a known property of 'div'
Content of html in package:
<div *ngIf="show">
...
</div>
Content of html in project:
<sezam-overflow [show]="true"></sezam-overflow>
Component in package:
import { Component, Input, Output, EventEmitter, OnChanges, forwardRef } from '@angular/core';
@Component({
selector: 'sezam-overflow',
templateUrl: `sezam-overflow.component.html`,
})
export class SezamOverflowComponent {
@Input() show = false;
constructor() {}
}
How fix error? Can't bind to 'ngIf'
If you would like to install a package, you need to add postintall script to package.json:
"postinstall": "ngcc"
CodePudding user response:
this error is not related to the component. just add the below code to your module
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
your final code like this
@NgModule({
imports: [CommonModule,BrowserModule ],
declarations: [SezamOverflowComponent]
})
class AppModule {}
CodePudding user response:
4 things to check:
- What module declares the
SezamOverflowComponent? - Does this modules
exportscontain theSezamOverflowComponent? (I'll just assume you called thisSezamOverflowModule...) - What component are you using the
<sezam-overflow>on? What module declares this component? (Assume XxMidule...) - This
XxMiduleshould import theSezamOverflowModule
