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?
習慣沉默2017-05-15 17:04:07
Let’s do this:
<input type="text" readonly="ifReadOnly"/>
$scope.$watch('index', function(newIndex){
$scope.ifReadOnly = newIndex !== '0';
});
淡淡烟草味2017-05-15 17:04:07
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
}
};
ringa_lee2017-05-15 17:04:07
用ng-readyonly, https://docs.angularjs.org/api/ng/directive/ngReadonly