Edit on
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Directivas automáticas</title>
</head>
<body ng-app="app">
  <div ng-controller="controlador">
  <button crear-boton>Crear boton</button>
  <div id="espacioParaelBoton"></div>
    </div>
</body>
</html>
angular.module('app',[])

var app = angular.module('app')

app.controller('controlador',function($scope){
   $scope.console = function(){
     alert('auto click')
   }
})

app.directive('doAutoClick',['$timeout',
  function($timeout) {
    return {
      restrict: 'A',
      priority: -1,
      link: function($scope, iElm, iAttrs, controller) {
        
        $timeout(function(){
         iElm.triggerHandler('click'); 
},500)  
          //podemos modificar los eventos
          //click, hover, focus, etc

      }
    };
  }
]);

app.directive("crearBoton", function($compile){
	return function(scope, element, attrs){
		element.bind("click", function(){
				angular.element(document.getElementById('espacioParaelBoton')).append($compile("<div><button ng-click='console()'  do-auto-click>boton generado automaticamente</button></div>")(scope));
//podemos añadirle al botón directivas, estilos y funciones de ng, gracias al método $compile de angular
		});
	};
});
Rerun