angular.js - How does angular add a field to determine a boolean value?
PHP中文网
PHP中文网 2017-05-15 17:02:07
0
3
1122

As follows:<input type="text" readonly="ifReadOnly()"/>
readonly="expression"

How to obtain it from the controller in expression?

if($scope.index == “0”){
                
                $scope.ifReadOnly=function(){
                    
                    return false;
                }
            }else{
                
                $scope.ifReadOnly=function(){
                    
                    return true;
                }
            }

readonly="expression" cannot be written as readonly="ifReadOnly()".

How to modify it so that readonly can work according to different values ​​of expression?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
習慣沉默

Let’s do this:

<input type="text" readonly="ifReadOnly"/>
$scope.$watch('index', function(newIndex){
    $scope.ifReadOnly = newIndex !== '0';
});
淡淡烟草味

html:

<input type="checkbox" ng-model="demo.readOnly" ng-change="handleRead()">

js:

// 默认值
$scope.demo = {
    readOnly: true
};

$scope.handleRead = function () {
    if ($scope.demo.readOnly) {
        // todo readonly
    } else {
        // todo not readonly
    }
};
左手右手慢动作

用ng-readyonly, https://docs.angularjs.org/api/ng/directive/ngReadonly

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template