我正在尝试将 $resource promise 绑定(bind)到 ng-repeat。但我无法让它发挥作用。
HTML
<ul ng-controller="ColorsCtrl">
<li ng-repeat="colors in getColors()"></li>
</ul>
脚本
app.module("myApp", ['ngResource'])
.factory('Color', function($resource) {
return $resource('/colors.json');
})
.controller('ColorsCtrl', function($scope, Color) {
$scope.getColors = function() {
return Color.query();
}
});
最佳答案
您不需要将您的 UI 绑定(bind)到一个 promise:您将 UI 绑定(bind)到一个数组,然后填充该数组:
$scope.colors = [];
var colors = Colors.query(function() {
// fill here $scope.colors
});
在处理异步请求时,通常您会在要显示数据的地方显示一个加载球。
关于angularjs - 将 ng-repeat 绑定(bind)到一个 promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27858592/