I was trying to put the data[0] from ApiService to this.data.
However, it failed. Can anyone please guide me on this?
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApiService } from '../services/api.service';
@Component({
selector: 'app-card-details',
templateUrl: './card-details.component.html',
styleUrls: ['./card-details.component.scss']
})
export class CardDetailsComponent implements OnInit {
name: string = "";
data: any;
constructor(
private route: ActivatedRoute,
private apiService: ApiService,
) { }
ngOnInit() {
this.getData();
}
getData(){
this.route.params.subscribe(params => this.name = params['name']);
this.apiService.getName(this.name).subscribe(data => {
this.data = data[0];
console.log(this.data); \\ console.log at here able to show the value of this.data
})
console.log(this.data); \\ console.log at here NOT able to show the value of this.data
}
}