我從「cameraData」服務調用camera.json文件並將cameradata服務注入到「CameraController」中。如果我點擊刷新按鈕後更改camera.json,我正在獲取舊數據。任何想法?更改json文件后角度工廠返回數據保持不變
.factory( 'cameraData',函數($ HTTP,$ Q,全局變量){ VAR推遲= $ q.defer();
var cameraData = {};
var contentType = "application/json; charset=utf-8";
cameraData.GetItemList = function(){
$('.loader').show();
var senddata ={};
senddata.installedcameraid = "9547857793457943";
$http({
//url: globalVariable.ServerAddress + "Admin_GetCameraPoints",
url: globalVariable.Camerafilepath,
dataType: 'json',
method: "POST",
data: JSON.stringify(senddata),
headers: {
"Content-Type": contentType,
"access_token": globalVariable.TOKEN
}
}).success(function(response){
//$scope.response = response;
deferred.resolve(response);
return deferred.promise;
}).error(function(error){
//$scope.error = error;
deferred.reject(error);
});
return deferred.promise;
}
return cameraData;
})
.controller(」 CameraController」,函數($範圍,$超時,cameraData){$ = scope.refreshCameraData函數(){
$scope.allCamera = [];
cameraData.GetItemList()
.then(function(data) {
$scope.allCamera = data.Camera;
}, function(err) {
// promise rejected, could log the error
console.log('error', err);
});
}
cameraData.GetItemList()
.then(function(data) {
$scope.allCamera = data.Camera;
}, function(err) {
// promise rejected, could log the error
console.log('error', err);
});
})
歡迎SO 。你能不能格式化代碼的第一行和最後一行,因爲這可能有助於人們快速理解代碼,從而更多地提供答案心情;-)? – Dilettant