angular.js - angularjs 路由使用resolve后報(bào)錯(cuò)
問題描述
路由的定義配置如下:
app.config([’$routeProvider’,function($routeProvider) //路由配置{ $routeProvider.when(’/tickets’, { templateUrl: ’tickets_list.jsp’, controller: ’ticketDetailController’, resolve:{data:function($http) {return $http.get(’ticket.action?method:projectTickets’);} } })}]);
然后在controller里賦值:
app.controller(’ticketDetailController’, function($scope,data) { $scope.data=data.data;}
我用chrome跟蹤過執(zhí)行,一直到賦值語句都沒有問題,但是controller創(chuàng)建完畢,就會報(bào)錯(cuò)
$scope.data之后和tickets_list.jsp頁面進(jìn)行數(shù)據(jù)綁定,以ng-repeat顯示。不知道這個(gè)錯(cuò)誤是為什么?謝謝回答~
問題解答
回答1:在stackoverflow上找到了解答。詳情地址
因?yàn)樵谂渲美镆呀?jīng)申明了controller,所以無需在jsp頁面中再使用ng-controller進(jìn)行申明。將指令刪除即可。希望對其他人有幫助。
回答2:resolve: { data: function ($http) {return $http.get(’ticket.action?method=projectTickets’).then(function (data) { return data;}, function () { return {};}); }}
http://stackoverflow.com/questions/17742787/angularjs-resolve-in-routeprovider-detecting-success-failure
相關(guān)文章:
1. 如何解決Centos下Docker服務(wù)啟動無響應(yīng),且輸入docker命令無響應(yīng)?2. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?3. vue ajax請求回來的數(shù)據(jù)沒有渲染到頁面4. mysql新建字段時(shí) timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 報(bào)錯(cuò)5. docker 17.03 怎么配置 registry mirror ?6. javascript - js 關(guān)于時(shí)間的轉(zhuǎn)換以及時(shí)間的加減。7. objective-c - IOS 分享到微信 提示 應(yīng)用消息數(shù)據(jù)錯(cuò)誤8. javascript - 音樂播放器-圖片旋轉(zhuǎn)9. angular.js - 用angularjs的service封裝百度地圖api出錯(cuò),請問原因?10. MySQL timestamp的默認(rèn)值怎么設(shè)置?
