我可以看到RESTful服務這條路線被訪問之前內loadProfile被稱爲....如何將解析的數據注入控制器?
$routeProvider.when('/editProfile', {
templateUrl: '/views/user/editprofile',
controller: 'UserCtrl',
access: access.user,
resolve: {
userProfile: function(UserSvc){
UserSvc.loadProfile(function(userProfile){ return userProfile });
}
}
});
那麼,如何再獲得這些數據注入到我的用戶控制器?
更新1:
馬特方式避讓我如何獲得在我的控制器注入所解析數據。但是,我立即收到一個錯誤「Unknown Provider:userProfileProvider」。基於其他一些類似的問題,我決定嘗試從相關視圖中刪除ng-controller =「UserCtrl」屬性。對於我的/ editProfile路由,未知提供者錯誤消失了,但隨後開始出現在此控制器的所有其他視圖/路由上。
更新2
我看了egghead.io一對夫婦的視頻,發現我能夠訪問在$路徑所承諾的數據。添加到我的控制器,瞧!
if($route.current.locals.userProfile){
$scope.userProfile = $route.current.locals.userProfile;
}
有趣。我剛剛嘗試過,現在我收到一個錯誤...「Unknown provider:userProfileProvider」 –
您的'routeProvider'配置與'UserCtrl'相同的模塊的一部分嗎? –
是... angular.module( '對myApp',[ 'ngCookies', 'ngRoute', 'ngSanitize']) 的.config([ '$ routeProvider', '$ locationProvider', '$ httpProvider', 函數($ routeProvider,$ locationProvider,$ httpProvider){... var UserCtrl = angular.module('myApp')。controller('UserCtrl', ['$ rootScope','$ scope','$ $ root',$ $'','$ timeout','$ window','$ upload','UserSvc','AuthSvc','MediaSvc', function($ rootScope ,$ scope,$ sanitize,$ translate,$ location,$ interval,$ timeout,$ window,$ upload,UserSvc,AuthSvc,MediaSvc){ –