3

我正在尝试连接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>

我错过了什么吗?

4

2 回答 2

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>
于 2015-03-21T13:45:37.417 回答
0

尝试在控制器名称中添加单引号:

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

编辑: 我有一件事要更新,我知道为什么会发生错误“'getBoundingClientRect' of undefined”。您必须将此脚本用作模板:

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

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

于 2015-03-21T01:53:37.447 回答