![](/img/trans.png)
[英]core.js:12853 Can't bind to 'ngIf' since it isn't a known property of 'div'
[英]Getting error in console Can't bind to 'ngif' since it isn't a known property of 'div' in angular app
在为编辑状态调用 ngif 语句后,我在控制台中收到此错误无法绑定到 'ngif' 因为它不是 'div' 的已知属性我必须提到我的第一个条件运行良好并且我已经导入了 BrowserModule 和 CommonModule到 app.module.ts
这是我的tasks.component.html
<div class="container mt-5">
<div *ngIf ="tasks?.length > 0; else noTasks" >
<ul class="list-group" >
<li *ngFor = "let task of tasks" class="list-group-item">
<div class="row">
<div class="col">
<strong> {{task.title}}: </strong> {{task.description}}
</div>
<div class="col-sm-auto">
<button (click)="editTask($event, task)" class="btn btn-link"> Edit </button>
</div>
<div class="col-sm-auto">
<button (click)="deleteTask($event, task)" class="btn btn-link"> Delete </button>
</div>
</div>
<div *ngif="editState && taskToEdit.id == task.id">
<form (ngSubmit)="udpateTask(task)">
<div class="row">
<div class="col-6">
<div class="form-group">
<label>Task title</label>
<input type="text" [(ngModel)]="task.title" name="title" class="form-control">
</div>
</div>
<div class="col-6">
<div class="form-group">
<label>Task Description</label>
<input type="text" [(ngModel)]="task.description" name="description" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<input type="submit" class="btn btn-dark" value="Update Task">
</div>
</div>
</form>
</div>
</li>
</ul>
</div>
<ng-template #noTasks>
<h5>There are no tasks to list</h5>
</ng-template>
这一行 *ngif="editState && taskToEdit.id == task.id" 包含一个错字,应该读为 *ngIf。 请检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.