相关疑难解决方法(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万
查看次数

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

情况:

请帮忙!我试图在我的Angular2应用程序中制作一个非常简单的表单,但无论它从不工作.

角度版本:

Angular 2.0.0 Rc5

错误:

Can't bind to 'formGroup' since it isn't a known property of 'form'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

代码:

风景:

<form [formGroup]="newTaskForm" (submit)="createNewTask()">

    <div class="form-group">
        <label for="name">Name</label>
        <input type="text" name="name" required>
    </div>

     <button type="submit" class="btn btn-default">Submit</button>

</form>
Run Code Online (Sandbox Code Playgroud)

控制器:

import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators, FormBuilder }  from '@angular/forms';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';
import { Task } from './task';

@Component({
    selector: 'task-add',
    templateUrl: 'app/task-add.component.html'

})


export class TaskAddComponent {

    newTaskForm: FormGroup;

    constructor(fb: FormBuilder) 
    {
        this.newTaskForm …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-forms angular

671
推荐指数
29
解决办法
49万
查看次数

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

这似乎是一个流行的问题,但解决方案都建议导入FormsModule,而这正在完成.

错误是:

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

<label for="city">City</label>
<input type="text" id="city" [ERROR ->][(ngModel)]="chosenCity">
<input type="button" value="Get Weather" (click)="getWeather(chosenCity)" "):
Run Code Online (Sandbox Code Playgroud)

模板和组件代码如下:

import { Component } from '@angular/core';
import { Http } from '@angular/http';

@Component({
    selector: 'weather',
    templateUrl: './weather.component.html'
})
export class WeatherComponent {
    public weather: Weather;

    constructor( private http: Http) {
    }

    public getWeather(chosenCity: string): void {
        this.http.get('/api/weather/city/' + chosenCity).subscribe(result => {
            this.weather = result.json();
        });
    }
}

interface Weather {
    temp: string;
    summary: string;
    city: string;
}
Run Code Online (Sandbox Code Playgroud)
<h1>Weather check</h1>

<label for="city">City</label>
<input type="text" …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
2万
查看次数

未捕获的错误:模板解析错误:由于它不是'input'的已知属性,因此无法绑定到'ngModel'

我正在使用Angular 4.2.4,并且在控制台中遇到错误:

Uncaught Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'.
Run Code Online (Sandbox Code Playgroud)

当我在文件app.module.ts中包含FormsModule时

import { FormsModule,ReactiveFormsModule }   from '@angular/forms';
@NgModule({
  declarations: [
    AppComponent,
    ...APP_LAYOUTS,
    ...APP_COMPONENTS,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)

和通过html代码是

<form id="user-add-form">
    <div class="text-center m-t-10"><span class="login-img"><i class="ti-check-box"></i></span></div>
    <h3 class="login-title">Add New User</h3>
    <div class="row">
      <div class="col-6">
        <div class="form-group">
          <input class="form-control" type="text" name="first_name" [(ngModel)]="first_name" placeholder="First Name">
        </div>
      </div>
      <div class="col-6">
        <div class="form-group">
          <input class="form-control" type="text" name="last_name" …
Run Code Online (Sandbox Code Playgroud)

angular

2
推荐指数
1
解决办法
2864
查看次数

标签 统计

angular ×4

typescript ×2

angular2-forms ×1

input ×1

javascript ×1