代码之家  ›  专栏  ›  技术社区  ›  wmash

TypeError:提供的范围$new不是函数-角度引导模式

  •  1
  • wmash  · 技术社区  · 9 年前

    我一直在遵循官方指南 here 但我仍然得到错误。上的用户 GitHub 经历了同样的问题,但没有提到如何解决,只是他的代码调用他的工厂时出现了错误,我无法从他的 plnkr .

    控制器:

    function ActivitiesController($scope, $state, $window, Authentication, activity, $uibModal, $uibModalInstance) {
        var vm = this;
    
        vm.authentication = Authentication;
        vm.activity = activity;
        vm.openModal = openModal;
        vm.okOnModal = okOnModal;
        vm.cancelOnModal = cancelOnModal;
    
        function openModal() {
            $uibModal.open({
                template: "<div class='modal-header'>"
                            + "<h3 class='modal-title' id='modal-title'>Friends</h3>"
                        + "</div>"
                        + "<div class='modal-body list-group' id='modal-body'>"
                            + "<a ng-repeat='friend in vm.friends' class='list-group-item'>"
                                + "<img class='friend-user-profile-picture' ng-src='{{ friend.friend.profileImageURL }}' alt='{{ friend.friend.displayName }}'>"
                                + "<h4 class='list-group-item-heading' ng-bind='friend.friend.displayName'></h4>"
                                + "<small class='list-group-item-text' ng-bind='friend.friend.username'></small>"
                                + "<p class='list-group-item-text' ng-bind='friend.friend.email'></p>"
                                + "<input type='checkbox'>"
                            + "</a>"
                        + "</div>"
                        + "<div class='modal-footer'>"
                            + "<button class='btn btn-primary' type='button' ng-click='vm.okOnModal()'>OK</button>"
                            + "<button class='btn btn-warning' type='button' ng-click='vm.cancelOnModal()'>Cancel</button>"
                        + "</div>",
                size: 'lg',
                scope: vm
            });
        }
    
        function okOnModal() {
            $uibModalInstance.close();
        }
    
        function cancelOnModal() {
            $uibModalInstance.dismiss('cancel');
        }
    }
    

    查看:

    <button class="btn btn-primary btn-lg" ng-click="vm.openModal()">Share with...</button>
    

    错误在 ui.bootstrap-tpls 在这里:

    var modalScope = providedScope.$new();
    

    依赖关系:

    • 角度: 1.4.8 (从 0.3 )
    • 角度自举: 2.4.0 (从 0.13.4 )
    • 引导: 3.3.7
    • MEAN.JS: 0.4.2

    平均阅读。JS文档, 0.4.2 使用角度用户界面 0.13.4 这不支持 $uibModal .因为不支持它,所以我升级到 2.4.0 没有提到MEAN.JS 0.4.2 不支持角度用户界面 2.4.0 但这可能是潜在的原因吗?


    编辑:

    我已经排除了依赖性版本的问题,因为我已经改回了默认版本,而默认版本是“0.4.2”。JS堆栈 (如此使用 $modal 而不是 $uibModal ) 我得到一个类似的错误:

    类型错误:(modalOptions.scope ||$rootScope)$new不是一个函数

    1 回复  |  直到 9 年前
        1
  •  10
  •   Estus Flask    9 年前

    vm 作为模态的父范围提供。这就是问题所在,因为 虚拟机 不是作用域。它是当前作用域上的控制器实例和对象(如果 controllerAs 使用语法)。

    虚拟机 不应该与 $scope 。应该是:

    scope: $scope