UI引导模式的控制器“没有定义” [英] ui bootstrap modal's controller 'is not defined'

查看:196
本文介绍了UI引导模式的控制器“没有定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用模态指令,从用户界面,引导0.6

i am trying to use the modal directive from ui-bootstrap 0.6

下面是从UI的引导页面的工作默认plunker:

here is the working default plunker from the ui-bootstrap page:

<一个href=\"http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=$p$pview\">http://plnkr.co/edit/JGBiBSeRqOnwRhYA9py8?p=$p$pview

现在,我试图使编码风格适合棱角分明种子风格包括在像这样的应用程序:

now, i tried to make the coding style fits angular-seed style to include it in one app like this :

<一个href=\"http://plnkr.co/edit/Y59rwlcNpQdijKtmjOPy?p=$p$pview\">http://plnkr.co/edit/Y59rwlcNpQdijKtmjOPy?p=$p$pview

angular.module('MyModal', ['ui.bootstrap', 'MyModal.controllers']);

angular.module('MyModal.controllers', [])
    .controller('ModalDemoCtrl', [ '$scope', '$modal', '$log', function ($scope, $modal, $log) {
    $scope.items = ['item1', 'item2', 'item3'];

    $scope.open = function () {
        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: ModalInstanceCtrl,
            resolve: {
                items: function () {
                return $scope.items;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
        }, function () {
            $log.info('Modal dismissed at: ' + new Date());
        });
    };
}])
.controller('ModalInstanceCtrl', [ '$scope', '$modalInstance', 'items', function ($scope, $modalInstance, items) {
    $scope.items = items;
    $scope.selected = {
        item: $scope.items[0]
    };

    $scope.ok = function () {
        $modalInstance.close($scope.selected.item);
    };

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

但它给了一个错误的ReferenceError:未定义ModalInstanceCtrl

我怎样才能使用定义控制器的这种方式这项工作?

how can i make this work using this way of defining controllers ?

推荐答案

提供控制器名称的字符串的,正如你会在路由定义,指令等做的:

Provide controller name as String, exactly as you would do in route definitions, directives etc.:

var modalInstance = $modal.open({
        templateUrl: 'myModalContent.html',
        controller: 'ModalInstanceCtrl',
        resolve: {
            items: function () {
            return $scope.items;
            }
        }
    });

这篇关于UI引导模式的控制器“没有定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆