2017-08-17 156 views
0

HTML代碼:如何在HTML中顯示Json數據?

<button type="button" (click)="callJoke()">Get joke</button> 
<h1>{{msg[1].joke.value}}</h1> 

JSON數據:

{ 
    "type":"success", 
    "value":{ 
     "id":533, 
     "joke":"The Chuck Norris Eclipse plugin made alien contact.", 
     "categories":[ 
     "nerdy" 
     ] 
    } 
} 

MSG是一個對象,即時從API響應得到

+1

嘗試msg.value.joke,因爲msg不是數組 – Vivz

回答

1

嘗試使用角json管:

<h1>{{msg.joke.value | json}} </h1>