2014-02-26 73 views
0

我在使用angular-ui模式引用範圍時遇到了問題。我收到了關於範圍值的未定義消息。我想要做的是獲取將被輸入到ng-model =「input.cost_center」的數據。但是,當我改編其他人提供的關於同一主題的示例時,它似乎不起作用。有人可以幫助我嗎?在此先感謝使用angular-ui模式獲取未定義值的問題

這裏是普拉克http://plnkr.co/edit/tIh5rbvseD7vxfPJHFd6?p=preview

莫代爾

$scope.openAddCenter = function() { 
    var modalAddCenter = $modal.open({ 
    templateUrl: 'myModalAddCenter.html', 
    controller: ModalAddCenterCtrl, 
    resolve: { 
    '$modalAddCenter': function() { 
     return function() { 
     return modalAddCenter; } 
    } 
    } 
}); 

}; 

模態控制器

var ModalAddCenterCtrl = function ($scope, $modalAddCenter, $http){ 
    $scope.input = {};    
    $scope.ok = function(){ 
    alert($scope.input.cost_center); 
    $modalAddCenter().close(); 
    }; 

    $scope.cancel = function(){ 
    $modalAddCenter().dismiss('cancel'); 
    }; 
}; 

HTML

<input type="text" class="form-control" id="modalCenter" ng-model="input.cost_center" placeholder="Cost Center" ng-minLength="8" maxLength="8" required /> 

回答

0

雖然我不確定爲什麼解決方案無法正常工作,看起來您應該使用anuglar-ui將提供給模態控制器的$ modelInstance參數來完成。因此,而不是嘗試:

var ModalAddCenterCtrl = function ($scope, $modalInstance, $http){ 
    $modalInstance.close(); 
} 

$ modalInstance總會解決當前的模式實例,而不需要與解析器注射進去。

+0

我仍然從ng-model =「input.cost_center」中獲取未定義的值,並且TypeError:object不是函數。這指出了$ scope.ok函數。 – MarkJ