1

您好我安装了以下模块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 is not defined

4

1 回答 1

8

您的控制器不依赖于 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
        }
    }
});
于 2014-01-29T10:27:48.123 回答