【问题标题】:what is this error (Can't bind to 'ngModel' since it isn't a known property of 'input'. )这是什么错误(无法绑定到“ngModel”,因为它不是“输入”的已知属性。)
【发布时间】:2018-01-31 19:49:06
【问题描述】:

控制台上的错误打印低于一个...我正在尝试通过添加员工按钮添加表单

无法绑定到“ngModel”,因为它不是“输入”的已知属性。 (" ][(ngModel)]="model.name" placeholder="输入你的名字">

here is the error image

下面是它的代码

<div class = "container">
<h1>{{title}}</h1>
<h2>Add Employee:</h2>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" 
name="name" [(ngModel)]="model.name"
placeholder="Enter Your Name">
</div>
</div>
<div class="form-group">
 <label class="control-label col-sm-2" for="position">Position:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="position" 
name="position" [(ngModel)]="model.position"
placeholder="Enter your position">

</div>
</div>
 <div class="form-group">
<label class="control-label col-sm-2" for="salary">Salary:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="salary" 
name="salary" [(ngModel)]="model.salary" 
placeholder="Enter Salary">
</div>
</div>
<div class="form-group">  
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" click)="addEmployee">Add 
Employee</button>
</div>
</div>
</form>
<h2>Employee Details</h2>
<table class="table table-bordered">
<thead>
<tr>
<th width=400>Name</th>
<th width=400>Position</th>
<th width=400>Salary</th>
<th width=200>Actions</th>
</tr>
</thead>
enter code here
<tbody>
<tr *ngFor="let employee of employees; let i=index">
<td>{{employee.name}}</td>
<td>{{employee.position}}</td>
<td>{{employee.salary}}</td>
<td><a class="btn btn-danger">Delete</a></td>
</tr></tbody></table></div>

【问题讨论】:

  • 通过添加 import { FormsModule } from '@angular/forms' 解决了我的问题;和 @NgModule({ 声明:[ AppComponent ],导入:[ BrowserModule ,FormsModule ] in app.module.ts

标签: twitter-bootstrap npm angular-cli


【解决方案1】:

通过添加 import { FormsModule } from '@angular/forms' 解决了我的问题;和 @NgModule({ 声明:[ AppComponent ],导入:[ BrowserModule ,FormsModule ] in app.module.ts

【讨论】:

    猜你喜欢
    • 2021-09-20
    • 2016-12-17
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 2016-12-18
    相关资源
    最近更新 更多