0

How can i access subjects in Json response and take the value which in types using typescript ?

Json Response :

{
"$id": "1",
"Council_ID": 102,
"place": "bla bla bla",
"number": "4644",
"type": 2,
"user_Id": 15,
"subjects": [
    {
        "$id": "2",
        "subjectCode": "464",
        "type": 1,
        "branch": "cairo",
        "gender": true
    },
    {
        "$id": "3",
        "subjectCode": "466",
        "type": 5,
        "branch": "alex",
        "gender": true
    }
],
"absence": []
}

meeting.component.ts :

this.dataStorageService.getCouncilId(this.meetingID).subscribe(response => {
                this.subjectsWithID = response.json();
                console.log(this.subjectsWithID, 'All Response')
                this.typee = this.subjectsWithID.subjects.type;
                console.log(this.typee, 'bla bla');
            });

2 Answers 2

1

Here is how to access the values

this.subjectsWithID.Council_ID; // 102
this.subjectsWithID.type; // 2
this.subjectsWithID.$id; // '1'
this.subjectsWithID.subjects[0].$id; // '2'
this.subjectsWithID.subjects[0].type; // 1
this.subjectsWithID.subjects[1].$id; // '3'
this.subjectsWithID.subjects[1].type; // 5
Sign up to request clarification or add additional context in comments.

1 Comment

i got it ,Thank you for helping :)
0

I might have misunderstood your question. If so please provide some example of the desired output.

this.dataStorageService
    .getCouncilId(this.meetingID)
    .map(json)
    .map(response => response.subjects.map(subject => subject.type))
    .subscribe(response => { ... });

1 Comment

i wanna have the value of types to use it in another function .. i want to make this.typee = 1 the value of first element in subjects

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.