Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <div ng-app="example">
  2. <div example-hover>
  3. Hover me
  4. </div>
  5. </div>
  6.  
  7. var app = angular.module('example', []);
  8.  
  9. angular.module("example")
  10. .controller("exampleHoverController", function( $scope ) {
  11. $scope.showHoverList = false;
  12.  
  13. $scope.setHoverList = function(value) {
  14. console.log("Set hoverlist value: "+value);
  15. this.showHoverList=value;
  16. $scope.$apply();
  17. }
  18. });
  19.  
  20. angular.module("example")
  21. .directive("exampleHover", function( $compile ) {
  22. return {
  23. restrict: "A",
  24. template: '',
  25. controller: 'exampleHoverController',
  26. link: function( scope, element) {
  27. element.after('<example-dropdown></example-dropdown>');
  28. $compile(element.parent().find('example-dropdown'))(scope);
  29.  
  30. element.bind("mouseover", function() {
  31. scope.showHoverList = true;
  32. scope.setHoverList(true);
  33. });
  34. element.bind("mouseout", function() {
  35. scope.showHoverList = false;
  36. scope.setHoverList(false);
  37. });
  38. }
  39. }
  40. });
  41.  
  42. angular.module("example")
  43. .directive("exampleDropdown", function() {
  44. return {
  45. restrict: 'E',
  46. replace: true,
  47. template: '<div ng-show="showHoverList">I should be visible when hovered!</template>',
  48. controller: "exampleHoverController"
  49. };
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement