Function implementation is missing or not immediately following the declaration, TypeScript class
The issue here is that you have some "code execution" (console.log(this.users);
) outside an "executable area" (for instance the "area" inside the ngOnInit
).
If you need to do console.log(this.users);
in order to see the data in the devtools, you should move the console.log
part inside the ngOnInit
which is an executable part of you class MyComponent
or maybe inside the constructor
.
I would recommend you to do it like this:
ngOnInit(): void { this.tstService.getTstWithObservable() .map(result => result.map(i => i.user.data)) .subscribe( res => { this.users = res; console.log(this.users); // <-- moved here! } );}
The thing is the code you're trying to execute needs to be inside some method which Angular executes.
See this demo with some examples. The relevant code is below:
export class AppComponent implements OnInit{ name = 'Angular 6'; constructor() { console.log(name); // OK } ngOnInit() { console.log('sample not giving error'); // OK } // comment line below and the error will go away console.log(name); // this will throw: Function implementation is missing or not immediately following the declaration}