hydrate.component.ts
import { Component } from 'angular/core';
import { userDataService } from 'some/different/path';
@Component({
selector: 'hydrate',
templateUrl: './hydrate.component.html'
})
export class HydrateComponent implements OnInIt {
...
...
userInfo: userModel;
constructor (public userService : UserDataService) {}
ngOnInit() {
this.fetchUserInfo();
}
fetchUserInfo() {
console.log('user data:', this.userService)
//need to extract name and gender for certain logic
//need to extract name and gender for certain logic
}
user-data.service.ts
import { Injectable } from '@angular/core';
import { UserModel } from 'some/different/path';
@Injectable({
providedIn: 'root'
})
export class UserDataService{
public userData: UserModel;
constructor() {}
}
user.model.ts
export class UserModel {
gender: string;
name: string;
hasPets: boolean;
constructor(data: UserModel) {
this.name = date.name;
this.gender = data.gender;
}
}
Console Output from hydrate component -> fetchUserInfo( console.log()) Please replace > with downward solid arrow as a json structure. I could not format it
> userService {}
> userData : UserModel
name: lisa
gender: male
hasPets: true
educator: false
>hobbies: {music: Array(2), sports: Array(3)}
>_proto_: Object
Question
When I try to access the name and gender within the readUsrInfo method, this.userService.gender currently returns undefined. How can I correctly retrieve these values? Any assistance would be greatly appreciated.