在Angular JS中注入控制器的问题

时间:2016-05-29 07:27:19

标签: angularjs angular-material

我尝试为对话框定义一个控制器,如Angular Material示例中所示(here

app/models/concerns/rent_readiness.rb

但我总是这样:

  

错误:[$ injector:unpr]未知提供程序:DialogControllerProvider< - DialogController< - MainController

1 个答案:

答案 0 :(得分:0)

您无法注入控制器。因此,从DialogController中的依赖项注入参数中删除MainController,并使用controller: 'DialogController'进行对话:

TestApp.controller('MainController', function MainController($scope, $mdDialog, $mdMedia) {

  // ...

  $scope.showImprintDialog = function(ev) {
    var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
    $mdDialog.show({
        controller: 'DialogController',
        templateUrl: 'impressum.html',
        parent: angular.element(document.body),
        targetEvent: ev,
        clickOutsideToClose: true,
        fullscreen: useFullScreen
      })
      .then(function(answer) {
        $scope.status = 'You said the information was "' + answer + '".';
      }, function() {
        $scope.status = 'You cancelled the dialog.';
      });
    $scope.$watch(function() {
      return $mdMedia('xs') || $mdMedia('sm');
    }, function(wantsFullScreen) {
      $scope.customFullscreen = (wantsFullScreen === true);
    });
  };

  // ...

});

演示: https://plnkr.co/edit/46YtlQbndPQ4n27uGFGQ?p=preview