-2

I trying to get data using web api in angular7 but i'm facing [object object] issue.

auth.service.ts

getCareer(){
    return this._HttpClient.get('http://localhost:49345/api/website/getCarrier');
    }

component.ts

export class careerComponent implements OnInit{

    getCareer$: object;

     constructor(private _AuthService: AuthService){ }

     ngOnInit(){
        this._AuthService.getCareer().subscribe(
        data => this.getCareer$ = data
    );
    }


}

component.html

<div class="col-xl-6" *ngFor="let career of getCareer$">
                    <h2>test</h2>
                    <h3>{{career.designation}}</h3>
                </div>

Issue/console screenshot

enter image description here

API Screenshot

enter image description here

How can i solve it?

2

1 Answer 1

0
`ngOnInit(){
    this._AuthService.getCareer().subscribe(
    data => { this.getCareer$ = data.data.map(item => {
            return item.designation
         })
});
}`

change the code as above..hope it will work. now the getCareer$ contains all the designations

Sign up to request clarification or add additional context in comments.

4 Comments

how to get in component.html?
<div class="col-xl-6" *ngFor="let career of getCareer$"> <h2>test</h2> <h3>{{career}}</h3> </div>
can you please check data inside getCareer$ ?
input = {"data":[{designation:"desig1"},{designation:"desig2"},{designation:"desig3"}]} this is the sample data i was trying with... and the code is expected = input.data.map(item => {return item.designation})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.