带有动态模板和控制器的角度弹出窗口

时间:2015-09-16 20:08:55

标签: angularjs

我找到了以下产生弹出窗口的代码。

angular.module('plunker', ['ui.bootstrap', 'myModal']);

angular.module("myModal", []).directive("myModal", function ($modal, $timeout) {
"use strict";
return {
  template: '<div ng-click="clickMe(rowData)" ng-transclude></div>',
  replace: true,
  transclude: true,
  scope: {
    rowData: '&myModal' 
  },
  link: function (scope, element, attrs) {
    scope.clickMe = function () {
        $modal.open({
        template: "<div>Created By:" + scope.rowData().data + "</div>"
                    + "<div class=\"modal-footer\">"
                    + "<button class=\"btn btn-primary\" ng-click=\"ok()\">OK</button>"
                    + "<button class=\"btn btn-warning\" ng-click=\"cancel()\">Cancel</button>"
                    + "</div>",
        controller: function ($scope, $modalInstance) {
            $scope.ok = function () {
                $modalInstance.close({ test: "test"});
            };

            $scope.cancel = function () {

            };

            $timeout(function () {
                        $(".modal-dialog").draggable();

                        var resizeOpts = {
                            handles: "all", autoHide: true
                        };

                        $(".modal-dialog").resizable(resizeOpts);
                    }, 0);
        },
        backdrop: "static"
    });
    }
  }
};
});

我想使这个代码通用,并动态分配模板及其控制器。我想我可以指定一个内置控制器的模板但是想避免这样做。

由于

0 个答案:

没有答案