无法绑定到“ ngModel”,因为它不是“ input”的已知属性

我与影子孤独终老i 提交于 2020-04-09 01:00:16

问题:

I've got the following error when launching my Angular app, even if the component is not displayed. 即使未显示组件,启动我的Angular应用程序时也会出现以下错误。

I have to comment out the <input> so that my app works. 我必须注释掉<input>这样我的应用才能正常工作。

    zone.js:461 Unhandled Promise rejection: Template parse errors:
    Can't bind to 'ngModel' since it isn't a known property of 'input'. ("
        <div>
            <label>Created:</label>
            <input  type="text" [ERROR ->][(ngModel)]="test" placeholder="foo" />
        </div>
    </div>"): InterventionDetails@4:28 ; Zone: <root> ; Task: Promise.then ; Value: 

I'm looking at the Hero plunker, but I don't see any difference from my code. 我正在查看Hero插件,但与我的代码没有任何区别。

Here is the component file: 这是组件文件:

    import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
    import { Intervention } from '../../model/intervention';

    @Component({
        selector: 'intervention-details',
        templateUrl: 'app/intervention/details/intervention.details.html',
        styleUrls: ['app/intervention/details/intervention.details.css']
    })

    export class InterventionDetails
    {
        @Input() intervention: Intervention;

        public test : string = "toto";
    }

解决方案:

参考一: https://stackoom.com/question/2dBml/无法绑定到-ngModel-因为它不是-input-的已知属性
参考二: https://oldbug.net/q/2dBml/Can-t-bind-to-ngModel-since-it-isn-t-a-known-property-of-input
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!