2017-05-29 31 views
0

我有一個問題。我是Angular 2的新成員,我試圖在變量中存儲一個簡單的值。我調用一個get方法返回一個數字(在C#中的後端)。我怎樣才能將這個值存儲在一個全局變量?Angular 2 - 從方法存儲值GET

getTarea(a,b,c,d,e){ 
     return this._http.get('http://localhost:50790/ApiProductoTipo/TareaPT?delegacionId='+a+'&municipioId='+b+'&ejercicioId='+c+'&ninternoId='+d+'&tipo='+e) 
      .map(res=> {alert('Tarea:'+res);}) 
      .catch(this.handleError); 
    } 

此代碼打印

利亞:響應狀態爲:200 OK的網址:http://localhost:50790/ApiProductoTipo/TareaPT?delegacionId=11&municipioId=1&ejercicioId=2017&ninternoId=-1&tipo=T

但我需要返回此方法的數值。有任何想法嗎?

返回

[HttpGet] 
public int GetTareaPT(int delegacionId, int municipioId, int ejercicioId, int ninternoId, string tipo) 
{ 
    int numtarea = this.productoTipoService.GetTareaPT(delegacionId, municipioId, ejercicioId, ninternoId, tipo); 

    if (numtarea != 0) 
    { 
     return numtarea; 
    } 
    else 
    { 
     return 0; 
    } 
} 
+0

首先你要的JSON:'.MAP(RES => {警報( '利亞:',res.json ());})' – Alex

+1

或文本:'.map(res => {alert('Tarea:'+ res.text());})' – PierreDuc

+0

@PierreDuc true,我總是忘記一個:D – Alex

回答

0

解決由於AJT_82做

.map(res=> {alert('Tarea:', res.json());})