I am facing an issue where I have data collected from a service in the form of an interface type object, but I am unable to find or filter a key within this object.
The specific error message I am encountering is: ERROR TypeError: Cannot read property 'userAccess' of undefined at ShowBranchuserComponent.push../src/app/pages/userrelated-page/show-branchuser/show-branchuser.component.ts.ShowBranchuserComponent.ngOnInit (show-branchuser.component.ts:42)
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { UserrelatedService } from '../userrelated-page.service';
import { UserRegister } from 'app/shared/model/Register';
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
import { RouteInfo } from 'app/shared/sidebar/sidebar.metadata';
import {map} from 'rxjs/operators';
@Component({
selector: 'app-show-branchuser',
templateUrl: './show-branchuser.component.html',
styleUrls: ['./show-branchuser.component.scss']
})
export class ShowBranchuserComponent implements OnInit {
showuser: UserRegister;
pname;
regularForm: FormGroup;
access:RouteInfo[];
constructor(private _AR:ActivatedRoute,
private _router: Router,
private _userRelated: UserrelatedService,
private _fb: FormBuilder) {
this._AR.params.subscribe(data=>{this.pname = data['id']})
}
ngOnInit() {
this._userRelated.getOneUser(this.pname).subscribe(data=> this.showuser = data);
this.regularForm = this._fb.group({
'id': [{value:'', disabled: true}, Validators.required],
'name':[{value:'', disabled: true}, Validators.required],
'username':[{value:'', disabled: true}, Validators.required],
'role':[{value:'', disabled: true}, Validators.required],
'status':[{value:'', disabled: true}, Validators.required],
'state':[{value:'', disabled: true}, Validators.required],
'pincode':[{value:'', disabled: true}, Validators.required],
'mobileno':[{value:'', disabled: true}, Validators.required],
'address':[{value:'', disabled: true}, Validators.required],
});
this.access = this.showuser.userAccess; // The problematic line triggering the error is here
console.log(this.showuser);
}
onReactiveFormSubmit(){
}
}