Last active
October 27, 2016 14:52
-
-
Save kingcody/6badcfc04c6138fff15c to your computer and use it in GitHub Desktop.
Angular Fullstack - delete confirmation modal example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function() { | |
class AdminController { | |
constructor(User, Modal) { | |
// Use the User $resource to fetch all users | |
this.users = User.query(); | |
// Our callback function is called if/when the delete modal is confirmed | |
this.delete = Modal.confirm.delete(user => { | |
user.$remove(); | |
this.users.splice(this.users.indexOf(user), 1); | |
}); | |
} | |
} | |
angular.module('myApp.admin') | |
.controller('AdminController', AdminController); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('myApp') | |
.controller('AdminCtrl', function($scope, Auth, User, Modal) { | |
// Use the User $resource to fetch all users | |
$scope.users = User.query(); | |
// Our callback function is called if/when the delete modal is confirmed | |
$scope.delete = Modal.confirm.delete(function(user) { | |
User.remove({ id: user._id }); | |
angular.forEach($scope.users, function(u, i) { | |
if (u === user) { | |
$scope.users.splice(i, 1); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-include="'components/navbar/navbar.html'"></div> | |
<div class="container"> | |
<p>The delete user and user index api routes are restricted to users with the 'admin' role.</p> | |
<ul class="list-group"> | |
<li class="list-group-item" ng-repeat="user in users"> | |
<strong>{{user.name}}</strong><br> | |
<span class="text-muted">{{user.email}}</span> | |
<!-- Our delete modal takes a string as the first arg (used to display what we are deleting) | |
all other args are passed to the callback defined in admin.controller.js --> | |
<a ng-click="delete(user.name, user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a> | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When updating UI-Bootstrap(by any reason) you should change the $modal by $uibModal in the Modal factory dependency injection