angular.module('MyApp',['ngMaterial','ngMessages','material.svgAssetsCache'])
.controller('AppCtrl', function ($scope, $mdDialog, ) {
$scope.showAdvanced = function (ev) {
$mdDialog.show({
controller: DialogController,
templateUrl: 'dialog1.tmpl.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true
})
};
function DialogController($scope, $mdDialog) {
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
$scope.answer = function (answer) {
$mdDialog.hide(answer);
};
}
});
出现错误 有谁可以帮忙解决?
答案 0 :(得分:0)
您必须注册DialogController
才能使用它,并将其作为string
的名称引用提供给AppCtrl。
您的代码应该像:
angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function ($scope, $mdDialog) {
$scope.showAdvanced = function (ev) {
$mdDialog.show({
controller: 'DialogController', // notice single qoutes here
templateUrl: 'dialog1.tmpl.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true
})
}) // end of 'AppCtrl'
.controller('DialogController', function ($scope, $mdDialog) {
$scope.hide = function () {
$mdDialog.hide();
};
$scope.cancel = function () {
$mdDialog.cancel();
};
$scope.answer = function (answer) {
$mdDialog.hide(answer);
};
}); // end of 'DialogController'