i have 2 controllers Login and Register using Controller As syntax like this
(function(app){
function Register(){
}
angular.extend(Register.prototype, {
isValid: true,
errors: {},
setError: function(field, condition){
var errors = this.errors;
if (!errors[field]) errors[field] = {};
errors[field][condition] = true;
this.isValid = false;
},
validationInputs: function(){
if(this.name.length == 0) this.setError("name", "required");
return !this.isValid;
}
});
app.controller("registerCtrl", [Register]);
})(angular.module("app.controllers"));
(function(app){
function Login(){
}
angular.extend(Login.prototype, {
isValid: true,
errors: {},
setError: function(field, condition){
var errors = this.errors;
if (!errors[field]) errors[field] = {};
errors[field][condition] = true;
this.isValid = false;
},
validationInputs: function(){
if(this.name.length == 0) this.setError("name", "required");
return !this.isValid;
}
});
app.controller("loginCtrl", [Login]);
})(angular.module("app.controllers"));
I want to put setError method to rootScope for Login and Register controller inherit from it, Do i need to write rootScope controller using Controller Syntax ? How do i implement it ?