简体   繁体   English

Angular 2 - 无法绑定到'ngModel',因为它不是'input'的已知属性

[英]Angular 2 - Can't bind to 'ngModel' since it isn't a known property of 'input'

I have a Angular 2 Inline Editing component in plunker. 我在plunker中有一个Angular 2 Inline Editing组件。 But suddenly i'm getting the above error. 但突然间我得到了上述错误。 What happened to it? 这是怎么回事?

Plunker code: http://plnkr.co/edit/3AODo6YGEhvPOKzloofz?p=preview Plunker代码: http ://plnkr.co/edit/3AODo6YGEhvPOKzloofz?p = preview

Parent component: 父组件:

<inline-edit [editEnable]="edit" [(ngModel)]="editableText" (onSave)="saveEditable($event)"></inline-edit>

Child component: 子组件:

<div id="inlineEditWrapper" (click)="edit(value)" class="iedit">
    <!-- Editable value -->
    <a  [hidden]="editing">{{ value }}&nbsp;<i class="glyphicon glyphicon-pencil" data-hidden="editing"></i></a>

    <!--<span class="glyphicon glyphicon-pencil" [hidden]="editing"></span>-->

    <!-- inline edit form -->
    <form  #inlineEditForm="ngForm" class="inlineEditForm form-inline" (ngSubmit)="onSubmit(value)" [hidden]="!editing">
        <div class="form-group">

            <!-- inline edit control  -->
           <input style="margin-bottom:10px;" #inlineEditControl class="form-control" [(ngModel)]="value"/>

            <!-- inline edit save and cancel buttons -->
            <br/>
           <span >
                <button type="submit" class="btn btn-primary">Change</button>
                <button class="btn btn-default" (click)="cancel(value)">Cancel</button>
           </span>

        </div>
    </form>
</div>

You can follow some steps: 您可以按照以下步骤操作:

Step 1: Load package for angular forms 第1步:为角形加载包装

'@angular/forms': {
      main: 'bundles/forms.umd.js',
      defaultExtension: 'js'
}

Step 2: Import disableDeprecatedForms, provideForms 第2步:导入disableDeprecatedForms,提供Forms

import {disableDeprecatedForms, provideForms} from '@angular/forms';

bootstrap(App, [
   disableDeprecatedForms()
   provideForms()
]).catch(err => console.error(err));

Step 3: Import ControlValueAccessor, NG_VALUE_ACCESSOR from "@angular/forms" in inline-edit.component.ts 第3步:从inline-edit.component.ts中的“@ angular / forms”导入ControlValueAccessor,NG_VALUE_ACCESSOR

Step 4: Adjust your input element in the form as: 第4步:在表单中调整输入元素:

<input style="margin-bottom:10px;" #inlineEditControl class="form-control" name="first_name" #first_name="ngModel" [(ngModel)]="value"/>

That work for me at here 那对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular2 RC5教程:无法绑定到'ngModel',因为它不是'input'的已知属性 - Angular2 RC5 tutorial : Can't bind to 'ngModel' since it isn't a known property of 'input' Angular 2 RC 5 - 无法绑定到&#39;...&#39;,因为它不是&#39;...&#39;的已知属性 - Angular 2 RC 5 - Can't bind to '…' since it isn't a known property of '…' 无法绑定到“ ngModule”,因为它不是“ input”的已知属性。 在angular 2 asp.net核心中 - Can't bind to 'ngModule' since it isn't a known property of 'input'. in angular 2 asp.net core 无法绑定到 &#39;dtOptions&#39;,因为它不是 &#39;table&#39; 的已知属性。 - Can't bind to 'dtOptions' since it isn't a known property of 'table'. 无法绑定到“ngForOf”,因为它不是 Ionic / Angular 9 中“ion-item”的已知属性 - Can't bind to 'ngForOf' since it isn't a known property of 'ion-item' in Ionic / Angular 9 使用ng2-bootstrap与Angular 2 RC 6 - 无法绑定到无法绑定到[...],因为它不是[...]的已知属性 - Using ng2-bootstrap with Angular 2 RC 6 - can't bind to can't bind to […] since it isn't a known property of […] 在 Angular 中使用 cdkDropListData 时出错,无法绑定到“cdkDropListData”,因为它不是“div”的已知属性 - Error when using cdkDropListData in Angular gives me Can't bind to 'cdkDropListData' since it isn't a known property of 'div' 2.0.0版本无法绑定到&#39;ngIf&#39;,因为它不是&#39;div&#39;的已知属性 - 2.0.0 version Can't bind to 'ngIf' since it isn't a known property of 'div' 离子图标和“无法绑定到&#39;名称&#39;,因为它不是已知的本机属性”错误 - ionic icon and “Can't bind to 'name' since it isn't a known native property” error |官方指南坏了吗?| 无法绑定到“ ngFor”,因为它不是已知的本机属性 - |Official guide broken?| Can't bind to 'ngFor' since it isn't a known native property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM