2017-10-17 6 views
0

각도가 너무 작습니다. 내 프로그램에서 ngSwitch을 사용하고 있지만 *ngSwitchDefault 프로그램을 실행할 때마다 *ngSwitchCase 대신 실행합니다.각도 * ngSwitchCase가 실행되지 않습니다.

<select [(ngModel)]="selectedControl" class="form-control"> 
    <option *ngFor="let inputControl of inputArray; let i=index" 
    [value]="inputControl">{{inputArray[i]}}</option>         
</select> 
<span [ngSwitch]="selectedControl"> 
    <span *ngSwitchCase="text"> 
    <p>text is selected</p>    
    </span> 
    <span *ngSwitchCase="radio"> 
    <p>radio is selected</p> 
    </span>   
    <span *ngSwitchDefault> 
    <p>Default value</p> 
    </span> 
</span> 
+0

으로 바꾸십시오. 문자열을 "true"로 설정해야합니다. " –

답변

1

쌉니다 ''*ngSwitchCase 표현 그들에게 strings를 만들기 위해 다음은 코드입니다. 비교는 ===과 함께 사용되므로 stringstring을 비교합니다. 귀하의 경우에는 이름이 radio 또는 text 인 회원을 찾고 그 값은 정의되지 않습니다.

<span [ngSwitch]="selectedControl"> 
    <span *ngSwitchCase="'text'"> 
    <!--     ^----^ --> 
    <p>text is selected</p>    
    </span> 
    <span *ngSwitchCase="'radio'"> 
    <!--     ^-----^ --> 
    <p>radio is selected</p> 
    </span>   
    <span *ngSwitchDefault> 
    <p>Default value</p> 
    </span> 
</span> 
+0

감사합니다. 작동합니다. –