Models and Services Angular 4 [closed]

-1

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?

    
asked by jara 13.11.2017 в 22:02
source

1 answer

0

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)

    
answered by 13.11.2017 / 23:07
source