您好我安装了以下模块https://github.com/likeastore/ngDialog
它工作得很好但是我无法从控制器中打开对话框,我这样做:
var app = angular.module('app', ['ngRoute','ngAnimate','ngSanitize','ngDialog']);
app.controller('SignupController', function($rootScope,$scope) {
$scope.signup = function(){
var error = false,
error_list = "ERRORS";
if(!$scope.signup_username){
error = true;
error_list += "\n\n Username \n " + $rootScope.errors.required_field;
}if(!$scope.signup_email){
error = true;
error_list += "\n\n Email \n " + $rootScope.errors.valid_email;
}if(!$scope.signup_password){
error = true;
error_list += "\n\n Password \n " + $rootScope.errors.required_field;
}
if(error){
ngDialog.open({template:error_list,plain:true});
}else{
//register
}
}
});
但它没有按预期工作,因为我得到控制台错误: ngDialog未定义。
答案 0 :(得分:7)
您的控制器不依赖于ngDialog,因此它在运行时是一个未知变量。
app.controller('SignupController', function($rootScope, $scope, ngDialog) {
$scope.signup = function(){
var error = false,
error_list = "ERRORS";
if(!$scope.signup_username){
error = true;
error_list += "\n\n Username \n " + $rootScope.errors.required_field;
}if(!$scope.signup_email){
error = true;
error_list += "\n\n Email \n " + $rootScope.errors.valid_email;
}if(!$scope.signup_password){
error = true;
error_list += "\n\n Password \n " + $rootScope.errors.required_field;
}
if(error){
ngDialog.open({template:error_list,plain:true});
}else{
//register
}
}
});