启动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) 情况:
请帮忙!我试图在我的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) 这似乎是一个流行的问题,但解决方案都建议导入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 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)