AngularUI模态文档困惑

时间:2014-09-11 11:25:13

标签: angularjs angular-ui angular-ui-bootstrap

我是Angular的新手,并且对AngularUI模式对话框的文档感到困惑。我看不出那里提供的代码如何适合主页的控制器,或者主页上的按钮在点击时如何打开模态对话框。

http://angular-ui.github.io/bootstrap/

ModalDemoCtrl是否应该追加到主页应用的控制器?

  var myApp = angular.module('myApp', ['ui.bootstrap']);

  var ModalDemoCtrl = function($scope, $modal, $log) {
        <snip>
  }
  myApp.controller("ModalDemoCtrl");

ModalDemoCtrl函数对象是否只是嵌套在主页面的控制器中?

 var myApp = angular.module('myApp', ['ui.bootstrap']);

 myApp.controller("MainPageCtrl", function($scope, $modal, $log) {

       var ModalDemoCtrl = function($scope, $modal, $log) {
        <snip>
        }
});

1 个答案:

答案 0 :(得分:1)

基本上它是一个常规控制器:

var modal = $modal.open({
       templateUrl: 'deleteDialog.html',
       controller: 'deleteDialogController'
});

modal.result.then(function () {

});

deleteDialogController.js文件:

appModule.controller("deleteDialogController", [ "$scope", "$modalInstance",
    function ($scope, $modalInstance)
    {
        $scope.ok = function () {
            $modalInstance.close();
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }
]);