<html ng-app="com.ngbook.demo">
<head>
<meta name="description" content="angular template">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8">
<title>JS Bin</title>
<script src="http://greengerong.github.io/self/cdn/angular.js"></script>
</head>
<body >
<div class="moon">
</div>
<div ng-controller="DemoController" class="container">
<pre>{{fromZone}}</pre>
</div>
</body>
</html>
angular.module("com.ngbook.demo", [])
.controller("DemoController", ['$scope', function($scope){
zone.fork({
afterTask: function(){
var phase = $scope.$root.$$phase;
if(['$apply', '$digest'].indexOf(phase) === -1) {
$scope.$apply();
}
}
}).run(function(){
setTimeout(function(){
$scope.fromZone = "I am from zone with setTimeout!";
}, 2000);
});
}]);
!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,exports,t){(function(e){var n=t(1),r=t(5);e.Zone?console.warn("Zone already exported on window the object!"):(e.Zone=n.Zone,e.zone=new e.Zone,r.apply()),exports.Zone=e.Zone}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(e,t){i.hasOwnProperty(e)||(i[e]=!0,console.warn("DEPRECATION WARNING: '"+e+"' is no longer supported and will be removed in next major release. "+t))}var r=t(2),o=t(3),i={},a=function(){function t(e,n){this.parent=null,this.onError=null;var r=arguments.length?Object.create(e):this;return r.parent=e||null,Object.keys(n||{}).forEach(function(t){var o=t.substr(1);"$"===t[0]?r[o]=n[t](e[o]||function(){}):"+"===t[0]?e[o]?r[o]=function(){var r=e[o].apply(this,arguments);return n[t].apply(this,arguments),r}:r[o]=n[t]:"-"===t[0]?e[o]?r[o]=function(){return n[t].apply(this,arguments),e[o].apply(this,arguments)}:r[o]=n[t]:r[t]="object"==typeof n[t]?JSON.parse(JSON.stringify(n[t])):n[t]}),r.$id=t.nextId++,r}return t.prototype.fork=function(e){return this.onZoneCreated(),new t(this,e)},t.prototype.bind=function(e,t){if("function"!=typeof e)throw new Error("Expecting function got: "+e);t||this.enqueueTask(e);var n=this.isRootZone()?this:this.fork();return function(){return n.run(e,this,arguments)}},t.prototype.bindOnce=function(e){n("bindOnce","There is no replacement.");var t=this;return this.bind(function(){var n=e.apply(this,arguments);return t.dequeueTask(e),n})},t.prototype.isRootZone=function(){return null===this.parent},t.prototype.run=function(t,n,r){r=r||[];var o=e.zone;e.zone=this;try{return this.beforeTask(),t.apply(n,r)}catch(i){if(!this.onError)throw i;this.onError(i)}finally{this.afterTask(),e.zone=o}},t.prototype.beforeTask=function(){},t.prototype.onZoneCreated=function(){},t.prototype.afterTask=function(){},t.prototype.enqueueTask=function(e){n("enqueueTask","Use addTask/addRepeatingTask/addMicroTask")},t.prototype.dequeueTask=function(e){n("dequeueTask","Use removeTask/removeRepeatingTask/removeMicroTask")},t.prototype.addTask=function(e){this.enqueueTask(e)},t.prototype.removeTask=function(e){this.dequeueTask(e)},t.prototype.addRepeatingTask=function(e){this.enqueueTask(e)},t.prototype.removeRepeatingTask=function(e){this.dequeueTask(e)},t.prototype.addMicrotask=function(e){this.enqueueTask(e)},t.prototype.removeMicrotask=function(e){this.dequeueTask(e)},t.prototype.addEventListener=function(){return this[r.common.addEventListener].apply(this,arguments)},t.prototype.removeEventListener=function(){return this[r.common.removeEventListener].apply(this,arguments)},t.nextId=1,t.bindPromiseFn=o.bindPromiseFn,t}();exports.Zone=a}).call(exports,function(){return this}())},function(e,exports){function t(e){return"_zone$"+e}exports.create=t,exports.common={addEventListener:t("addEventListener"),removeEventListener:t("removeEventListener")}},function(e,exports,t){(function(n){function r(e,t){var r=n,o=e.every(function(e){return r=r[e]});o&&t.forEach(function(e){var t=r[e];t&&(r[e]=exports.bindPromiseFn(t))})}function o(e){var t=e.then;e.then=function(){var n=a.bindArguments(arguments),r=t.apply(e,n);return o(r)};var n=e["catch"];return e["catch"]=function(){var t=a.bindArguments(arguments),r=n.apply(e,t);return o(r)},e}function i(){if(n.Promise){a.patchPrototype(Promise.prototype,["then","catch"]);var e=[[[],["fetch"]],[["Response","prototype"],["arrayBuffer","blob","json","text"]]];e.forEach(function(e){r(e[0],e[1])})}}var a=t(4);n.Promise?exports.bindPromiseFn=function(e){return function(){var t=e.apply(this,arguments);return t instanceof Promise?t:new Promise(function(e,n){t.then(e,n)})}}:exports.bindPromiseFn=function(e){return function(){return o(e.apply(this,arguments))}},exports.apply=i,e.exports={apply:i,bindPromiseFn:exports.bindPromiseFn}}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(t){for(var n=t.length-1;n>=0;n--)"function"==typeof t[n]&&(t[n]=e.zone.bind(t[n]));return t}function r(e,t){t.forEach(function(t){var r=e[t];r&&(e[t]=function(){return r.apply(this,n(arguments))})})}function o(){return"undefined"==typeof document}function i(e,t){var n=Object.getOwnPropertyDescriptor(e,t)||{enumerable:!0,configurable:!0};delete n.writable,delete n.value;var r=t.substr(2),o="_"+t;n.set=function(e){this[o]&&this.removeEventListener(r,this[o]),"function"==typeof e?(this[o]=e,this.addEventListener(r,e,!1)):this[o]=null},n.get=function(){return this[o]},Object.defineProperty(e,t,n)}function a(e,t){(t||function(){var t=[];for(var n in e)t.push(n);return t}().filter(function(e){return"on"===e.substr(0,2)})).forEach(function(t){i(e,t)})}function u(t){t[s.common.addEventListener]=t.addEventListener,t.addEventListener=function(t,n,r){if(n&&"[object FunctionWrapper]"!==n.toString()){var o,i=t+(r?"$capturing":"$bubbling");o=n.handleEvent?function(e){return function(){e.handleEvent.apply(e,arguments)}}(n):n,n[p]=o,n[f]=n[f]||{},n[f][i]=n[f][i]||e.zone.bind(o),arguments[1]=n[f][i]}var a=this||e;return e.zone.addEventListener.apply(a,arguments)},t[s.common.removeEventListener]=t.removeEventListener,t.removeEventListener=function(t,n,r){var o=t+(r?"$capturing":"$bubbling");if(n&&n[f]&&n[f][o]){var i=n[f];arguments[1]=i[o],delete i[o],e.zone.dequeueTask(n[p])}var a=this||e,u=e.zone.removeEventListener.apply(a,arguments);return u}}function c(t){var r=e[t];if(r){e[t]=function(){var e=n(arguments);switch(e.length){case 0:this[l]=new r;break;case 1:this[l]=new r(e[0]);break;case 2:this[l]=new r(e[0],e[1]);break;case 3:this[l]=new r(e[0],e[1],e[2]);break;case 4:this[l]=new r(e[0],e[1],e[2],e[3]);break;default:throw new Error("what are you even doing?")}};var o,i=new r;for(o in i)!function(n){"function"==typeof i[n]?e[t].prototype[n]=function(){return this[l][n].apply(this[l],arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(t){"function"==typeof t?this[l][n]=e.zone.bind(t):this[l][n]=t},get:function(){return this[l][n]}})}(o);for(o in r)"prototype"!==o&&r.hasOwnProperty(o)&&(e[t][o]=r[o])}}var s=t(2);exports.bindArguments=n,exports.patchPrototype=r,exports.isWebWorker=o,exports.patchProperty=i,exports.patchProperties=a;var p=s.create("originalFn"),f=s.create("boundFns");exports.patchEventTargetMethods=u;var l=s.create("originalInstance");exports.patchClass=c}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(){r.patchSetClearFunction(e,e.Zone,[["setTimeout","clearTimeout",!1,!1],["setInterval","clearInterval",!0,!1],["setImmediate","clearImmediate",!1,!1],["requestAnimationFrame","cancelAnimationFrame",!1,!0],["mozRequestAnimationFrame","mozCancelAnimationFrame",!1,!0],["webkitRequestAnimationFrame","webkitCancelAnimationFrame",!1,!0]]),r.patchFunction(e,["alert","prompt"]),c.apply(),s.apply(),o.apply(),i.patchClass("MutationObserver"),i.patchClass("WebKitMutationObserver"),a.apply(),u.apply(),p.apply(),f.apply()}var r=t(6),o=t(3),i=t(8),a=t(9),u=t(10),c=t(11),s=t(12),p=t(14),f=t(15);exports.apply=n}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(t,n,r){function i(r,i,a,u){var c=t[r],s=t[i],p={};if(c){var f=o.createEvent("Zone#"+r+"(uint32 zone, uint32 id, uint32 delay)"),l=o.createEvent("Zone#"+i+"(uint32 zone, uint32 id)"),d=o.createScope("Zone#cb:"+r+"(uint32 zone, uint32 id, uint32 delay)");t[r]=function(){return e.zone[r].apply(e.zone,arguments)},t[i]=function(){return e.zone[i].apply(e.zone,arguments)},n.prototype[r]=function(e,n){var r=e;"function"!=typeof r&&c.apply(t,arguments);var i=this,s=null;return arguments[0]=function(){var e=i.isRootZone()||u?i:i.fork(),t=this,c=arguments;return o.leaveScope(d(e.$id,s,n),e.run(function(){return a||(delete p[s],e.removeTask(r)),r.apply(t,c)}))},a?i.addRepeatingTask(r):i.addTask(r),s=c.apply(t,arguments),p[s]=r,f(i.$id,s,n),s},n.prototype[r+"Unpatched"]=function(){return c.apply(t,arguments)},n.prototype[i]=function(e){if(l(this.$id,e),p.hasOwnProperty(e)){var n=p[e];delete p[e],a?this.removeRepeatingTask(n):this.removeTask(n)}return s.apply(t,arguments)},n.prototype[i+"Unpatched"]=function(){return s.apply(t,arguments)}}}r.forEach(function(e){i.apply(null,e)})}function r(t,n){n.forEach(function(n){var r=t[n];e.zone[n]=function(){return r.apply(t,arguments)},t[n]=function(){return e.zone[n].apply(this,arguments)}})}var o=t(7);exports.patchSetClearFunction=n,exports.patchFunction=r}).call(exports,function(){return this}())},function(e,exports){(function(e){function t(){}var n=null,r=null,o=function(){var t=e.wtf;return t&&(n=t.trace)?(r=n.events,!0):!1}();exports.enabled=o,exports.createScope=o?function(e,t){return r.createScope(e,t)}:function(e,n){return t},exports.createEvent=o?function(e,t){return r.createInstance(e,t)}:function(e,n){return t},exports.leaveScope=o?function(e,t){return n.leaveScope(e,t),t}:function(e,t){return t},exports.beginTimeRange=o?function(e,t){return n.beginTimeRange(e,t)}:function(e,t){return null},exports.endTimeRange=o?function(e){n.endTimeRange(e)}:function(e){}}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(t){var n=e[t];if(n){e[t]=function(t){this[o]=new n(e.zone.bind(t,!0)),this[i]=e.zone};var r=new n(function(){});e[t].prototype.disconnect=function(){var e=this[o].disconnect.apply(this[o],arguments);return this[a]&&(this[i].dequeueTask(),this[a]=!1),e},e[t].prototype.observe=function(){return this[a]||(this[i].enqueueTask(),this[a]=!0),this[o].observe.apply(this[o],arguments)};var u;for(u in r)!function(n){"undefined"==typeof e[t].prototype&&("function"==typeof r[n]?e[t].prototype[n]=function(){return this[o][n].apply(this[o],arguments)}:Object.defineProperty(e[t].prototype,n,{set:function(t){"function"==typeof t?this[o][n]=e.zone.bind(t):this[o][n]=t},get:function(){return this[o][n]}}))}(u)}}var r=t(2),o=r.create("originalInstance"),i=r.create("creationZone"),a=r.create("isActive");exports.patchClass=n}).call(exports,function(){return this}())},function(e,exports,t){function n(){Object.defineProperty=function(e,t,n){if(o(e,t))throw new TypeError("Cannot assign to read only property '"+t+"' of "+e);return"prototype"!==t&&(n=i(e,t,n)),u(e,t,n)},Object.defineProperties=function(e,t){return Object.keys(t).forEach(function(n){Object.defineProperty(e,n,t[n])}),e},Object.create=function(e,t){return"object"==typeof t&&Object.keys(t).forEach(function(n){t[n]=i(e,n,t[n])}),s(e,t)},Object.getOwnPropertyDescriptor=function(e,t){var n=c(e,t);return o(e,t)&&(n.configurable=!1),n}}function r(e,t,n){return n=i(e,t,n),u(e,t,n)}function o(e,t){return e&&e[p]&&e[p][t]}function i(e,t,n){return n.configurable=!0,n.configurable||(e[p]||u(e,p,{writable:!0,value:{}}),e[p][t]=!0),n}var a=t(2),u=Object.defineProperty,c=Object.getOwnPropertyDescriptor,s=Object.create,p=a.create("unconfigurables");exports.apply=n,exports._redefineProperty=r},function(e,exports,t){(function(e){function n(){if(!o.isWebWorker()&&"registerElement"in e.document){var t=document.registerElement,n=["createdCallback","attachedCallback","detachedCallback","attributeChangedCallback"];document.registerElement=function(o,i){return i&&i.prototype&&n.forEach(function(t){if(i.prototype.hasOwnProperty(t)){var n=Object.getOwnPropertyDescriptor(i.prototype,t);n&&n.value?(n.value=e.zone.bind(n.value),r._redefineProperty(i.prototype,t,n)):i.prototype[t]=e.zone.bind(i.prototype[t])}else i.prototype[t]&&(i.prototype[t]=e.zone.bind(i.prototype[t]))}),t.apply(document,[o,i])}}}var r=t(9),o=t(4);exports.apply=n}).call(exports,function(){return this}())},function(e,exports,t){(function(e){"use strict";function n(){if(e.EventTarget)r.patchEventTargetMethods(e.EventTarget.prototype);else{var t=["ApplicationCache","EventSource","FileReader","InputMethodContext","MediaController","MessagePort","Node","Performance","SVGElementInstance","SharedWorker","TextTrack","TextTrackCue","TextTrackList","WebKitNamedFlow","Worker","WorkerGlobalScope","XMLHttpRequest","XMLHttpRequestEventTarget","XMLHttpRequestUpload"];t.forEach(function(t){var n=e[t]&&e[t].prototype;n&&n.addEventListener&&r.patchEventTargetMethods(n)}),"undefined"!=typeof window&&r.patchEventTargetMethods(window)}}var r=t(4);exports.apply=n}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(){if(!a.isWebWorker()){var e="undefined"!=typeof WebSocket;if(r()){var t=c.map(function(e){return"on"+e});a.patchProperties(HTMLElement.prototype,t),a.patchProperties(XMLHttpRequest.prototype),e&&a.patchProperties(WebSocket.prototype)}else o(),a.patchClass("XMLHttpRequest"),e&&i.apply()}}function r(){if(!Object.getOwnPropertyDescriptor(HTMLElement.prototype,"onclick")&&"undefined"!=typeof Element){var e=Object.getOwnPropertyDescriptor(Element.prototype,"onclick");if(e&&!e.configurable)return!1}Object.defineProperty(HTMLElement.prototype,"onclick",{get:function(){return!0}});var t=document.createElement("div"),n=!!t.onclick;return Object.defineProperty(HTMLElement.prototype,"onclick",{}),n}function o(){c.forEach(function(t){var n="on"+t;document.addEventListener(t,function(t){for(var r,o=t.target;o;)o[n]&&!o[n][s]&&(r=e.zone.bind(o[n]),r[s]=o[n],o[n]=r),o=o.parentElement},!0)})}var i=t(13),a=t(4),u=t(2),c="copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror".split(" ");exports.apply=n;var s=u.create("unbound")}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(){var t=e.WebSocket;e.EventTarget||r.patchEventTargetMethods(t.prototype),e.WebSocket=function(e,n){var o,i=arguments.length>1?new t(e,n):new t(e),a=Object.getOwnPropertyDescriptor(i,"onmessage");return a&&a.configurable===!1?(o=Object.create(i),["addEventListener","removeEventListener","send","close"].forEach(function(e){o[e]=function(){return i[e].apply(i,arguments)}})):o=i,r.patchProperties(o,["onclose","onerror","onmessage","onopen"]),o}}var r=t(4);exports.apply=n}).call(exports,function(){return this}())},function(e,exports,t){(function(e){function n(){e.navigator&&e.navigator.geolocation&&r.patchPrototype(e.navigator.geolocation,["getCurrentPosition","watchPosition"])}var r=t(4);exports.apply=n}).call(exports,function(){return this}())},function(e,exports,t){function n(){r.patchClass("FileReader")}var r=t(4);exports.apply=n}]);
var log = function(phase){
return function(){
console.log("I am in zone.js " + phase + "!");
};
};
zone.fork({
onZoneCreated: log("onZoneCreated"),
beforeTask: log("beforeTask"),
afterTask: log("afterTask"),
}).run(function(){
var methodLog = function(func){
return function(){
console.log("I am from " + func + " function!");
};
},
foo = methodLog("foo"),
bar = methodLog("bar"),
baz = function(){
setTimeout(methodLog('baz in setTimeout'));
};
foo();
baz();
bar();
});
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. |