2016-04-03 65 views
0

反映VIEW部分

<div class="col-sm-8" data-ng-init="init_enable_disable()"> 
    <select class="form-control" style="margin-top: 5px;" data-ng-model="schedule.scheduleType" data-ng-change="enable_disableDiv(schedule.scheduleType);"> 
     <option ng-selected="{{type == defaultSelectedType}}" data-ng-repeat="type in schduleType">{{type}} 
     </option> 
    </select> 
</div> 

NG重複模式

$scope.schduleType = ['Recurring', 'One time']; 

我更新在以後的NG-模型,但它不反映在視圖

if (editRecord.freq_type === 1) 
{ 
    alert("one time"); 
    $scope.schedule.scheduleType = 'One time'; 
} 

什麼問題請建議我。

回答

1

當您使用ng-model和分配的值從控制器無需無需在DOM使用ng-selected。並更好地從控制器初始化。

可以試試

在你的控制器

$scope.schduleType = ['Recurring', 'One time']; 
    $scope.schedule = {}; 
    $scope.schedule.scheduleType = $scope.schduleType[0]; // initial select 

    $scope.enable_disableDiv = function(){ 
    console.log($scope.schedule.scheduleType); 
    } 

在HTML:

<select class="form-control" data-ng-model="schedule.scheduleType" data-ng-change="enable_disableDiv(schedule.scheduleType)"> 
    <option ng-repeat="type in schduleType" value="{{type}}">{{type}}</option> 
</select> 

注意:如果你想從你的控制器更改選項的值,那麼你應該使用$scope.schduleType代替someValue用於參考,因爲從控制器分配值時不參考schduleType。喜歡想根據條件改變然後使用像:

if(editRecord.freq_type === 1) { 
    $scope.schedule.scheduleType = $scope.schduleType[1];// not "one Time" 
} 
0

你可以嘗試

`$scope.$applyAsync(function(){ 
 
    $scope.schedule.scheduleType = 'One time'; 
 
})`