ngModel and #firstName always fails with ". . not assignable to . ."

Working through Mosh’s course on the ngModel lecture I’m getting the following error:

Argument of type ‘NgModel’ is not assignable to parameter of type ‘string’.

This is happening whenever I add change detection output.


To this:

<input ngModel name="firstName" #firstName="ngModel" id="firstName" type="text" class="form-control">

I’m stumped on how to move forward. Suggestions welcome.


Fixed. The issue was in the component.ts:

log( msg : string ) {
    console.log( msg );

The template variable #firstName is an object (not a string).

To show the value of the template variable use:


or be prepared for an object to be passed to the log() function.

Second update for completeness.

As the template variable type isn’t known I found it required to specify the variable type any otherwise an error would occur (Parameter ‘msg’ implicitly has an ‘any’ type.)

log( msg : any ) {
    console.log( msg );