Angular ng-disabled

时间:2014-01-24 12:02:04

标签: javascript angularjs

如果有人有这个问题,请回答我。

这样的工作正常(元素将在其真实时被禁用):

            <input type="text" class="no-phone-input" name="phone" ng-model="currentOrder.Customer.Phone" ng-pattern="/^[0-9-]+$/" ng-disabled="{{currentOrder.Status == 7 || currentOrder.Status == 9}}"/>

这也有效:

<input type="text" id="orderNumberInput" class="no-num-input" name="OrderNumber" ng-model ="currentOrder.OrderNumber" ng-disabled="{{currentOrder.Status == 2 || currentOrder.Status == 3  || currentOrder.Status == 4 || currentOrder.Status == 6 || currentOrder.Status == 7 || currentOrder.Status == 8 || currentOrder.Status == 9}}" required/>

但是这在相同的角度视图(相同范围)下不起作用:

<input id="customer" name="customer" type="text" ng-model="currentOrder.Customer.Name" ng-disabled="{{currentOrder.Status == 7 || currentOrder.Status == 9}}" required/>

元素没有被禁用......

2 个答案:

答案 0 :(得分:1)

或者只是在控制器中执行:

$scope.disabler = function(){
    if($scope.currentOrder.Status ==7 || $scope.currentOrder.Status ==9 ){
        return true;
    }
}

并在您的模板中:

<input id="customer" name="customer" type="text" ng-model="currentOrder.Customer.Name" ng-disabled="disabler()" required/>

答案 1 :(得分:0)

这适用于我的构建..

<input id="customer" name="customer" type="text" ng-model="currentOrder.Customer.Name" ng-disabled="(currentOrder.Status == 7 || currentOrder.Status == 9)" required/>

{{}}更改为()