Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app">
  <div derp></div>
  
</body>
</html>
 
var app = angular.module('app', []);
app.directive('derp', function () {
  return {
    restrict: 'A',
    controller: function ($scope) {
      $scope.logIt = function () {
        console.log('original ctrl');
      };
      
      $scope.logIt();
    },
    link: function (scope, el, attrs) {
      el.html('hai');
    }
  };
});
app.config(function ($provide) {
  $provide.decorator('derpDirective', function ($delegate, $controller) {
    var dir = $delegate[0];
    var origCtrl = dir.controller;
    
    dir.controller = function ($scope, $element, $attrs, $timeout) {
      var ctrl = $controller(origCtrl, { $scope: $scope });
      
      $scope.logLater = function () {
        $timeout(function () {
          console.log('log later');
          $element.html('bai');
        }, 1500);
      };
      
      $scope.logLater();
      
      return ctrl;
    };
    
    
    return $delegate;
  });
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers