我有这段代码(简化):
angular
.module('app.core')
.factory('experienceDataservice', ['$http', 'Facebook', dataservice]);
function dataservice($http, Facebook){
var service = {
getExperiences: getExperiences
};
debugger;
function getExperiences() {
debugger;
}
}
问题是,在debugger;
块的第一个dataservice
,我可以同时访问$http
和Facebook
,但在第二个debugger;
,在getExperiences
区块内,我只能访问$http
而非Facebook
。
我不明白为什么会这样。 我试图让代码尽可能简单。 如果需要更多细节,我会提供。
更大的片段:
(function(){
'use strict';
angular
.module('app.core')
.factory('experienceDataservice', ['$http', 'Facebook', dataservice]);
function dataservice($http, Facebook){
var service = {
getExperiences: getExperiences
};
debugger;
function getExperiences() {
debugger;
var access = '';
var access = Facebook.getAccessToken(); //Does not work
var auth = 'Bearer' + access;
var req =
{
method: 'GET',
url: '/api/reviews?location=London&term=',
headers:
{
'Accept' : "application/json, text/javascript, */*; q=0.01",
'Authorization': auth
}
}
$http(req) // Does 'work'
.success(function(data, status, headers, config){debugger;})
.error(function(data, status, headers, config){debugger;});
}
return service;
}
})();