<html ng-app="app">
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<body ng-controller="Ctrl">
{{1+3}}
<div>
<div directive-name directive-name2>
<div directive-name3>
Hello World...
</div>
</div>
<div directive-name directive-name2>
<div directive-name3>
Hello World...
</div>
</div>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
<script src="directives.js"></script>
</body>
</body>
</html>
var app = angular.module("app",[]);
app.config(function ($provide) {
$provide.decorator('$compile', function ($delegate) {
var result = function ($compileNodes, transcludeFn, maxPriority, ignoreDirective,
previousCompileContext) {
var start = new Date();
console.log("$compile start");
var link = $delegate($compileNodes, transcludeFn, maxPriority, ignoreDirective,
previousCompileContext);
console.log("$compile Decorator took: " + (new Date() - start) + "ms");
return link;
};
return result;
});
});
app.directive('directiveName', function ($parse) {
console.log('Directive factory 1');
var directiveDefinitionObject = {
priority: 0,
template: function () {
console.log('Template 1');
return "<div>I am a Template 1: <strong>{{name}}</strong><br/><hr/><div ng-transclude></div></div>";
},
replace: true,
transclude: true,
restrict: 'A', //E lement, A ttribute , C lass, M (Commant)
scope: true,
controller: function ($scope, $element, $attrs, $transclude) {
console.log('controller 1');
},
compile: function compile(tElement, tAttrs, transclude) {
console.log('compile 1');
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
console.log('preLink 1');
},
post: function postLink(scope, iElement, iAttrs, controller) {
console.log('postLink 1');
}
};
},
link: function postLink(scope, iElement, iAttrs) {
console.log('link 1');
}
};
return directiveDefinitionObject;
});
app.directive('directiveName2', function ($parse) {
console.log('Directive factory 2');
var directiveDefinitionObject = {
priority: 0,
replace: true,
transclude: false,
restrict: 'A', //E lement, A ttribute , C lass, M (Commant)
scope: false,
controller: function ($scope, $element, $attrs, $transclude) {
console.log('controller 2');
},
compile: function compile(tElement, tAttrs, transclude) {
console.log('compile 2');
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
console.log('preLink 2');
},
post: function postLink(scope, iElement, iAttrs, controller) {
console.log('postLink 2');
}
};
},
link: function postLink(scope, iElement, iAttrs) {
console.log('link 2');
}
};
return directiveDefinitionObject;
});
app.directive('directiveName3', function ($parse) {
console.log('Directive factory 3');
var directiveDefinitionObject = {
priority: 0,
template: function () {
console.log('Template 3');
return "<div>I am a Template {{1+2}}: <br/><hr/><div directive-name4 ></div><hr/><div ng-transclude></div></div>";
},
replace: true,
transclude: true,
restrict: 'A', //E lement, A ttribute , C lass, M (Commant)
scope: false,
controller: function ($scope, $element, $attrs, $transclude) {
console.log('controller 3');
},
compile: function compile(tElement, tAttrs, transclude) {
console.log('compile 3');
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
console.log('preLink 3');
},
post: function postLink(scope, iElement, iAttrs, controller) {
console.log('postLink 3');
}
};
},
link: function postLink(scope, iElement, iAttrs) {
console.log('link 3');
}
};
return directiveDefinitionObject;
});
app.directive('directiveName4', function ($parse) {
console.log('Directive factory 4');
var directiveDefinitionObject = {
priority: 0,
template: function () {
console.log('Template 4');
return "<div>I am a Template {{2+2}}</div>";
},
replace: true,
transclude: false,
restrict: 'A', //E lement, A ttribute , C lass, M (Commant)
scope: true,
controller: function ($scope, $element, $attrs, $transclude) {
console.log('controller 4');
},
compile: function compile(tElement, tAttrs, transclude) {
console.log('compile 4');
return {
pre: function preLink(scope, iElement, iAttrs, controller) {
console.log('preLink 4');
},
post: function postLink(scope, iElement, iAttrs, controller) {
console.log('postLink 4');
}
};
},
link: function postLink(scope, iElement, iAttrs) {
console.log('link 4');
}
};
return directiveDefinitionObject;
});
app.directive('e4dShow', function ($compile) {
console.log('Directive e4dShow');
return {
//template: function () {
// console.log('Template e4dShow');
// return "<div ng-hide='false' ng-controller='Ctrl'>ng-show : {{name}} , {{2+3}}</div>";
//},
priority: 1000,
compile: function (elm, attr, trsc ) {
console.log('compile e4dShow : ' + elm.valueOf());
elm[0].innerHTML = "<div ng-hide='false' ng-controller='Ctrl'>ng-show : {{name}} , {{2+3}}</div>";
return function (scope, elm, attr, ctrls) {
console.log("link e4dShow");
};
}
};
});
function Ctrl($scope) {
$scope.name = 'Angular';
$scope.html = 'Hello {{name}}';
}
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |