angular - asp.net core Angular2 MVC http get issue -


i new angular 2. trying data mvc controller angular 2

import { component } '@angular/core'; import { http } '@angular/http';  @component({     selector: 'subscriber',     templateurl: './subscriber.component.html',     styleurls: ['./subscriber.component.css']     }) export class subscribercomponent {      public ivm: incidentviewmodel;       constructor(private http: http) {         //this.ivm.id = "id";         this.http.get('api/form/incidentform').subscribe(res => this.ivm = res.json() incidentviewmodel); //map         console.log(this.ivm.id)     }   }  interface incidentviewmodel {     id: string;     code: string;     datetime: date;     address: address;     contact: contactviewmodel;  }  interface contactviewmodel {     firstname: string;     lastname: string;     telephone1: string;     telephone2: string; }  interface address {     street1: string; } 

this controller

namespace subscriber.controllers {     [route("api/[controller]")]     public class formcontroller : controller     {          [httpget("[action]")]         public  incidentviewmodel incidentform()         {             list<timelineviewmodel> tlvm = new list<timelineviewmodel>();             tlvm.add(new timelineviewmodel()             {                 date = datetime.now,                 notes = "notes 1",                 title = "n1"             });             tlvm.add(new timelineviewmodel()             {                 date = datetime.now.addhours(1),                 notes = "notes 2",                 title = "n2"             });             tlvm.add(new timelineviewmodel()             {                 date = datetime.now.addhours(2),                 notes = "notes 3",                 title = "n3"             });             tlvm.add(new timelineviewmodel()             {                 date = datetime.now.addhours(3),                 notes = "notes 4",                 title = "n4"             });              incidentviewmodel ivm = new incidentviewmodel()             {                 id = guid.newguid(),                 code = "12345678",                 date = datetime.now,                 contact = new contactviewmodel()                 {                     firstname = "kostas",                     lastname = "kostas",                     telephone1 = "6974123456",                     telephone2 = "2101234567"                 },                 address = new addressviewmodel()                 {                     street1 = "asdf 9"                 },                 timeline = tlvm             };             return ivm;         }     } } 

i cant bind data controller angular2 component. when try display inside console (console.log(this.ivm.id)) error unidentified think issue inside subscribe. suggestions?

the should more this:

getheroes(): observable { return this.http.get(this.heroesurl) .map(this.extractdata) .catch(this.handleerror); }

see docs complete example: https://angular.io/docs/ts/latest/guide/server-communication.html#!#fetch-data


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -