export class UserComponent {
users: User[] = new Array<User>();
removeAll(){
this.users = new Array<User>();
}
}
<button (click)="removeAll">Remove</button>
<ul>
<li *ngFor="let user of users>{{user.name}}</li>
</ul>
当我点击删除按钮时,它们应为空,但ul具有所有先前的值。如何刷新绑定? 感谢
答案 0 :(得分:3)
(click)="removeAll"
应该是
(click)="removeAll()"