2016-10-01 6 views
0

나는이 component.html이 : 기본적으로각도 2 *에 대한 ngIf '이'코너 2에서

editAction(){ this.iscalled = true; } 

은이 component.ts

<li *ngFor="let something of somethings"> 
    <span>{{something}}</span> 
    <input class="doit" type="text" *ngIf="iscalled" /> 
<div id="container"> 
    <button class="btn btn-warning editsection (click)="editAction()">Edit</button> 
</div> 
</li> 

을 내 구성 요소에서 false로 설정하십시오.

기본적으로 각 somethingsomethings입니다. 내 목록과 함께 입력란에는 할당 된 입력란과 editAction()을 실행하는 버튼이 있습니다. 사용자가 editAction() 버튼을 클릭하면 버튼이 나타납니다.

이제는 editAction() 버튼을 클릭하면 내 목록의 모든 입력 필드가 활성화됩니다. 이 내용을 의미하는 정확히 li 요소로 제한하고 싶습니다.

각도 2에 특정 동작이 있는지, 아니면 일반 자바 스크립트 솔루션인지 알 수 없습니다.

+1

ngFor가 노출하는 색인을 사용해 보셨습니까? – jonrsharpe

답변

1

참고 :이 설정을 사용하면 토글 에 원하는 경우

<li *ngFor="let something of somethings"> 
    <span>{{something}}</span> 
    <input class="doit" type="text" 
      *ngIf="something.iscalled" />  //<<<===changed 

    <div id="container"> 
      <button class="btn btn-warning 
      editsection 
      (click)="editAction(something)">  //<<<===changed 
       Edit 
      </button> 
    </div> 
</li> 

editAction(something){ something.iscalled = true; } 

다음 거짓 을 iscalled기본 값을 설정하지 마십시오 다음과 같이 할 수 있습니다.

editAction(something){ something.iscalled != something.iscalled; } 
+0

감사합니다! 그러나 토글 옵션이 작동하지 않는 것 같습니다. 그리고 당신의 오타가 있다는 것을 이해합니다, 그래서 나는 그것을 복사 - 붙여 넣는 것과 다르지 않습니다. 논리는 끝나지 않습니다. – abrahamlinkedin

+1

작동해야합니다. 나는 그것에 대해 꽤 확신한다. 'something' 객체에 대해 어떤 모델을 사용하고 있다면 iscalled 속성을 그 모델에 추가해야합니다. 예상대로 작동합니다. – micronyks

+1

알겠습니다. 작동하지 않으면'something.iscalled! = something.iscalled'을'something.iscalled =! something.iscalled'로 변경할 수 있습니다. – micronyks

관련 문제