简体   繁体   中英

Angular ng-disabled

If someone have this problem please answer me.

Something like this works fine (element will be disabled when its true):

            <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}}"/>

And this works too:

<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/>

But this doesn`t work at the same angular view (same scope):

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

Element doesn`t disabled...

Or just do in controller:

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

and in your template :

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

this works in my build ..

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

change {{}} into ()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM