簡體   English   中英

Angular-UI模態范圍不確定獲得不確定的值

[英]Trouble with scope on angular-ui modal getting undefined value

我在使用angular-ui模式引用范圍時遇到麻煩。 我收到有關范圍值的未定義消息。 我要做的是獲取將輸入到ng-model =“ input.cost_center”的數據。 但是,當我改寫其他人提供的有關同一主題的示例時,它似乎不起作用。 有人可以幫我嗎? 提前致謝

這是pl的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 />

盡管我不確定解析為什么不起作用,但似乎您要嘗試使用$ modelInstance參數完成該操作,anuglar-ui將使模態控制器可用。 因此,請嘗試:

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

$ modalInstance將始終解析為當前模式實例,而不需要將其與解析器一起插入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM