0
我有一些指令:角度引导模式
.directive("modal", [function(){
var controller = function($scope, $attrs, $element, $uibModal){
var defaultOptions = {
title: "Modal title",
content: "Modal body"
},
userOptions = {
title: $attrs.title,
content: $attrs.content,
templateUrl: $attrs.templateUrl,
templateController: $attrs.templateController
};
options = angular.extend({},defaultOptions, userOptions || {});
$element.on($scope.event, function(){
$uibModal.open({
templateUrl: defaultTemplate,
controller: "DefaultModalController",
resolve: {
options: function() {
return options
}
}
});
});
},
defaultTemplate = "templates/default-modal-template.html";
return {
restrict: "A",
scope: {
event: "@"
},
controller: ["$scope", "$attrs", "$element", "$uibModal", controller]
}
}])
我采用了棱角分明的引导模式,我想是这样的:
<section>
<header class="modal-header">
<h3 class="modal-title">{{modalOptions.title}}</h3>
</header>
<div class="modal-body" ng-if="modalOptions.templateUrl">
{{modalOptions.content}}
</div>
<div class="modal-body" ng-if="modalOptions.templateUrl" ng-include="modalOptions.templateUrl" ng-controller="modalOptions.templateController"></div>
<footer class="modal-footer">
<button type="button" class="btn btn-danger" ng-click="close()">Close</button>
</footer>
</section>
当然它不工作,因为有像没有控制器modalOptions.templateController,我想要在这个变量下的控制器名称。
短:我需要这样的东西指令在编译引导模式
多个视图,你不能只是访问从位指示的选项?我也建议你使用controllerAs。例如@defaultModalController。用户控制器作为modalCtrl然后访问这样的选项。 modalCtrl.options.yourproperty –
不,我有主模式控制器,并在设置'templateUrl'后,我想有'modal-body'元素上的额外控制器,或者''TemplateController'通过某种方式扩展'DefaultModalController' – Alcadur
http:// stackoverflow .com/questions/25417162/how-do-i-inject-a-controller-into-another-controller-in-angularjs这就是你的意思吗? –