0

我见过很多像我这样的问题,但答案似乎并没有解决我的问题。奇怪的是它以前工作过。此外,当我在用于对话框的控制器中放置断点时,用于传递值的变量不为空。该值已正确传递,但仍然是未知的提供程序错误

这是我的父控制器中的代码

 function addFaq(category, ev){

    $mdDialog.show({
        controller: 'newfaqController'
        , templateUrl: './app/components/faq/modals/newFaq.html'
        , parent: angular.element(document.body)
        , targetEvent: ev
        , bindToController: true
        , clickOutsideToClose: true
        , locals: {
            newFaqCategory: category
         }
        , controllerAs: vm
    }).then(function(result){
        if(result){
            vm.allFaqs.push(result);
        }
    });

    $scope.$watch(function () {
        return $mdMedia('xs') || $mdMedia('sm');
    }, function (wantsFullScreen) {
        $scope.customFullscreen = (wantsFullScreen === true);
    });
};

这些是我的对话控制器的第一行

 angular.module('MyApp').controller('newfaqController', ['$mdDialog', 'newFaqCategory', 'apiFactory', newfaqController]);
function newfaqController($mdDialog, newFaqCategory, apiFactory) {
4

1 回答 1

2

您是否也将调用 $mdDialog 的控制器引用为 vm ?我遇到了与此冲突,并且我们将 dvm(对话框视图模型)作为 $mdDialog 中的控制器引用。

这就是答案,我也可以让“ControllerAs”远离选项。但仍然必须在我的模态控制器中将 vm 更改为 dvm

 function addFaq(category, ev){

    $mdDialog.show({
        controller: 'newfaqController'
        , templateUrl: './app/components/faq/modals/newFaq.html'
        , parent: angular.element(document.body)
        , targetEvent: ev
        , bindToController: true
        , clickOutsideToClose: true
        , locals: {
            newFaqCategory: category
         }
    }).then(function(result){
        if(result){
            vm.allFaqs.push(result);
        }
    });

    $scope.$watch(function () {
        return $mdMedia('xs') || $mdMedia('sm');
    }, function (wantsFullScreen) {
        $scope.customFullscreen = (wantsFullScreen === true);
    });
};

还有我的模态控制器

angular.module('MyApp').controller('newfaqController', ['$mdDialog', 'newFaqCategory', 'apiFactory', newfaqController]);

函数 newfaqController($mdDialog, newFaqCategory, apiFactory) { var dvm = this;

于 2016-05-17T19:54:22.413 回答