Skip to content

Commit 8a76da2

Browse files
committed
feat(client:admin): use controllerAs syntax for AdminController
1 parent 5babe1c commit 8a76da2

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

Diff for: app/templates/client/app/admin(auth)/admin(html).html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<div class="container">
44
<p>The delete user and user index api routes are restricted to users with the 'admin' role.</p>
55
<ul class="list-group">
6-
<li class="list-group-item" ng-repeat="user in users">
6+
<li class="list-group-item" ng-repeat="user in admin.users">
77
<strong>{{user.name}}</strong><br>
88
<span class="text-muted">{{user.email}}</span>
9-
<a ng-click="delete(user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a>
9+
<a ng-click="admin.delete(user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a>
1010
</li>
1111
</ul>
1212
</div>

Diff for: app/templates/client/app/admin(auth)/admin(jade).jade

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ navbar
33
p
44
| The delete user and user index api routes are restricted to users with the 'admin' role.
55
ul.list-group
6-
li.list-group-item(ng-repeat='user in users')
6+
li.list-group-item(ng-repeat='user in admin.users')
77
strong {{user.name}}
88
br
99
span.text-muted {{user.email}}
10-
a.trash(ng-click='delete(user)')
10+
a.trash(ng-click='admin.delete(user)')
1111
span.glyphicon.glyphicon-trash.pull-right
+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
'use strict';
22

3-
angular.module('<%= scriptAppName %>.admin')
4-
.controller('AdminCtrl', function($scope, $http, Auth, User) {
3+
(function() {
4+
5+
function AdminController(User) {
6+
// Use the User $resource to fetch all users
7+
var users = this.users = User.query();
58

6-
// Use the User $resource to fetch all users
7-
$scope.users = User.query();
9+
this.delete = function(user) {
10+
user.$remove();
11+
users.splice(users.indexOf(user), 1);
12+
};
13+
}
14+
15+
angular.module('<%= scriptAppName %>.admin')
16+
.controller('AdminController', AdminController);
817

9-
$scope.delete = function(user) {
10-
User.remove({ id: user._id });
11-
$scope.users.splice(this.$index, 1);
12-
};
13-
});
18+
})();

Diff for: app/templates/client/app/admin(auth)/admin.router.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ angular.module('<%= scriptAppName %>.admin')
55
$routeProvider
66
.when('/admin', {
77
templateUrl: 'app/admin/admin.html',
8-
controller: 'AdminCtrl',
8+
controller: 'AdminController',
9+
controllerAs: 'admin',
910
authenticate: 'admin'
1011
});
1112
});<% } if (filters.uirouter) { %>.config(function($stateProvider) {
1213
$stateProvider
1314
.state('admin', {
1415
url: '/admin',
1516
templateUrl: 'app/admin/admin.html',
16-
controller: 'AdminCtrl',
17+
controller: 'AdminController',
18+
controllerAs: 'admin',
1719
authenticate: 'admin'
1820
});
1921
});<% } %>

0 commit comments

Comments
 (0)