相关疑难解决方法(0)

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

启动Angular应用程序时出现以下错误,即使未显示该组件也是如此.

我必须注释掉,以便我的应用程序正常运行.

    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: 
Run Code Online (Sandbox Code Playgroud)

我正在看着英雄的掠夺者,但我没有看到任何区别.

这是组件文件:

    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"; …
Run Code Online (Sandbox Code Playgroud)

javascript input typescript angular

1173
推荐指数
39
解决办法
70万
查看次数

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

我已链接到另一张票。此错误仅发生在测试中,并且我已导入每个链接消息的 FormsModule。我正在使用 Angular 2.2.1。

ngModel 未在“ng test”中定义我已导入 FormsModule 和 ReactiveFormsModule 无效。我已经研究这个问题24小时了,但还没有更接近。大多数与升级有关,我擦除并重新启动时遇到同样的问题,使用 nggenerate 创建时测试模板非常简单。

我使用 Angular cli 来构建我的应用程序(并重建它......),并且我添加了表单导入,因为它看起来很重要。

这是我的简单模板,请注意,它不是一个表单,而是一个 div,这没有什么区别。“ngserve”看起来很合理,所以代码理论上是正确的。

这是我的表格...

<form class="form-horizontal">
  <div class="form-group">
    <label class="col-sm-2 control-label" for='line1'>Address 1</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" placeholder="Line 1" id='line1' [(ngModel)]='address.line1' required>
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword" class="col-sm-2 control-label" for='line2'>Address 2</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="line2" placeholder="Line 2" [(ngModel)]='address.line2'>
    </div>
  </div>
  <div class="form-inline">
    <div class="form-group">
      <label for="inputPassword" class="col-sm-2 control-label" for='Suburb'>Suburb</label>
      <div class="col-sm-6">
        <input type="text" class="form-control" id="suburb" placeholder="Suburb" [(ngModel)]='address.suburb'>
      </div>
      <div class="col-sm-2"> …
Run Code Online (Sandbox Code Playgroud)

angular2-testing angular

3
推荐指数
1
解决办法
1680
查看次数