2014-09-05 95 views
11

我正在一個複雜的應用程序,我需要禁用一個鏈接,如果從後端發送的ID符合一定的標準。 我使用這個,但現在不知道這是否是正確的:AngularJS ng顯示三元條件具有多個條件

ng-show="parentheaderData.casid === '807' || '806' || '808' ?false:true" 

這是否正確?

回答

1
ng-show="(parentheaderData.casid === '807' || parentheaderData.casid ==='806' parentheaderData.casid === || '808') ? false : true" 
9

你爲什麼不這樣的邏輯移動到控制器,以便有

HTML:

ng-show="showParentheader(parentheaderData.casid)" 

控制器:

$scope.showParentheader = function(id) { 
    return ! (id === '807' || id ==='806' || id ==='808'); 
} 
2

,你可以這樣做:

ng-show="(parentheaderData.casid === '807' || parentheaderData.casid ==='806' parentheaderData.casid === || '808') ? false : true" 

或:

ng-show=" !(parentheaderData.casid === '807' || parentheaderData.casid ==='806' parentheaderData.casid === || '808')" 
9

感謝所有支持。正確的解決方案是:

ng-hide="parentheaderData.casid == '806' || parentheaderData.casid == '807' || parentheaderData.casid == '808'" 
+0

您應該接受此答案爲正確的 – Icet 2016-12-13 09:47:10