2015-10-15 82 views
0

我有一個默認禁用的文本輸入:角:禁用文本輸入

<input type="text" ng-model="city.name" class="form-control" 
            disabled 
            name="name"> 

但我想啓用它,當輸入國不爲空:

<input type="text" ng-model="country.name" class="form-control" 
             > 

哪有我在角度控制器中這樣做?我開始像這樣 在我的控制器,但我不知道如何啓用它一旦國內值不爲空

// Watch if the country value is not null 
      $scope.$watch("country.name", function (value) { 
       if (value !=null) { 
        // enable the city field 
       } 
      },true); 

感謝

回答

1

可以使用NG-殘疾人無需進入控制器:

<input type="text" ng-model="city.name" class="form-control" ng-disabled="!country.name" name="name"> 
<input type="text" ng-model="country.name" class="form-control"> 
+0

Omg!最快和有效的答案:)謝謝 – user708683

+0

NP,不要忘記接受+ upvote :) –

+0

完成Mathew Berg :) – user708683