如何在沒有從API響應錯誤處理角JS
service.js
app.factory('dropdownService', function ($http,CD_CONTEXT_VOLTAGE_URL) {
return {
getDropDownData: function (callback) {
$http.get(CD_CONTEXT_VOLTAGE_URL).success(callback);
}
}
});
controller.js
app.controller('loadDropDownController', ['$scope','dropdownService',function($scope,dropdownService) {
getFormData();
function getFormData() {
dropdownService.getDropDownData(function (results) {
$scope.contextlist = results.context;
$scope.cdlst = results.coordinationType;
$scope.voltageList = results.constraintValue;
});
};
}]);
上面的代碼只處理成功的條件我處理。有人可以幫助我的代碼,以便我可以處理錯誤條件