0

I have some data coming from rest API where the model property of myobject is an array, but when I map it via creating service it converts it to string. Please see my code below.

  //from inteface =>
  export interface Car{
     make:string;
     model :Array<any>;
  }
  //from service => 
  getCars():Observable<Car[]> {
    return this._http.get(this._getUrl)
        .map(response=>response.json())
   }
  //from component= >
    this._carservice.getCars()
        .subscribe(cars=> {
            this.cars = cars;
            for(var i = 0; i<this.cars.length;i++){
                console.log(this.cars[i].Model)
            }
   });
  // OutPut 
  "Saloon,Estate,Coupe"
  //required OutPut
  [Saloon,Estate,Coupe]
2
  • The server probably sends it as string. Commented Jul 4, 2016 at 12:53
  • 1
    Thanks Günter, i forget to restart node after making changes to my model..i thought forever will take control of it.. Thanks a lot anyway.. Commented Jul 4, 2016 at 13:00

1 Answer 1

1

Issue on server side, The server was sending it as string..resolved by changing model in node

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

Comments

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.