我是loopback和angularjs的新手。我已经成功地使用mongodb建立了loopback数据源、模型和lb-服务。
下面是angular代码:
angular.module('myApp', ['lbServices'])
.controller('TestController', ['$scope','Clip', function TestController($scope, Clip) {
$scope.allClips = Clip.find();
console.log($scope.allClips);
}]); 它返回所有Clips并将其绑定到视图。现在,模型的结构有一个object类型的属性。$scope.allClips在控制台上打印$promise: d,$resolved: false。
lb-services中的find()工厂方法返回R的一个实例,这是一个模型名。
我尝试过使用Clip.find().then(),但是它引发了一个错误,说明.then()不是一个函数。

如何使用控制器内的所有属性访问响应的值?
发布于 2016-07-18 04:44:47
我已经用以下代码解决了这个问题:
angular.module('myApp', ['lbServices'])
.controller('TestController', ['$scope','Clip', function TestController($scope, Clip) {
$scope.allClips = Clip.find();
$scope.allClips.$promise.then(function(data){
console.log(JSON.stringify(data));
});
console.log($scope.allClips);
}]);https://stackoverflow.com/questions/38424821
复制相似问题