Response of Http Api call promise is undefined - Angular 2

后端 未结 2 346
滥情空心
滥情空心 2021-01-27 04:15

I have created an api in WebAPI as below.

public HttpResponseMessage Get() {

            var response = Request.CreateResponse(HttpStatusCode.OK);
            r         


        
2条回答
  •  温柔的废话
    2021-01-27 04:42

    Put the console.log inside the data function.

    Could you try like this.

    export class AppComponent implements OnInit  { 
    
      data2: String;
      constructor(private s: DemoService){} 
    
      ngOnInit(){
    
        this.s.GetHttpData().subscribe(data=>{
            this.data2=data;
            console.log("Http call  completed: "+this.data2)
        });
    
    }
    

提交回复
热议问题