1
I can access a class attribute within the constructor scope, but outside gives 'Undefined'
constructor(errorAlert){
this._errorAlert = errorAlert;
}
If, for example, in the code above, I give console.log()
in the received parameter and attribute, both return the same value, but when I use the attribute in the rest of the class, I cannot.
class Controller{
constructor(errorAlert){
this._errorAlert = errorAlert;
}
login(login, senha){
let $ = new Serv();
$.ajax({
'url': '/login',
'type': 'post',
'responseType': 'json',
'data': 'login='+login+'&senha='+senha
}).then(function(resolve){
let datas = resolve;
if(datas['loginStatus'] == 1){
window.location = base_url;
}else{
console.log(this._erroAlert);
view.viewErrorMessage("Usuário ou senha incorreto", this._errorAlert);
}
}).catch(function(reject){
console.log(reject);
});
}
}
The code works perfectly, my only problem is that of the scope of the same attribute.
Error:
TypeError: Cannot read property '_erroAlert' of undefined at Controller.js:19 at <anonymous>
You can put the complete code in the question, including the error message that appears on
console
?– Woss
Thanks Tom Melo! Solve, but only so if I capture the DOM element inside the constructor, but I want to pass by parameter, advises something?
– instalação planejamento