Created
November 24, 2014 13:52
-
-
Save EmmanuelDemey/83721133ea613e8f590e to your computer and use it in GitHub Desktop.
Slide 129 - Creating new directives
This file contains hidden or 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 data-ng-app="app"> | |
| <div class='html-content'><div data-ng-init="login='Bob'"> | |
| <button class="btn" data-ng-click="login=''" data-confirm-click data-message="Are you sure ? ">Reset login</button> | |
| Login: {{login}} | |
| </div></div></div> |
This file contains hidden or 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
| angular.module('app',['ui.bootstrap']) | |
| .directive('confirmClick', function($modal) { | |
| return { | |
| restrict: 'A', | |
| priority: '10', | |
| terminal: true, | |
| link: function(scope, elm, attrs) { | |
| var button = elm[0]; | |
| angular.element(button).on("click", function($event){ | |
| $event.preventDefault(); | |
| $event.stopPropagation(); | |
| $modal.open({ | |
| template : "<div>"+ | |
| "<div class='modal-body'>" + attrs.message + "</div>"+ | |
| "<div class='modal-footer'>"+ | |
| "<button class='btn btn-primary' data-ng-click='confirm()'>OK</button>"+ | |
| "<button class='btn btn-warning' data-ng-click='cancel()'>KO</button>"+ | |
| "</div>"+ | |
| "</div>", | |
| controller : function($scope, $modalInstance){ | |
| $scope.confirm = function(){ | |
| scope.$eval(attrs.ngClick); | |
| $modalInstance.dismiss('cancel'); | |
| } | |
| $scope.cancel = function(){ | |
| $modalInstance.dismiss('cancel'); | |
| } | |
| } | |
| }); | |
| }); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment