Skip to content Skip to sidebar Skip to footer

How To Initialize Object, Array And Object-array In Angular Service Class?

How to initialize an object inside an object and array-object in angular service class? I want to use the two-way binding into my-form, so I want to pass the variable from service

Solution 1:

you can create multiple model classes. you can update the current model and create a TrainerName.ts class that holds the name object and Language.ts that holds the language object. like this:

export class TrainerName{
 first_name: String,
 last_name: String
}

and Language model class like :

export class Language {
items:  String       
}

and use it in your current model class like:

export class Trainner {
personal_details: { type: Object,
    name: TrainerName,
    dob: String,
    about_yourself: String,
    languages_known: Language[],
    willingly_to_travel: String
};

}

and in your service you can use map

getAllTrainner(): Observable<Trainner[]> {
    return this._http.get<Trainner[]>(this._url, headerOption).map(res => new Trainner(res));
  }

Post a Comment for "How To Initialize Object, Array And Object-array In Angular Service Class?"