At line 16 i change the value of email. At line 17 i can print the correct value of the email. But, why at line 20 i can't print the new value of the email? At line 20 the console.log prints the value of email at line 5 (''). I'll need the value of email at line 22. How can i do that?
1. export class SettingsComponent implements OnInit {
2. private token: string | null = '';
3. public settings! : Settings;
4. public settingsForm!: FormGroup;
5. public email: string | null = '';
6. constructor(
7. private SettingsService: SettingsService,
8. private formBuilder: FormBuilder) { }
9. ngOnInit(): void {
10. this.token = localStorage.getItem('token');
11. if (this.token){
12. this.SettingsService
13. .getSettings(this.token)
14. .subscribe(res => {
15. this.settings = JSON.parse(JSON.stringify(res));
16. this.email = this.settings.email;
17. console.log(this.email);
18. },err => {
19. console.log(err); })
}
20. console.log(this.email);
21. this.settingsForm = this.formBuilder.group({
22. email: [this.email]
});
}
I want to change the value of an property and then use this value later.