javascript - Angular 5 ngModel 不更新值

标签 javascript angular angular5 ngmodel

我有以下组件:

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/

相关文章:

javascript - append.html jquery 与现有 html 的工作方式不同吗?

javascript - 以 ionic 滑动问题中的形式动态添加图像

javascript - Angular5:在加载页面之前加载微调器

javascript - 如何将 *ngif 用于 [值]?

javascript - 如何制作发布apk?

javascript - Notification.requestPermission() 不请求权限

javascript - Ramda 过滤器 - 数字包含数字

html - Angular 8形式,ngSubmit返回空数据对象

angular - 在 Angular 8 项目中使用对象哈希会导致 "Cannot read property ' crypto' of undefined”错误

javascript - 通过传递数组来添加类