$ mdDialog传递本地未知提供者

时间:2016-05-17 18:51:32

标签: angularjs angular-material mddialog

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

这是我父控制器中的代码

 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) {

1 个答案:

答案 0 :(得分: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]);

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