我正在开发 angular2 应用程序。我的要求是使用数组创建多个复选框,并选中最后一个复选框,因此如果未选中最后一个复选框,则显示 div,因此隐藏 div。
组件.ts:-
peoples: any = [
{ "name":"rahul", "status":false},
{ "name":"rija", "status":false},
{ "name":"roy", "status":false},
{ "name":"ninja", "status":false},
{ "name":"riya", "status":false},
{ "name":"rohit", "status":true},
];
组件.html
<div *ngFor = "let people of peoples">
<input type = "checkbox" [value] = 'people?.name' [checked] = "people?.status">
{{people?.name}}
</div>
/****** Hide/show div (if last checkbox is checked so show is div and unchecked so hide this div ******/
<div>
<span> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</div>
就像 pardeep jain 指出的那样,你可以使用
[hidden]="!peoples[peoples.length - 1].status"
但是我只想提一下,然后用ngModel
,用的[checked]
时候,用的时候也可以去掉。
<div *ngFor="let people of peoples">
<input type="checkbox" [value]="people.name" [(ngModel)]="people.status">
{{people?.name}}
</div>
<div [hidden]="peoples[peoples.length - 1].status">
<span> Lorem Ipsum is simply dummy text </span>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句