我的services.js
angular.module('myApp.services', []).
factory('MyApi', function (Restangular) {
var options = {quran: 210, content: 217, audio: 1};
var callBack = 1;
return {
option: {
quran: Restangular.all("options").one("quran").getList(),
content: Restangular.all("options").one("content").getList(),
audio: Restangular.all("options").one("audio").getList()
},
optionChange: function(key, value){
// console.log(value)
options[key] = value
console.log(options)
Restangular.all("bucket").one("page", 2).get(options).then(function(response){
callBack = response
console.log(callBack)
console.log(this)
});
// console.log(this.call)
},
setOptions: options,
call: callBack
};
})
我试图得到它,只要有一个更改,调用optionChange函数,更改Restangular函数的选项,然后它将被推送到我的控制器:
.controller('MyCtrl1', function ($scope, MyApi, Restangular, $routeParams) {
console.log(MyApi.call)
$scope.array = MyApi.call
})
答案 0 :(得分:0)
起初你的工厂从选项更改中返回,你必须从restangular返回承诺(回调是oldschool而不是有角度的做事方式。
optionChange: function(key, value){
options[key] = value
return Restangular.all("bucket").one("page", 2).get(options);
}
然后在控制器内部。
.controller('MyCtrl1', function ($scope, MyApi, Restangular, $routeParams) {
$scope.optionChange = function(key,value) {
MyApi.optionChange(key,value).then(function(response) {
$scope.array = response;
});
}
});