2014-04-03 1 views
1

부모 범위에 저장된 부울 값을 기반으로 지시문을 조건부로 표시하려고합니다. 나는 왜 아래가 작동하지 않는지 이해할 수 없다. "작동하지 않음"이란 지시어가 표시되지 않음을 의미합니다.Angular JS : ng-switch on boolean이 작동하지 않습니다.

<ul class="nav navbar-nav pull-right" ng-switch="userIsAuthenticated"> 
    <account-item item="accountMenuItem" ng-repeat="accountMenuItem in anonymousMenuItems" ng-switch-when="false"></account-item> 
    <account-item item="accountMenuItem" ng-repeat="accountMenuItem in authenticatedMenuItems" ng-switch-when="true"></account-item> 
</ul> 

어느 지침은 심지어 "userIsAuthenticated는"내 테스트 케이스에 '거짓'으로 설정되어 생각 표시됩니다. 지시문 위에 {{userIsAuthenticated}}을 추가하면 'false'가 예상대로 출력됩니다.

나는 또한이 시도했습니다

<ul class="nav navbar-nav pull-right" ng-switch={{userIsAuthenticated}}> 
    <account-item item="accountMenuItem" ng-repeat="accountMenuItem in anonymousMenuItems" ng-switch-when={{false}}></account-item> 
    <account-item item="accountMenuItem" ng-repeat="accountMenuItem in authenticatedMenuItems" ng-switch-when={{true}}></account-item> 
</ul> 

나는 제거 할 경우 조건부 NG-스위치 때이 표시됩니다 지침 중 하나에서 속성. 그래서 문제가 내 스위치인지 알 수 있습니다. NG 스위치의

+0

'account-item' 지시어에 표시 할 수 있습니까? – raina77ow

답변

2

귀하의 사용은 account-item 지시없이 물론,이 간단한 데모 작동합니다 http://plnkr.co/AppN8xmFeIwjaP631lj7

account-item에 대한 코드를 보지 않고, 그것을 방해 할 수있는 것을 생각하기 어렵다. 하나의 항목 또는 다른 항목 표시를 처리하려면 ng-if을 사용하는 것이 좋습니다.

<ul> 
    <div ng-if="!userIsAuthenticated">Content when not authenticated</div> 
    <div ng-if="userIsAuthenticated">Content when authenticated</div> 
</ul> 

업데이트 또한 대신 원시 부울의 객체 속성에 바인딩해야합니다. 마찬가지로 : ngSwitchWhen 이후 user. authenticated

+0

이 [Plunkr] (http://plnkr.co/edit/cy8AfaBTlRwsEplHTBer?p=preview)에서이 항목들에 (아주 간단한) ng-repeat를 추가했습니다. 제대로 작동하는 것 같습니다. 따라서 '계정 항목'이 여기에 핵심 요소가되어야합니다. – raina77ow

1

800의 우선 순위를 가지고, 당신은이 ngSwitchWhen 지침에 의해 처리되기 전에 컴파일하기 위해 사용자 정의 지시어 (즉 account-item)에 더 높은 우선 순위를 설정해야합니다. 예 :

.directive('accountItem', function() { 
    return { 
     ... 
     priority: 900, 
     ... 
    }; 
}); 
관련 문제