我有以下组件:
export class ModuleComponentComponent implements OnInit {
dropzoneConf;
fileService = environment.getFileUrl;
constructor(
private moduleComponentService: ModuleComponentService) {
}
@Input()
selectedComponent: ModuleComponent;
ngOnInit() {
this.setDropZoneConfig();
}
}
我有以下 HTML:
<h3 class="m-portlet__head-text m--font-success">
<input class="form-control" type="text" [ngModel]="selectedComponent.title" />
</h3>
以及我在 HTML 中添加组件的方式:
<div class="col-lg-8 col-x1-12" *ngIf="selectedComponent != null">
<app-module-component [selectedComponent]="selectedComponent"></app-module-component>
</div>
当我在输入字段中输入内容时,它不会更新 selectedComponent.title
变量
可能发生什么情况?
最佳答案
使用双向绑定(bind)
[(ngModel)]="selectedComponent.title"
关于javascript - Angular 5 ngModel 不更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837261/