Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <div ng-app='myApp' ng-controller='DirectiveTestController'>
  2. <button hello ng-click="testClick()">Test CLICK!</button>
  3. </div>
  4.  
  5. var myApp = angular.module('myApp', []);
  6. myApp.controller('DirectiveTestController', ['$scope',
  7.  
  8. function ($scope) {
  9. $scope.testClick = function () {
  10. window.alert("hey");
  11. console.log("hey");
  12. }
  13. }]);
  14. myApp.directive('hello', function () {
  15. return {
  16. scope: true,
  17. controller: ['$scope', '$element', '$compile', function ($scope, $element, $compile) {
  18. $element.removeAttr('hello');
  19. // $element.removeAttr('ng-click');
  20. $compile($element)($scope);
  21. }]
  22.  
  23. };
  24. });
  25.  
  26. app.directive("otcDynamic", function($compile){
  27. return {
  28. link: function(scope, element){
  29. var template = "<button ng-click='doSomething()'>{{label}}</button>";
  30. var content = $compile(template)(scope);
  31. element.append(content);
  32. }
  33. };
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement