我寫了ui.router從JSON文件中獲取數據。 我沒有收到錯誤消息,但代碼沒有輸入「解決」部分。 所以我無法從JSON文件中獲取數據。AngularJS ui路由器(解析部分)
任何人都可以告訴我什麼可能會發生這種情況和解決辦法嗎?
這是我的代碼。 (功能(){
/*
* Declaration of main angular module for this application.
*
* It is named turtleFacts and has no dependencies (hence the
* empty array as the second argument)
*/
angular
.module('GrammarQuiz', ['ui.router'])
.config(
function($stateProvider, $urlRouterProvider) {
console.log('HOLY SMOKES, I CAN BREATHE IN HERE')
$urlRouterProvider.otherwise('/browse/1');
$stateProvider
.state('home',{
url: "/#/testtest",
resolve: {
questions: function($http){
console.log('!!#@!#@!');
return $http({
method: 'GET',
url: 'api/data1.json'
}).error(function(data,status,headers,config){
console.log('thisi now working!!!!');
})
}
}
})
})
})();
嘗試向$ http promise添加成功方法,該方法返回re sponse。 – csschapker
另外,對$ http promises使用.success和.error已棄用。我建議使用.then – csschapker