My inconvenience is the following I am creating a system in which I have to consume a service through POSTMAN and create my services without problem my question is TO CONSUME OR CREATE A SERVICE IT IS NECESSARY TO CREATE A MODEL?
My inconvenience is the following I am creating a system in which I have to consume a service through POSTMAN and create my services without problem my question is TO CONSUME OR CREATE A SERVICE IT IS NECESSARY TO CREATE A MODEL?
If with model you mean to declare the type of data for example
Element{
id : number;
name : string;
}
It is not necessary to save the answer in a variable of type any, however it is not a good practice because one of the main characteristics of angular is to use Typescript and the main advantage of using typescript is to have a static typing
import { Injectable, DoCheck } from '@angular/core';
import { Http } from '@angular/http'
import 'rxjs/add/operator/map'
Element : any;
URL_SERVICE : string = "http://localhost:8080/mi_servicio";
constructor( private http:Http) { }
getService (){
return this.http.get(this.URL_SERVICE)
.map( res => {
this.Element = res.json().servicios_internet;
console.log(this.Element);
})
}
}
Note: my example is based on the call to a REST service that returns an object (JSON)