Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 9b885ca

Browse files
committed
use ngRoute "resolve"
1 parent df889c9 commit 9b885ca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app/view1/view1.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ angular.module('myApp.view1', ['ngRoute'])
55
.config(['$routeProvider', function($routeProvider) {
66
$routeProvider.when('/view1', {
77
templateUrl: 'view1/view1.html',
8-
controller: 'View1Ctrl'
8+
controller: 'View1Ctrl',
9+
resolve: {
10+
user: function($http) {
11+
return $http.get('backend/user.php').then(function (user) {
12+
return user.data;
13+
});
14+
}
15+
}
916
});
1017
}])
1118

12-
.controller('View1Ctrl', function($http, $scope) {
13-
$http.get('backend/user.php').success(function (user) {
14-
$scope.user = user;
15-
});
19+
.controller('View1Ctrl', function($scope, user) {
20+
$scope.user = user;
1621
});

app/view1/view1_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('myApp.view1 module', function() {
99
it('should ....', inject(function($rootScope, $controller) {
1010
//spec body
1111
var scope = $rootScope.$new();
12-
var view1Ctrl = $controller('View1Ctrl', {$scope: scope});
12+
var user = {'id': "foo"};
13+
var view1Ctrl = $controller('View1Ctrl', {$scope: scope, user: user});
1314
expect(view1Ctrl).toBeDefined();
1415
}));
1516

0 commit comments

Comments
 (0)