0
我有一個簡單的工廠這樣工廠更新時爲什麼沒有計算的數量更新?
angular.module('posBitcoinApp')
.factory('invoiceData', function ($http, $interval) {
var blockchainInfoExchangeRates = {};
var getLatestExchangeRates = function() {
$http.get('https://api.bitcoinaverage.com/ticker/global/IDR/')
.success(function(response) {
blockchainInfoExchangeRates.IDR = response.last;
});
};
$interval(getLatestExchangeRates, 60000);
getLatestExchangeRates();
return {
exchangeRates: blockchainInfoExchangeRates
};
});
然後在我的控制器我有一個...
angular.module('posBitcoinApp')
.controller('InvoiceCtrl', function ($scope, $http, $interval, $location, invoiceData) {
$scope.invoiceData = invoiceData;
$scope.invoiceData.btcAmount = parseFloat($scope.invoiceData.idrAmount/$scope.invoiceData.exchangeRates.IDR).toFixed(8);
所以每一分鐘的匯率得到更新。但是,計算出的BTC值($ scope.invoiceData.btcAmount)不會自動更新。我錯過了什麼?有什麼東西需要觀看? $ scope.apply()在哪裏?
謝謝。
您的控制器應該監視'invoiceData.exchangeRates'。 – leesei 2014-10-20 05:39:45