未知提供者:显示材料角度对话框时的电子提供者 <- e



我正在尝试连接材质角度的对话框。下面的代码。我收到错误,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>

我遗漏了什么吗?

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>

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

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

编辑:我有一件事要更新,我知道为什么会发生错误"未定义的'getBoundingClientRect'"。你必须使用这个脚本作为模板:

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

顺便说一句,我关于单引号的回答应该在第一时间起作用。请使用此新模板重试。

相关内容

最新更新