无法读取undefined属性'open'

时间:2015-06-02 19:19:12

标签: angularjs angular-bootstrap

我正在尝试使用angular-bootstrap,但我一直收到错误Cannot read property 'open' of undefined

以下是我如何使用它。

在我的index.html中,我已将其包含在内

<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.min.js"></script>
app.js中的

angular
    .module('MyApp', ['ngRoute', 'ngResource', 'ui.bootstrap', 
        'angularDjangoRegistrationAuthApp', 'http-auth-interceptor',
        'angularPayments', 'angularApp'])

在我的控制器中

'use strict';

angular.module('MyApp')
    .controller('SubscriptionCtrl', ['$scope','$rootScope',
    'djangoAuth','LoginRequired','Validate','$location',
    function($scope, $rootScope, djangoAuth, LoginRequired, Validate, $location, $modal) {

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

HTML

打开我!

错误 当我点击“打开我!”时我收到以下错误:

TypeError: Cannot read property 'open' of undefined

1 个答案:

答案 0 :(得分:4)

您忘了表示您需要$modal作为您功能的依赖:

angular.module('MyApp').controller('SubscriptionCtrl',
    ['$scope','$rootScope', 'djangoAuth', 'LoginRequired', 'Validate', '$location', '$modal',
    function($scope, $rootScope, djangoAuth, LoginRequired, Validate, $location, $modal) {
     ...