Skip to content

Instantly share code, notes, and snippets.

@kingcody
Last active October 27, 2016 14:52
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kingcody/6badcfc04c6138fff15c to your computer and use it in GitHub Desktop.
Save kingcody/6badcfc04c6138fff15c to your computer and use it in GitHub Desktop.
Angular Fullstack - delete confirmation modal example
'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);
})();
'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);
}
});
});
});
<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>
@Djalmar
Copy link

Djalmar commented Apr 12, 2016

When updating UI-Bootstrap(by any reason) you should change the $modal by $uibModal in the Modal factory dependency injection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment