Search code examples
javascriptangularangular5ngmodel

Angular 5 ngModel doesn't update value


I have the following component:

export class ModuleComponentComponent implements OnInit {
    dropzoneConf;
    fileService = environment.getFileUrl;

    constructor(
        private moduleComponentService: ModuleComponentService) {
    }

    @Input()
    selectedComponent: ModuleComponent;

    ngOnInit() {
        this.setDropZoneConfig();
    }    
}

And in that I have the following HTML:

<h3 class="m-portlet__head-text m--font-success">
   <input class="form-control" type="text" [ngModel]="selectedComponent.title" />
</h3>

and the way I add the component in my HTML:

<div class="col-lg-8 col-x1-12" *ngIf="selectedComponent != null">
   <app-module-component [selectedComponent]="selectedComponent"></app-module-component>
</div>

When I type something into the input field it doesn't update the selectedComponent.title variable

What might be going on?


Solution

  • Use the two way binding

     [(ngModel)]="selectedComponent.title"