0
我已經嘗試了其他答案,但是都沒有工作。我有問題,我打電話給我的工廠,我得到undefined
回報。AngularJS工廠服務返回'undefined'
控制器(main.js):
app.controller('MainCtrl', ['$scope','beamAPI', function($scope, beamAPI){
$scope.debug = 'Debug True';
$scope.beamFollowers = 1;
console.log(beamAPI('amtraxtge'));
}]);
廠(beam.js):
app.factory('beamAPI', function($http) {
var APIuser = {};
APIuser = function(user) {
$http.get('https://beam.pro/api/v1/channels/' + user).
then(function(res){
console.log(res.data);
return res.data;
});
}
return APIuser;
});
控制檯:
undefined main.js:4
► Object beam.js:6
只返回$ http.get( 'https://beam.pro/api/v1/channels/'+用戶) –