如何识别特定的列表元素字段并将其显示对象的属性设置为true

时间:2016-08-07 08:35:55

标签: javascript html dom angular angular2-template

因此使用* ngFor i显示了对象的name属性列表,这个对象也有一个名为isAvailable的属性我想设置isAvalable属性,当我点击它时,在true和false之间切换,并基于isAvalible下一个文本到li将显示是否可用

<p>Authors</p>
<ul>
<li *ngFor='let author of authors' (click)='onClick()'>
{{author.name}}
</li>
</ul>

2 个答案:

答案 0 :(得分:0)

<p>Authors</p>
<ul>

   <li *ngFor='let author of authors'>
        <span [hidden]='author.isAvalible'>{{author.name}}</span>
        <span (click)='onClick()'>author.isAvalible</span>
    </li>
</ul>


onClick(value){
   value=!value;
}

答案 1 :(得分:0)

据我所知你想要这个

<p>Authors</p>
<ul>
   <li *ngFor='let author of authors'>
     <span [hidden]='author.isAvalible'>{{author.name}}</span>
     <span (click)='author.isAvalible = !author.isAvalible '>author.isAvalible</span>
   </li>
</ul>