我做與實時更新的儀表板指定默認值,所以當一個DB返回$ HTTP調用空對象後,我想指定默認值爲零AngularJS:綁定值
$scope.SAP=0;
$http({
\t \t \t method: 'GET',
url: 'getTilesDataForPrjectReport.do',
\t \t }).then(function(response){
\t \t \t \t if(response.data.proj==='SAP'){
\t \t \t \t \t $scope.SAP=response.data;
\t \t \t \t }
\t \t \t }
\t \t });
<div style="height:20%; background-color:#ff9e97;">
\t <p id="colorPalletDashboardTileRed"> {{SAP.red}}</p>
\t <p id="colorPalletDashboardTileAmber">{{SAP.amber}}</p>
\t <p id="colorPalletDashboardTileGreen">{{SAP.green}}</p>
\t </div>
\t <div style="height:18%; background-color:#ff8a81;">
\t <p> Total Projects : {{SAP.totalProj}} </p>
\t </div>
如果SAP沒有響應數據,我需要在所有SAP綁定中顯示0,即使我將0賦給$ scope.SAP,它也不會在html中反映。我知道這可能與NG隱藏來實現與另一<p>
標籤,但什麼是最簡單的解決方案
你能粘貼您的JSON響應嗎? –