我似乎无法找到如何进行 ajax 调用并设置 '$scope.ticker' 模型并以角度响应。基本上,这是通过 ajax 调用来获取股票的最后价格(btc_usd、btc_eur 或 btc_rur)。
这样“$scope.last”始终是选中的任何一个单选按钮的最后价格。
<label><input type="radio" name="currency" value="btc_usd" ng-model="currency"> USD</label>
<label><input type="radio" name="currency" value="btc_eur" ng-model="currency"> EUR</label>
<label><input type="radio" name="currency" value="btc_rur" ng-model="currency"> RUR</label>
$scope.ticker = quote.ticker($scope.currency).then(function(data){
var last = data.ticker.last;
$log.log('last', last);
$scope.ticker = last;
$scope.last = last;
});
app.factory('quote', function($http, $log) {
return {
ticker: function(currency){
$log.log('ticker.currency', currency);
//return the promise directly.
return $http.get('/api/last/'+currency)
.then(function(result) {
//resolve the promise as the data
return result.data;
});
}
};
});