您有两个问题:
- 您需要在模态配置中定义控制器
- 你的决心对象需要是地图的
string
:function
,其中string
是将被注入到你的模态的控制依赖的名称,function
是将用来提供这种依赖性当控制器被实例化一个工厂函数。
工作示例:JSFiddle
JavascriptHTMLangular.module('myApp', ['ui.bootstrap']) .controller('MyModalController', MyModalController) .directive('modalTrigger', modalTriggerDirective) .factory('$myModal', myModalFactory);function MyModalController($uibModalInstance, items) { var vm = this; vm.content = items; vm.confirm = $uibModalInstance.close; vm.cancel = $uibModalInstance.dismiss;};function modalTriggerDirective($myModal) { function postlink(scope, iElement, iAttrs) { function onClick() { var size = scope.$eval(iAttrs.size) || 'lg'; // default to large size var title = scope.$eval(iAttrs.title) || 'Default Title'; var message = scope.$eval(iAttrs.message) || 'Default Message'; $myModal.open(size, title, message); } iElement.on('click', onClick); scope.$on('$destroy', function() { iElement.off('click', onClick); }); } return { link: postlink };}function myModalFactory($uibModal) { var open = function (size, title, message) { return $uibModal.open({ controller: 'MyModalController', controllerAs: 'vm', templateUrl : 'templates/CustomModal.html', size: size, resolve: { items: function() { return { title: title, message: message }; } } }); }; return { open: open };}
<script type="text/ng-template" id="templates/CustomModal.html"> <div > <h3 >{{vm.content.title}}</h3> </div> <div > {{vm.content.message}} </div> <div > <button type="button" ng-click="vm.confirm()"> confirm </button> <button type="button" ng-click="vm.cancel()"> cancel </button> </div></script><button modal-trigger size="'sm'" title="'Hello World!'" message="'This is a test'"> Click Me</button>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)