角引导UI模式具有相同的控制器,而不是新的控制器 [英] Angular bootstrap ui modal with same controller instead of new controller

查看:91
本文介绍了角引导UI模式具有相同的控制器,而不是新的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度引导用户界面模式对话框它说给一个新的$ modalInstance新controller.I要使用的模式box.I搜索在那里我初始化了相同的控制器,但没有success.I发现这个链接,但没有成功 -

I am using angular bootstrap ui modal box it says to give a new $modalInstance for new controller.I want to use the same controller where i have initialized the modal box.I searched but no success.I found this links but no success -

<一个href=\"http://stackoverflow.com/questions/23780950/how-to-use-the-same-controller-for-modal-and-non-modal-form-in-angular-ui-bootst\">How用于在角UI引导模态和非模态的形式相同的控制器?
<一href=\"http://stackoverflow.com/questions/23756105/angular-ui-bootstrap-modal-without-creating-new-controller\">Angular-ui引导模式,而无需创建新的控制器

app.controller('UserCtrl',['$scope','$filter','ngTableParams','$modal',function($scope, $filter, ngTableParams,$modal) {

  var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl', //Instead of this i want to use the same controller 'UserCtrl'
  size: size,
  resolve: {
    items: function () {
      return $scope.items;
    }
  }
});

modalInstance.result.then(function (selectedItem) {
  $scope.selected = selectedItem;
}, function () {
  $log.info('Modal dismissed at: ' + new Date());
});
 };
};

  } ]);

这样我就可以调用save这就是所谓的节省模式对话框单击此同一个控制器上的功能

So that i can call the save function on this same controller which is called on save click of modal box

推荐答案

这在旧版本中是允许的用户界面,引导0.10.0
下载 Library.Even最新版本,它为我的作品

It was possible in older version of UI-Bootstrap 0.10.0 Download Library.Even latest version,it works for me

<!-- if you are using Bower -->    
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js">
</script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js">
</script>

<!-- button click opens modal-->
<button ng-click="openModal()">Button test</button>

<!-- modal -->
<!-- look at 'type' and 'id' values -->
<script type="text/ng-template" id="myTestModal.tmpl.html">
   <div class="modal-header">
      <h3>Modal Header</h3>
   </div>   

   <div class="modal-body">
      <p>Modal Body</p>
   </div>

   <div class="modal-footer">
      <button type="button" class="btn btn-default" ng-click="close()" data-dismiss="modal">Close
      </button>
      <button type="button" class="btn btn-primary" ng-click="doSomething()">Do Something
      </button>
   </div> 
</script>

modalDemoController.js

$scope.openModal=function(){
    $scope.modalInstance=$modal.open({
        templateUrl: 'myTestModal.tmpl.html',
        scope:$scope
    });
}

$scope.close=function(){
    $scope.modalInstance.dismiss();//$scope.modalInstance.close() also works I think
};

$scope.doSomething=function(){
    //any actions to take place
    console.log("Do Something");
}

这篇关于角引导UI模式具有相同的控制器,而不是新的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆