0
開始學習angularjs我正在嘗試一些簡單的例子。 我想在我看來2個變量total1和total2,它們是在我的js函數中計算的。Angularjs如何返回多個變量
我的js
var total1 = 0;
var total2 = 0;
// Use the angular forEach helper method to
// loop through the services array:
angular.forEach($scope.services, function(s){
if (s.active){
total1+= s.price;
total2+= 1;
}
});
return [total1, total2];
};
我的HTML
<div class="total">
<!-- Calculate the total price of all chosen services. Format it as currency. -->
Totaal: <span>{{total1 | currency:"€ "}}</span>
Selected: <span>{{total2 | currency:"€ "}}</span>
</div>
有沒有辦法來顯示視圖withing角變量,使用somehing像{{my_var1}} {{my_var2}}
爲什麼你需要返回這些變量?將這些變量附加到$ scope,您可以在視圖中訪問它 – BKM
用$ scope.total1 = 0替換var total1 = 0,並執行$ scope.total1 + = s.price。與total2一樣。 –
謝謝你的回答。我明白了(有點)現在的工作http://jsfiddle.net/richard7/BLJ5M/ – Richard