未知提供者:eProvider< - e显示材料角度对话框

时间:2015-03-21 00:59:00

标签: angularjs modal-dialog angular-material

我正试图将material angular的对话连接起来。代码如下。我收到错误Unknown provider: eProvider <- e

的js

var app = angular.module('app', ['ngMaterial']);

var dialogController = app.controller('dialogController', ['$scope', '$mdDialog', function($scope, $mdDialog) {
    $scope.hide = function () {
        $mdDialog.hide();
    };
    $scope.cancel = function () {
        $mdDialog.cancel();
    };
    $scope.answer = function (answer) {
        $mdDialog.hide(answer);
    };
}]);

app.controller('mainController', ['$scope', '$http', '$mdDialog', function ($scope, $http, $mdDialog) {
    $scope.showDialog = function (e) {
        e.preventDefault();
        $mdDialog.show({
            controller: dialogController,
            templateUrl: 'sign-in.html',
            targetEvent: e
        });
    };
}]);

HTML

<a href="#" ng-click="showDialog($event)">Show dialog</a>

<script type="text/ng-template" id="sign-in.html">
    hello there
</script>

我错过了什么吗?

2 个答案:

答案 0 :(得分:2)

var app = angular.module('app', ['ngMaterial']);

var dialogController = function($scope, $mdDialog) {
   $scope.hide = function () {
      $mdDialog.hide();
   };
   $scope.cancel = function () {
      $mdDialog.cancel();
   };
   $scope.answer = function (answer) {
       $mdDialog.hide(answer);
   };
};

app.controller('mainController', ['$scope', '$http', '$mdDialog', function ($scope, $http, $mdDialog) {
    $scope.showDialog = function (e) {

      $mdDialog.show({
         controller: dialogController,
         templateUrl: 'sign-in.html',
         targetEvent: e
      });
   };
}]);

HTML称之为:

 <md-button class="md-primary" ng-click="showDialog($event)">Show dialog</md-button>

答案 1 :(得分:0)

尝试将单引号添加到控制器名称:

$mdDialog.show({
    controller: 'dialogController',
    templateUrl: 'sign-in.html',
    targetEvent: e
});

修改 我有一件事要更新,我知道为什么错误&#34;&#39; getBoundingClientRect&#39;未定义&#34;发生。您必须将此脚本用作模板:

<script type="text/ng-template" id="sign-in.html">
    <md-dialog> 
        <md-content>Hello there</md-content> 
    </md-dialog>    
</script>

顺便说一句,我对单引号的回答应该是第一次。使用这个新模板再试一次。