0
I have looked here in the stack but I did not find the answer. Does anyone know if you can access a variable that is inside the ngAfterViewInit() in Angular.
In the code below, in the last line when I try to assign the variable motivo
for motivoTitulo
, ide informs me that "Unable to find the name 'reason'".
ngAfterViewInit() {
const controlBlurs: Observable < any > [] = this.formInputElements
.map((formControl: ElementRef) => Observable.fromEvent(formControl.nativeElement, 'blur'));
const self = this;
let motivo: string;
this.swal.showSwalConfirmText(function(confirmacaoMotivo) {
if (confirmacaoMotivo) {
motivo = confirmacaoMotivo;
self.removerTitulo();
} else {
self.cancelar();
}
});
}
motivoTitulo = motivo;
Why don’t you move that line into the afterviewinit?? In javascript and most languages will only exist within its scope for example a function
– Eduardo Vargas
thanks @Eduardovargas .. is pq need to use this variable in another function within that same component. In the function I will use, I try to assign the variable but it comes as Undefined:
let tituloHistorico = new TituloHistorico();


 tituloHistorico.motivo = this.swal.motivoTitulo;
– Lucas Latorre
this.algumacoisa = things that are xistenafuncao;
– Eduardo Vargas
No, but why don’t you declare the variable motive outside the
ngAfterViewInit()
if you want to use the value assigned to it outside viewInit?– LeAndrade
@Eduardovargas tried with
this.motivo = confirmacaoMotivo;
outside ngAfterViewInit() but says "Unable to find the name 'confirmationMotive'"– Lucas Latorre
@Leandrade then guy, I tried to assign with
motivo = confirmacaoMotivo;
outside of Ngafterviewinit() but says "Unable to find the name 'confirmationMotive'."– Lucas Latorre
I will edit my reply and enter what your code should look like.
– LeAndrade