Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No provider for NgModel! while creating Structural directive

I created an structural directive. Here is the constructor of that class.

constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, public query: NgModel) {
    console.log(this.query)
}

If I remove public query:NgModel, it works fine. If I add it It throws error.

Error: Uncaught (in promise): No provider for NgModel! (ControlMeta -> NgModel)

What is the error here?

I did same for normal directive, it is working fine.

like image 245
Laxmikant Dange Avatar asked Jul 29 '16 11:07

Laxmikant Dange


1 Answers

You have to specify NgModel as provider:

@Directive({ 
  selector: '...',
  providers: [NgModel],
  ...
})
like image 148
Andrei Zhytkevich Avatar answered Oct 07 '22 04:10

Andrei Zhytkevich