0

i have some directive:

.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]
    }
}])

I using angular bootstrap modal, and I want something like this:

<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>

Of course it's not working because there is no controller like modalOptions.templateController, I want controller name under this variable.

Short: I need something like directive compile in bootstrap modal

Alcadur
  • 681
  • 1
  • 8
  • 22
  • Couldn't you just access the options from the contoller? I would also suggest you use controllerAs. For example @defaultModalController. User controllerAs modalCtrl and then access the options like this. modalCtrl.options.yourproperty – Olavi Sau Oct 22 '15 at 21:37
  • No, I have main modal controller and after set `templateUrl` I would like have extra controller on `modal-body` element, or some way extend `DefaultModalController` by `templateController` – Alcadur Oct 22 '15 at 21:54
  • http://stackoverflow.com/questions/25417162/how-do-i-inject-a-controller-into-another-controller-in-angularjs is this what you mean? – Olavi Sau Oct 22 '15 at 22:02
  • `$controller` unfortunately doesn't work in directive: http://codepen.io/anon/pen/vNdpKa – Alcadur Oct 23 '15 at 06:42

1 Answers1

0

Currently I created multiple views for different controllers

Alcadur
  • 681
  • 1
  • 8
  • 22