2015-05-12 55 views
0

現在,我正在使用複選框來禁用/不可禁用其他按鈕的單擊。 我的代碼是在這裏:

<button class="dateicon" ng-disabled='ExpReport.Beld' ng-click="openstart($event)">button1</button> 
<button ng-disabled='ExpReport.Beld' class="dateicon" ng-click="openend($event)">button2</button> 
<input id='beld' ng-model='ExpReport.Beld' class='checkboxinline' type='checkbox'/> 

$scope.ExpReport.Beld = false; 
$scope.$watch('ExpReport.Beld',function(){ 
      if($scope.ExpReport.Beld=true){ 
      $scope.ExpReport.startdate = ''; 
      $scope.ExpReport.enddate = ''; 
      } 
     }) 

好像複選框始終設置爲false,當我提出一個斷點,它會設置爲true,然後馬上轉回來爲false。任何想法?

+1

把一個Plunker或JSBin,但你的問題是比較的標誌,'''scope.ExpReport.Beld === true''',而不是''scopepace.ExpReport.Beld = true''' – TheUnnamed

+0

'$ scope.ExpReport.Beld === true'可能是多餘的;只需使用'$ scope.ExpReport.Beld'。 –

回答

2

下面一行

if($scope.ExpReport.Beld=true){ 

實際上是$ scope.ExpReport.Beld變量,而不是比較的分配。確保你使用兩倍或三倍的平等。

if($scope.ExpReport.Beld == true){ 

if($scope.ExpReport.Beld){ 

會工作得很好。

2
if($scope.ExpReport.Beld=true){ 

這條線。如果你正在做一個比較,使用==或者===

+0

大壩,我是多麼愚蠢!感謝您指出! – linyuanxie