搜尋

首頁  >  問答  >  主體

angular.js - angular如何為一個boolean的值加一個欄位來判斷

如下:
readonly="expression"

expression中如何根據控制器來獲得呢,

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

readonly="expression" 寫成readonly="ifReadOnly()"不可以的。

如何修改才能讓readonly根據expression不同的值去產生作用呢?

PHP中文网PHP中文网2839 天前1126

全部回覆(3)我來回復

  • 習慣沉默

    習慣沉默2017-05-15 17:04:07

    這樣吧:

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

    回覆
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 17:04:07

    html:

    雷雷

    js:

    雷雷

    回覆
    0
  • ringa_lee

    ringa_lee2017-05-15 17:04:07

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

    回覆
    0
  • 取消回覆