我正在使用angular2應用程序。在我的要求是使用數組創建多個複選框,並選中最後一個複選框,以顯示div,如果最後一個複選框未選中,請隱藏div。如果在angular2中選中/取消選中最後一個複選框,如何顯示/隱藏div?
Component.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},
];
component.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>
嘗試'和'* ngFor' –
last'指數與'* ngFor'像'* ngFor = 「;讓最後=最後讓人民的人」 使用它。你將從這裏得到ngFor的最後一個索引,你可以用它來檢查複選框是否是最後一個 –
@harleen,或者你也可以使用這個'[hidden] =「!peoples [peoples.length - 1] .status」' –