1 /******/ (function(modules) { // webpackBootstrap
2 /******/ // The module cache
3 /******/ var installedModules = {};
5 /******/ // The require function
6 /******/ function __webpack_require__(moduleId) {
8 /******/ // Check if module is in cache
9 /******/ if(installedModules[moduleId])
10 /******/ return installedModules[moduleId].exports;
12 /******/ // Create a new module (and put it into the cache)
13 /******/ var module = installedModules[moduleId] = {
15 /******/ id: moduleId,
16 /******/ loaded: false
19 /******/ // Execute the module function
20 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22 /******/ // Flag the module as loaded
23 /******/ module.loaded = true;
25 /******/ // Return the exports of the module
26 /******/ return module.exports;
30 /******/ // expose the modules object (__webpack_modules__)
31 /******/ __webpack_require__.m = modules;
33 /******/ // expose the module cache
34 /******/ __webpack_require__.c = installedModules;
36 /******/ // __webpack_public_path__
37 /******/ __webpack_require__.p = "";
39 /******/ // Load entry module and return exports
40 /******/ return __webpack_require__(0);
42 /************************************************************************/
45 /***/ function(module, exports, __webpack_require__) {
47 __webpack_require__(1);
48 __webpack_require__(3);
49 __webpack_require__(4);
50 __webpack_require__(6);
51 __webpack_require__(8);
52 __webpack_require__(9);
53 __webpack_require__(10);
54 __webpack_require__(11);
55 __webpack_require__(12);
56 __webpack_require__(13);
57 __webpack_require__(14);
58 __webpack_require__(15);
59 __webpack_require__(16);
60 __webpack_require__(17);
61 __webpack_require__(18);
62 __webpack_require__(19);
63 __webpack_require__(20);
68 /***/ function(module, exports, __webpack_require__) {
70 __webpack_require__(2);
71 module.exports = angular;
76 /***/ function(module, exports) {
79 * @license AngularJS v1.4.8
80 * (c) 2010-2015 Google, Inc. http://angularjs.org
83 (function(window, document, undefined) {'use strict';
88 * This object provides a utility for producing rich Error messages within
89 * Angular. It can be called as follows:
91 * var exampleMinErr = minErr('example');
92 * throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
94 * The above creates an instance of minErr in the example namespace. The
95 * resulting error will have a namespaced error code of example.one. The
96 * resulting error will replace {0} with the value of foo, and {1} with the
97 * value of bar. The object is not restricted in the number of arguments it can
100 * If fewer arguments are specified than necessary for interpolation, the extra
101 * interpolation markers will be preserved in the final string.
103 * Since data will be parsed statically during a build step, some restrictions
104 * are applied with respect to how minErr instances are created and called.
105 * Instances should have names of the form namespaceMinErr for a minErr created
106 * using minErr('namespace') . Error codes, namespaces and template strings
107 * should all be static strings, not variables or general expressions.
109 * @param {string} module The namespace to use for the new minErr instance.
110 * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
111 * error from returned function, for cases when a particular type of error is useful.
112 * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
115 function minErr(module, ErrorConstructor) {
116 ErrorConstructor = ErrorConstructor || Error;
118 var SKIP_INDEXES = 2;
120 var templateArgs = arguments,
121 code = templateArgs[0],
122 message = '[' + (module ? module + ':' : '') + code + '] ',
123 template = templateArgs[1],
126 message += template.replace(/\{\d+\}/g, function(match) {
127 var index = +match.slice(1, -1),
128 shiftedIndex = index + SKIP_INDEXES;
130 if (shiftedIndex < templateArgs.length) {
131 return toDebugString(templateArgs[shiftedIndex]);
137 message += '\nhttp://errors.angularjs.org/1.4.8/' +
138 (module ? module + '/' : '') + code;
140 for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') {
141 message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' +
142 encodeURIComponent(toDebugString(templateArgs[i]));
145 return new ErrorConstructor(message);
149 /* We need to tell jshint what variables are being exported */
150 /* global angular: true,
161 REGEX_STRING_REGEXP: true,
162 VALIDITY_STATE_PROPERTY: true,
166 manualLowercase: true,
167 manualUppercase: true,
200 escapeForRegexp: true,
213 toJsonReplacer: true,
216 convertTimezoneToLocal: true,
217 timezoneToOffset: true,
219 tryDecodeURIComponent: true,
222 encodeUriSegment: true,
223 encodeUriQuery: true,
226 getTestability: true,
231 assertNotHasOwnProperty: true,
234 hasOwnProperty: true,
237 NODE_TYPE_ELEMENT: true,
238 NODE_TYPE_ATTRIBUTE: true,
239 NODE_TYPE_TEXT: true,
240 NODE_TYPE_COMMENT: true,
241 NODE_TYPE_DOCUMENT: true,
242 NODE_TYPE_DOCUMENT_FRAGMENT: true,
245 ////////////////////////////////////
254 * The ng module is loaded by default when an AngularJS application is started. The module itself
255 * contains the essential components for an AngularJS application to function. The table below
256 * lists a high level breakdown of each of the services/factories, filters, directives and testing
257 * components available within this core module.
259 * <div doc-module-components="ng"></div>
262 var REGEX_STRING_REGEXP = /^\/(.+)\/([a-z]*)$/;
264 // The name of a form control's ValidityState property.
265 // This is used so that it's possible for internal tests to create mock ValidityStates.
266 var VALIDITY_STATE_PROPERTY = 'validity';
270 * @name angular.lowercase
274 * @description Converts the specified string to lowercase.
275 * @param {string} string String to be converted to lowercase.
276 * @returns {string} Lowercased string.
278 var lowercase = function(string) {return isString(string) ? string.toLowerCase() : string;};
279 var hasOwnProperty = Object.prototype.hasOwnProperty;
283 * @name angular.uppercase
287 * @description Converts the specified string to uppercase.
288 * @param {string} string String to be converted to uppercase.
289 * @returns {string} Uppercased string.
291 var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
294 var manualLowercase = function(s) {
295 /* jshint bitwise: false */
297 ? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);})
300 var manualUppercase = function(s) {
301 /* jshint bitwise: false */
303 ? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);})
308 // String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish
309 // locale, for this reason we need to detect this case and redefine lowercase/uppercase methods
310 // with correct but slower alternatives.
311 if ('i' !== 'I'.toLowerCase()) {
312 lowercase = manualLowercase;
313 uppercase = manualUppercase;
318 msie, // holds major version number for IE, or NaN if UA is not IE.
319 jqLite, // delay binding since jQuery could be loaded after us.
320 jQuery, // delay binding
324 toString = Object.prototype.toString,
325 getPrototypeOf = Object.getPrototypeOf,
326 ngMinErr = minErr('ng'),
329 angular = window.angular || (window.angular = {}),
334 * documentMode is an IE-only property
335 * http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
337 msie = document.documentMode;
343 * @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
346 function isArrayLike(obj) {
348 // `null`, `undefined` and `window` are not array-like
349 if (obj == null || isWindow(obj)) return false;
351 // arrays, strings and jQuery/jqLite objects are array like
352 // * jqLite is either the jQuery or jqLite constructor function
353 // * we have to check the existance of jqLite first as this method is called
354 // via the forEach method when constructing the jqLite object in the first place
355 if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) return true;
357 // Support: iOS 8.2 (not reproducible in simulator)
358 // "length" in obj used to prevent JIT error (gh-11508)
359 var length = "length" in Object(obj) && obj.length;
361 // NodeList objects (with `item` method) and
362 // other objects with suitable length characteristics are array-like
363 return isNumber(length) &&
364 (length >= 0 && (length - 1) in obj || typeof obj.item == 'function');
369 * @name angular.forEach
374 * Invokes the `iterator` function once for each item in `obj` collection, which can be either an
375 * object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
376 * is the value of an object property or an array element, `key` is the object property key or
377 * array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
379 * It is worth noting that `.forEach` does not iterate over inherited properties because it filters
380 * using the `hasOwnProperty` method.
383 * [Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
384 * Providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
385 * return the value provided.
388 var values = {name: 'misko', gender: 'male'};
390 angular.forEach(values, function(value, key) {
391 this.push(key + ': ' + value);
393 expect(log).toEqual(['name: misko', 'gender: male']);
396 * @param {Object|Array} obj Object to iterate over.
397 * @param {Function} iterator Iterator function.
398 * @param {Object=} context Object to become context (`this`) for the iterator function.
399 * @returns {Object|Array} Reference to `obj`.
402 function forEach(obj, iterator, context) {
405 if (isFunction(obj)) {
407 // Need to check if hasOwnProperty exists,
408 // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
409 if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
410 iterator.call(context, obj[key], key, obj);
413 } else if (isArray(obj) || isArrayLike(obj)) {
414 var isPrimitive = typeof obj !== 'object';
415 for (key = 0, length = obj.length; key < length; key++) {
416 if (isPrimitive || key in obj) {
417 iterator.call(context, obj[key], key, obj);
420 } else if (obj.forEach && obj.forEach !== forEach) {
421 obj.forEach(iterator, context, obj);
422 } else if (isBlankObject(obj)) {
423 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
425 iterator.call(context, obj[key], key, obj);
427 } else if (typeof obj.hasOwnProperty === 'function') {
428 // Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
430 if (obj.hasOwnProperty(key)) {
431 iterator.call(context, obj[key], key, obj);
435 // Slow path for objects which do not have a method `hasOwnProperty`
437 if (hasOwnProperty.call(obj, key)) {
438 iterator.call(context, obj[key], key, obj);
446 function forEachSorted(obj, iterator, context) {
447 var keys = Object.keys(obj).sort();
448 for (var i = 0; i < keys.length; i++) {
449 iterator.call(context, obj[keys[i]], keys[i]);
456 * when using forEach the params are value, key, but it is often useful to have key, value.
457 * @param {function(string, *)} iteratorFn
458 * @returns {function(*, string)}
460 function reverseParams(iteratorFn) {
461 return function(value, key) { iteratorFn(key, value); };
465 * A consistent way of creating unique IDs in angular.
467 * Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
468 * we hit number precision issues in JavaScript.
470 * Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
472 * @returns {number} an unique alpha-numeric string
480 * Set or clear the hashkey for an object.
482 * @param h the hashkey (!truthy to delete the hashkey)
484 function setHashKey(obj, h) {
488 delete obj.$$hashKey;
493 function baseExtend(dst, objs, deep) {
494 var h = dst.$$hashKey;
496 for (var i = 0, ii = objs.length; i < ii; ++i) {
498 if (!isObject(obj) && !isFunction(obj)) continue;
499 var keys = Object.keys(obj);
500 for (var j = 0, jj = keys.length; j < jj; j++) {
504 if (deep && isObject(src)) {
506 dst[key] = new Date(src.valueOf());
507 } else if (isRegExp(src)) {
508 dst[key] = new RegExp(src);
509 } else if (src.nodeName) {
510 dst[key] = src.cloneNode(true);
511 } else if (isElement(src)) {
512 dst[key] = src.clone();
514 if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
515 baseExtend(dst[key], [src], true);
529 * @name angular.extend
534 * Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
535 * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
536 * by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
538 * **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
539 * {@link angular.merge} for this.
541 * @param {Object} dst Destination object.
542 * @param {...Object} src Source object(s).
543 * @returns {Object} Reference to `dst`.
545 function extend(dst) {
546 return baseExtend(dst, slice.call(arguments, 1), false);
552 * @name angular.merge
557 * Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
558 * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
559 * by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
561 * Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
562 * objects, performing a deep copy.
564 * @param {Object} dst Destination object.
565 * @param {...Object} src Source object(s).
566 * @returns {Object} Reference to `dst`.
568 function merge(dst) {
569 return baseExtend(dst, slice.call(arguments, 1), true);
574 function toInt(str) {
575 return parseInt(str, 10);
579 function inherit(parent, extra) {
580 return extend(Object.create(parent), extra);
590 * A function that performs no operations. This function can be useful when writing code in the
593 function foo(callback) {
594 var result = calculateResult();
595 (callback || angular.noop)(result);
605 * @name angular.identity
610 * A function that returns its first argument. This function is useful when writing code in the
614 function transformer(transformationFn, value) {
615 return (transformationFn || angular.identity)(value);
618 * @param {*} value to be returned.
619 * @returns {*} the value passed in.
621 function identity($) {return $;}
622 identity.$inject = [];
625 function valueFn(value) {return function() {return value;};}
627 function hasCustomToString(obj) {
628 return isFunction(obj.toString) && obj.toString !== toString;
634 * @name angular.isUndefined
639 * Determines if a reference is undefined.
641 * @param {*} value Reference to check.
642 * @returns {boolean} True if `value` is undefined.
644 function isUndefined(value) {return typeof value === 'undefined';}
649 * @name angular.isDefined
654 * Determines if a reference is defined.
656 * @param {*} value Reference to check.
657 * @returns {boolean} True if `value` is defined.
659 function isDefined(value) {return typeof value !== 'undefined';}
664 * @name angular.isObject
669 * Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
670 * considered to be objects. Note that JavaScript arrays are objects.
672 * @param {*} value Reference to check.
673 * @returns {boolean} True if `value` is an `Object` but not `null`.
675 function isObject(value) {
676 // http://jsperf.com/isobject4
677 return value !== null && typeof value === 'object';
682 * Determine if a value is an object with a null prototype
684 * @returns {boolean} True if `value` is an `Object` with a null prototype
686 function isBlankObject(value) {
687 return value !== null && typeof value === 'object' && !getPrototypeOf(value);
693 * @name angular.isString
698 * Determines if a reference is a `String`.
700 * @param {*} value Reference to check.
701 * @returns {boolean} True if `value` is a `String`.
703 function isString(value) {return typeof value === 'string';}
708 * @name angular.isNumber
713 * Determines if a reference is a `Number`.
715 * This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`.
717 * If you wish to exclude these then you can use the native
718 * [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
721 * @param {*} value Reference to check.
722 * @returns {boolean} True if `value` is a `Number`.
724 function isNumber(value) {return typeof value === 'number';}
729 * @name angular.isDate
734 * Determines if a value is a date.
736 * @param {*} value Reference to check.
737 * @returns {boolean} True if `value` is a `Date`.
739 function isDate(value) {
740 return toString.call(value) === '[object Date]';
746 * @name angular.isArray
751 * Determines if a reference is an `Array`.
753 * @param {*} value Reference to check.
754 * @returns {boolean} True if `value` is an `Array`.
756 var isArray = Array.isArray;
760 * @name angular.isFunction
765 * Determines if a reference is a `Function`.
767 * @param {*} value Reference to check.
768 * @returns {boolean} True if `value` is a `Function`.
770 function isFunction(value) {return typeof value === 'function';}
774 * Determines if a value is a regular expression object.
777 * @param {*} value Reference to check.
778 * @returns {boolean} True if `value` is a `RegExp`.
780 function isRegExp(value) {
781 return toString.call(value) === '[object RegExp]';
786 * Checks if `obj` is a window object.
789 * @param {*} obj Object to check
790 * @returns {boolean} True if `obj` is a window obj.
792 function isWindow(obj) {
793 return obj && obj.window === obj;
797 function isScope(obj) {
798 return obj && obj.$evalAsync && obj.$watch;
802 function isFile(obj) {
803 return toString.call(obj) === '[object File]';
807 function isFormData(obj) {
808 return toString.call(obj) === '[object FormData]';
812 function isBlob(obj) {
813 return toString.call(obj) === '[object Blob]';
817 function isBoolean(value) {
818 return typeof value === 'boolean';
822 function isPromiseLike(obj) {
823 return obj && isFunction(obj.then);
827 var TYPED_ARRAY_REGEXP = /^\[object (?:Uint8|Uint8Clamped|Uint16|Uint32|Int8|Int16|Int32|Float32|Float64)Array\]$/;
828 function isTypedArray(value) {
829 return value && isNumber(value.length) && TYPED_ARRAY_REGEXP.test(toString.call(value));
833 var trim = function(value) {
834 return isString(value) ? value.trim() : value;
838 // http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
839 // Prereq: s is a string.
840 var escapeForRegexp = function(s) {
841 return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, '\\$1').
842 replace(/\x08/g, '\\x08');
848 * @name angular.isElement
853 * Determines if a reference is a DOM element (or wrapped jQuery element).
855 * @param {*} value Reference to check.
856 * @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
858 function isElement(node) {
860 (node.nodeName // we are a direct element
861 || (node.prop && node.attr && node.find))); // we have an on and find method part of jQuery API
865 * @param str 'key1,key2,...'
866 * @returns {object} in the form of {key1:true, key2:true, ...}
868 function makeMap(str) {
869 var obj = {}, items = str.split(","), i;
870 for (i = 0; i < items.length; i++) {
871 obj[items[i]] = true;
877 function nodeName_(element) {
878 return lowercase(element.nodeName || (element[0] && element[0].nodeName));
881 function includes(array, obj) {
882 return Array.prototype.indexOf.call(array, obj) != -1;
885 function arrayRemove(array, value) {
886 var index = array.indexOf(value);
888 array.splice(index, 1);
900 * Creates a deep copy of `source`, which should be an object or an array.
902 * * If no destination is supplied, a copy of the object or array is created.
903 * * If a destination is provided, all of its elements (for arrays) or properties (for objects)
904 * are deleted and then all elements/properties from the source are copied to it.
905 * * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned.
906 * * If `source` is identical to 'destination' an exception will be thrown.
908 * @param {*} source The source that will be used to make a copy.
909 * Can be any type, including primitives, `null`, and `undefined`.
910 * @param {(Object|Array)=} destination Destination into which the source is copied. If
911 * provided, must be of the same type as `source`.
912 * @returns {*} The copy or updated `destination`, if `destination` was specified.
915 <example module="copyExample">
916 <file name="index.html">
917 <div ng-controller="ExampleController">
918 <form novalidate class="simple-form">
919 Name: <input type="text" ng-model="user.name" /><br />
920 E-mail: <input type="email" ng-model="user.email" /><br />
921 Gender: <input type="radio" ng-model="user.gender" value="male" />male
922 <input type="radio" ng-model="user.gender" value="female" />female<br />
923 <button ng-click="reset()">RESET</button>
924 <button ng-click="update(user)">SAVE</button>
926 <pre>form = {{user | json}}</pre>
927 <pre>master = {{master | json}}</pre>
931 angular.module('copyExample', [])
932 .controller('ExampleController', ['$scope', function($scope) {
935 $scope.update = function(user) {
936 // Example with 1 argument
937 $scope.master= angular.copy(user);
940 $scope.reset = function() {
941 // Example with 2 arguments
942 angular.copy($scope.master, $scope.user);
951 function copy(source, destination) {
952 var stackSource = [];
956 if (isTypedArray(destination)) {
957 throw ngMinErr('cpta', "Can't copy! TypedArray destination cannot be mutated.");
959 if (source === destination) {
960 throw ngMinErr('cpi', "Can't copy! Source and destination are identical.");
963 // Empty the destination object
964 if (isArray(destination)) {
965 destination.length = 0;
967 forEach(destination, function(value, key) {
968 if (key !== '$$hashKey') {
969 delete destination[key];
974 stackSource.push(source);
975 stackDest.push(destination);
976 return copyRecurse(source, destination);
979 return copyElement(source);
981 function copyRecurse(source, destination) {
982 var h = destination.$$hashKey;
984 if (isArray(source)) {
985 for (var i = 0, ii = source.length; i < ii; i++) {
986 destination.push(copyElement(source[i]));
988 } else if (isBlankObject(source)) {
989 // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
990 for (key in source) {
991 destination[key] = copyElement(source[key]);
993 } else if (source && typeof source.hasOwnProperty === 'function') {
994 // Slow path, which must rely on hasOwnProperty
995 for (key in source) {
996 if (source.hasOwnProperty(key)) {
997 destination[key] = copyElement(source[key]);
1001 // Slowest path --- hasOwnProperty can't be called as a method
1002 for (key in source) {
1003 if (hasOwnProperty.call(source, key)) {
1004 destination[key] = copyElement(source[key]);
1008 setHashKey(destination, h);
1012 function copyElement(source) {
1014 if (!isObject(source)) {
1018 // Already copied values
1019 var index = stackSource.indexOf(source);
1021 return stackDest[index];
1024 if (isWindow(source) || isScope(source)) {
1025 throw ngMinErr('cpws',
1026 "Can't copy! Making copies of Window or Scope instances is not supported.");
1029 var needsRecurse = false;
1032 if (isArray(source)) {
1034 needsRecurse = true;
1035 } else if (isTypedArray(source)) {
1036 destination = new source.constructor(source);
1037 } else if (isDate(source)) {
1038 destination = new Date(source.getTime());
1039 } else if (isRegExp(source)) {
1040 destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
1041 destination.lastIndex = source.lastIndex;
1042 } else if (isFunction(source.cloneNode)) {
1043 destination = source.cloneNode(true);
1045 destination = Object.create(getPrototypeOf(source));
1046 needsRecurse = true;
1049 stackSource.push(source);
1050 stackDest.push(destination);
1053 ? copyRecurse(source, destination)
1059 * Creates a shallow copy of an object, an array or a primitive.
1061 * Assumes that there are no proto properties for objects.
1063 function shallowCopy(src, dst) {
1067 for (var i = 0, ii = src.length; i < ii; i++) {
1070 } else if (isObject(src)) {
1073 for (var key in src) {
1074 if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
1075 dst[key] = src[key];
1086 * @name angular.equals
1091 * Determines if two objects or two values are equivalent. Supports value types, regular
1092 * expressions, arrays and objects.
1094 * Two objects or values are considered equivalent if at least one of the following is true:
1096 * * Both objects or values pass `===` comparison.
1097 * * Both objects or values are of the same type and all of their properties are equal by
1098 * comparing them with `angular.equals`.
1099 * * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
1100 * * Both values represent the same regular expression (In JavaScript,
1101 * /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
1102 * representation matches).
1104 * During a property comparison, properties of `function` type and properties with names
1105 * that begin with `$` are ignored.
1107 * Scope and DOMWindow objects are being compared only by identify (`===`).
1109 * @param {*} o1 Object or value to compare.
1110 * @param {*} o2 Object or value to compare.
1111 * @returns {boolean} True if arguments are equal.
1113 function equals(o1, o2) {
1114 if (o1 === o2) return true;
1115 if (o1 === null || o2 === null) return false;
1116 if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
1117 var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
1119 if (t1 == 'object') {
1121 if (!isArray(o2)) return false;
1122 if ((length = o1.length) == o2.length) {
1123 for (key = 0; key < length; key++) {
1124 if (!equals(o1[key], o2[key])) return false;
1128 } else if (isDate(o1)) {
1129 if (!isDate(o2)) return false;
1130 return equals(o1.getTime(), o2.getTime());
1131 } else if (isRegExp(o1)) {
1132 return isRegExp(o2) ? o1.toString() == o2.toString() : false;
1134 if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
1135 isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
1136 keySet = createMap();
1138 if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
1139 if (!equals(o1[key], o2[key])) return false;
1143 if (!(key in keySet) &&
1144 key.charAt(0) !== '$' &&
1145 isDefined(o2[key]) &&
1146 !isFunction(o2[key])) return false;
1155 var csp = function() {
1156 if (!isDefined(csp.rules)) {
1159 var ngCspElement = (document.querySelector('[ng-csp]') ||
1160 document.querySelector('[data-ng-csp]'));
1163 var ngCspAttribute = ngCspElement.getAttribute('ng-csp') ||
1164 ngCspElement.getAttribute('data-ng-csp');
1166 noUnsafeEval: !ngCspAttribute || (ngCspAttribute.indexOf('no-unsafe-eval') !== -1),
1167 noInlineStyle: !ngCspAttribute || (ngCspAttribute.indexOf('no-inline-style') !== -1)
1171 noUnsafeEval: noUnsafeEval(),
1172 noInlineStyle: false
1179 function noUnsafeEval() {
1181 /* jshint -W031, -W054 */
1183 /* jshint +W031, +W054 */
1197 * @param {string=} ngJq the name of the library available under `window`
1198 * to be used for angular.element
1200 * Use this directive to force the angular.element library. This should be
1201 * used to force either jqLite by leaving ng-jq blank or setting the name of
1202 * the jquery variable under window (eg. jQuery).
1204 * Since angular looks for this directive when it is loaded (doesn't wait for the
1205 * DOMContentLoaded event), it must be placed on an element that comes before the script
1206 * which loads angular. Also, only the first instance of `ng-jq` will be used and all
1210 * This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
1219 * This example shows how to use a jQuery based library of a different name.
1220 * The library name must be available at the top most 'window'.
1223 <html ng-app ng-jq="jQueryLib">
1229 var jq = function() {
1230 if (isDefined(jq.name_)) return jq.name_;
1232 var i, ii = ngAttrPrefixes.length, prefix, name;
1233 for (i = 0; i < ii; ++i) {
1234 prefix = ngAttrPrefixes[i];
1235 if (el = document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]')) {
1236 name = el.getAttribute(prefix + 'jq');
1241 return (jq.name_ = name);
1244 function concat(array1, array2, index) {
1245 return array1.concat(slice.call(array2, index));
1248 function sliceArgs(args, startIndex) {
1249 return slice.call(args, startIndex || 0);
1256 * @name angular.bind
1261 * Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
1262 * `fn`). You can supply optional `args` that are prebound to the function. This feature is also
1263 * known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
1264 * distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
1266 * @param {Object} self Context which `fn` should be evaluated in.
1267 * @param {function()} fn Function to be bound.
1268 * @param {...*} args Optional arguments to be prebound to the `fn` function call.
1269 * @returns {function()} Function that wraps the `fn` with all the specified bindings.
1272 function bind(self, fn) {
1273 var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
1274 if (isFunction(fn) && !(fn instanceof RegExp)) {
1275 return curryArgs.length
1277 return arguments.length
1278 ? fn.apply(self, concat(curryArgs, arguments, 0))
1279 : fn.apply(self, curryArgs);
1282 return arguments.length
1283 ? fn.apply(self, arguments)
1287 // in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
1293 function toJsonReplacer(key, value) {
1296 if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
1298 } else if (isWindow(value)) {
1300 } else if (value && document === value) {
1302 } else if (isScope(value)) {
1312 * @name angular.toJson
1317 * Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
1318 * stripped since angular uses this notation internally.
1320 * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
1321 * @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
1322 * If set to an integer, the JSON output will contain that many spaces per indentation.
1323 * @returns {string|undefined} JSON-ified string representing `obj`.
1325 function toJson(obj, pretty) {
1326 if (typeof obj === 'undefined') return undefined;
1327 if (!isNumber(pretty)) {
1328 pretty = pretty ? 2 : null;
1330 return JSON.stringify(obj, toJsonReplacer, pretty);
1336 * @name angular.fromJson
1341 * Deserializes a JSON string.
1343 * @param {string} json JSON string to deserialize.
1344 * @returns {Object|Array|string|number} Deserialized JSON string.
1346 function fromJson(json) {
1347 return isString(json)
1353 function timezoneToOffset(timezone, fallback) {
1354 var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
1355 return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
1359 function addDateMinutes(date, minutes) {
1360 date = new Date(date.getTime());
1361 date.setMinutes(date.getMinutes() + minutes);
1366 function convertTimezoneToLocal(date, timezone, reverse) {
1367 reverse = reverse ? -1 : 1;
1368 var timezoneOffset = timezoneToOffset(timezone, date.getTimezoneOffset());
1369 return addDateMinutes(date, reverse * (timezoneOffset - date.getTimezoneOffset()));
1374 * @returns {string} Returns the string representation of the element.
1376 function startingTag(element) {
1377 element = jqLite(element).clone();
1379 // turns out IE does not let you set .html() on elements which
1380 // are not allowed to have children. So we just ignore it.
1383 var elemHtml = jqLite('<div>').append(element).html();
1385 return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
1387 match(/^(<[^>]+>)/)[1].
1388 replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
1390 return lowercase(elemHtml);
1396 /////////////////////////////////////////////////
1399 * Tries to decode the URI component without throwing an exception.
1402 * @param str value potential URI component to check.
1403 * @returns {boolean} True if `value` can be decoded
1404 * with the decodeURIComponent function.
1406 function tryDecodeURIComponent(value) {
1408 return decodeURIComponent(value);
1410 // Ignore any invalid uri component
1416 * Parses an escaped url query string into key-value pairs.
1417 * @returns {Object.<string,boolean|Array>}
1419 function parseKeyValue(/**string*/keyValue) {
1421 forEach((keyValue || "").split('&'), function(keyValue) {
1422 var splitPoint, key, val;
1424 key = keyValue = keyValue.replace(/\+/g,'%20');
1425 splitPoint = keyValue.indexOf('=');
1426 if (splitPoint !== -1) {
1427 key = keyValue.substring(0, splitPoint);
1428 val = keyValue.substring(splitPoint + 1);
1430 key = tryDecodeURIComponent(key);
1431 if (isDefined(key)) {
1432 val = isDefined(val) ? tryDecodeURIComponent(val) : true;
1433 if (!hasOwnProperty.call(obj, key)) {
1435 } else if (isArray(obj[key])) {
1438 obj[key] = [obj[key],val];
1446 function toKeyValue(obj) {
1448 forEach(obj, function(value, key) {
1449 if (isArray(value)) {
1450 forEach(value, function(arrayValue) {
1451 parts.push(encodeUriQuery(key, true) +
1452 (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
1455 parts.push(encodeUriQuery(key, true) +
1456 (value === true ? '' : '=' + encodeUriQuery(value, true)));
1459 return parts.length ? parts.join('&') : '';
1464 * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
1465 * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
1468 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
1469 * pct-encoded = "%" HEXDIG HEXDIG
1470 * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1471 * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1472 * / "*" / "+" / "," / ";" / "="
1474 function encodeUriSegment(val) {
1475 return encodeUriQuery(val, true).
1476 replace(/%26/gi, '&').
1477 replace(/%3D/gi, '=').
1478 replace(/%2B/gi, '+');
1483 * This method is intended for encoding *key* or *value* parts of query component. We need a custom
1484 * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
1485 * encoded per http://tools.ietf.org/html/rfc3986:
1486 * query = *( pchar / "/" / "?" )
1487 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
1488 * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1489 * pct-encoded = "%" HEXDIG HEXDIG
1490 * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1491 * / "*" / "+" / "," / ";" / "="
1493 function encodeUriQuery(val, pctEncodeSpaces) {
1494 return encodeURIComponent(val).
1495 replace(/%40/gi, '@').
1496 replace(/%3A/gi, ':').
1497 replace(/%24/g, '$').
1498 replace(/%2C/gi, ',').
1499 replace(/%3B/gi, ';').
1500 replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
1503 var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-'];
1505 function getNgAttribute(element, ngAttr) {
1506 var attr, i, ii = ngAttrPrefixes.length;
1507 for (i = 0; i < ii; ++i) {
1508 attr = ngAttrPrefixes[i] + ngAttr;
1509 if (isString(attr = element.getAttribute(attr))) {
1522 * @param {angular.Module} ngApp an optional application
1523 * {@link angular.module module} name to load.
1524 * @param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be
1525 * created in "strict-di" mode. This means that the application will fail to invoke functions which
1526 * do not use explicit function annotation (and are thus unsuitable for minification), as described
1527 * in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in
1528 * tracking down the root of these bugs.
1532 * Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
1533 * designates the **root element** of the application and is typically placed near the root element
1534 * of the page - e.g. on the `<body>` or `<html>` tags.
1536 * Only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
1537 * found in the document will be used to define the root element to auto-bootstrap as an
1538 * application. To run multiple applications in an HTML document you must manually bootstrap them using
1539 * {@link angular.bootstrap} instead. AngularJS applications cannot be nested within each other.
1541 * You can specify an **AngularJS module** to be used as the root module for the application. This
1542 * module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
1543 * should contain the application code needed or have dependencies on other modules that will
1544 * contain the code. See {@link angular.module} for more information.
1546 * In the example below if the `ngApp` directive were not placed on the `html` element then the
1547 * document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
1548 * would not be resolved to `3`.
1550 * `ngApp` is the easiest, and most common way to bootstrap an application.
1552 <example module="ngAppDemo">
1553 <file name="index.html">
1554 <div ng-controller="ngAppDemoController">
1555 I can add: {{a}} + {{b}} = {{ a+b }}
1558 <file name="script.js">
1559 angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
1566 * Using `ngStrictDi`, you would see something like this:
1568 <example ng-app-included="true">
1569 <file name="index.html">
1570 <div ng-app="ngAppStrictDemo" ng-strict-di>
1571 <div ng-controller="GoodController1">
1572 I can add: {{a}} + {{b}} = {{ a+b }}
1574 <p>This renders because the controller does not fail to
1575 instantiate, by using explicit annotation style (see
1576 script.js for details)
1580 <div ng-controller="GoodController2">
1581 Name: <input ng-model="name"><br />
1584 <p>This renders because the controller does not fail to
1585 instantiate, by using explicit annotation style
1586 (see script.js for details)
1590 <div ng-controller="BadController">
1591 I can add: {{a}} + {{b}} = {{ a+b }}
1593 <p>The controller could not be instantiated, due to relying
1594 on automatic function annotations (which are disabled in
1595 strict mode). As such, the content of this section is not
1596 interpolated, and there should be an error in your web console.
1601 <file name="script.js">
1602 angular.module('ngAppStrictDemo', [])
1603 // BadController will fail to instantiate, due to relying on automatic function annotation,
1604 // rather than an explicit annotation
1605 .controller('BadController', function($scope) {
1609 // Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated,
1610 // due to using explicit annotations using the array style and $inject property, respectively.
1611 .controller('GoodController1', ['$scope', function($scope) {
1615 .controller('GoodController2', GoodController2);
1616 function GoodController2($scope) {
1617 $scope.name = "World";
1619 GoodController2.$inject = ['$scope'];
1621 <file name="style.css">
1622 div[ng-controller] {
1624 -webkit-border-radius: 4px;
1629 div[ng-controller^=Good] {
1630 border-color: #d6e9c6;
1631 background-color: #dff0d8;
1634 div[ng-controller^=Bad] {
1635 border-color: #ebccd1;
1636 background-color: #f2dede;
1643 function angularInit(element, bootstrap) {
1648 // The element `element` has priority over any other element
1649 forEach(ngAttrPrefixes, function(prefix) {
1650 var name = prefix + 'app';
1652 if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
1653 appElement = element;
1654 module = element.getAttribute(name);
1657 forEach(ngAttrPrefixes, function(prefix) {
1658 var name = prefix + 'app';
1661 if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
1662 appElement = candidate;
1663 module = candidate.getAttribute(name);
1667 config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
1668 bootstrap(appElement, module ? [module] : [], config);
1674 * @name angular.bootstrap
1677 * Use this function to manually start up angular application.
1679 * See: {@link guide/bootstrap Bootstrap}
1681 * Note that Protractor based end-to-end tests cannot use this function to bootstrap manually.
1682 * They must use {@link ng.directive:ngApp ngApp}.
1684 * Angular will detect if it has been loaded into the browser more than once and only allow the
1685 * first loaded script to be bootstrapped and will report a warning to the browser console for
1686 * each of the subsequent scripts. This prevents strange results in applications, where otherwise
1687 * multiple instances of Angular try to work on the DOM.
1693 * <div ng-controller="WelcomeController">
1697 * <script src="angular.js"></script>
1699 * var app = angular.module('demo', [])
1700 * .controller('WelcomeController', function($scope) {
1701 * $scope.greeting = 'Welcome!';
1703 * angular.bootstrap(document, ['demo']);
1709 * @param {DOMElement} element DOM element which is the root of angular application.
1710 * @param {Array<String|Function|Array>=} modules an array of modules to load into the application.
1711 * Each item in the array should be the name of a predefined module or a (DI annotated)
1712 * function that will be invoked by the injector as a `config` block.
1713 * See: {@link angular.module modules}
1714 * @param {Object=} config an object for defining configuration options for the application. The
1715 * following keys are supported:
1717 * * `strictDi` - disable automatic function annotation for the application. This is meant to
1718 * assist in finding bugs which break minified code. Defaults to `false`.
1720 * @returns {auto.$injector} Returns the newly created injector for this app.
1722 function bootstrap(element, modules, config) {
1723 if (!isObject(config)) config = {};
1724 var defaultConfig = {
1727 config = extend(defaultConfig, config);
1728 var doBootstrap = function() {
1729 element = jqLite(element);
1731 if (element.injector()) {
1732 var tag = (element[0] === document) ? 'document' : startingTag(element);
1733 //Encode angle brackets to prevent input from being sanitized to empty string #8683
1736 "App Already Bootstrapped with this Element '{0}'",
1737 tag.replace(/</,'<').replace(/>/,'>'));
1740 modules = modules || [];
1741 modules.unshift(['$provide', function($provide) {
1742 $provide.value('$rootElement', element);
1745 if (config.debugInfoEnabled) {
1746 // Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
1747 modules.push(['$compileProvider', function($compileProvider) {
1748 $compileProvider.debugInfoEnabled(true);
1752 modules.unshift('ng');
1753 var injector = createInjector(modules, config.strictDi);
1754 injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
1755 function bootstrapApply(scope, element, compile, injector) {
1756 scope.$apply(function() {
1757 element.data('$injector', injector);
1758 compile(element)(scope);
1765 var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/;
1766 var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
1768 if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) {
1769 config.debugInfoEnabled = true;
1770 window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, '');
1773 if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
1774 return doBootstrap();
1777 window.name = window.name.replace(NG_DEFER_BOOTSTRAP, '');
1778 angular.resumeBootstrap = function(extraModules) {
1779 forEach(extraModules, function(module) {
1780 modules.push(module);
1782 return doBootstrap();
1785 if (isFunction(angular.resumeDeferredBootstrap)) {
1786 angular.resumeDeferredBootstrap();
1792 * @name angular.reloadWithDebugInfo
1795 * Use this function to reload the current application with debug information turned on.
1796 * This takes precedence over a call to `$compileProvider.debugInfoEnabled(false)`.
1798 * See {@link ng.$compileProvider#debugInfoEnabled} for more.
1800 function reloadWithDebugInfo() {
1801 window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
1802 window.location.reload();
1806 * @name angular.getTestability
1809 * Get the testability service for the instance of Angular on the given
1811 * @param {DOMElement} element DOM element which is the root of angular application.
1813 function getTestability(rootElement) {
1814 var injector = angular.element(rootElement).injector();
1816 throw ngMinErr('test',
1817 'no injector found for element argument to getTestability');
1819 return injector.get('$$testability');
1822 var SNAKE_CASE_REGEXP = /[A-Z]/g;
1823 function snake_case(name, separator) {
1824 separator = separator || '_';
1825 return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) {
1826 return (pos ? separator : '') + letter.toLowerCase();
1830 var bindJQueryFired = false;
1831 var skipDestroyOnNextJQueryCleanData;
1832 function bindJQuery() {
1833 var originalCleanData;
1835 if (bindJQueryFired) {
1839 // bind to jQuery if present;
1841 jQuery = isUndefined(jqName) ? window.jQuery : // use jQuery (if present)
1842 !jqName ? undefined : // use jqLite
1843 window[jqName]; // use jQuery specified by `ngJq`
1845 // Use jQuery if it exists with proper functionality, otherwise default to us.
1846 // Angular 1.2+ requires jQuery 1.7+ for on()/off() support.
1847 // Angular 1.3+ technically requires at least jQuery 2.1+ but it may work with older
1848 // versions. It will not work for sure with jQuery <1.7, though.
1849 if (jQuery && jQuery.fn.on) {
1852 scope: JQLitePrototype.scope,
1853 isolateScope: JQLitePrototype.isolateScope,
1854 controller: JQLitePrototype.controller,
1855 injector: JQLitePrototype.injector,
1856 inheritedData: JQLitePrototype.inheritedData
1859 // All nodes removed from the DOM via various jQuery APIs like .remove()
1860 // are passed through jQuery.cleanData. Monkey-patch this method to fire
1861 // the $destroy event on all removed nodes.
1862 originalCleanData = jQuery.cleanData;
1863 jQuery.cleanData = function(elems) {
1865 if (!skipDestroyOnNextJQueryCleanData) {
1866 for (var i = 0, elem; (elem = elems[i]) != null; i++) {
1867 events = jQuery._data(elem, "events");
1868 if (events && events.$destroy) {
1869 jQuery(elem).triggerHandler('$destroy');
1873 skipDestroyOnNextJQueryCleanData = false;
1875 originalCleanData(elems);
1881 angular.element = jqLite;
1883 // Prevent double-proxying.
1884 bindJQueryFired = true;
1888 * throw error if the argument is falsy.
1890 function assertArg(arg, name, reason) {
1892 throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required"));
1897 function assertArgFn(arg, name, acceptArrayAnnotation) {
1898 if (acceptArrayAnnotation && isArray(arg)) {
1899 arg = arg[arg.length - 1];
1902 assertArg(isFunction(arg), name, 'not a function, got ' +
1903 (arg && typeof arg === 'object' ? arg.constructor.name || 'Object' : typeof arg));
1908 * throw error if the name given is hasOwnProperty
1909 * @param {String} name the name to test
1910 * @param {String} context the context in which the name is used, such as module or directive
1912 function assertNotHasOwnProperty(name, context) {
1913 if (name === 'hasOwnProperty') {
1914 throw ngMinErr('badname', "hasOwnProperty is not a valid {0} name", context);
1919 * Return the value accessible from the object by path. Any undefined traversals are ignored
1920 * @param {Object} obj starting object
1921 * @param {String} path path to traverse
1922 * @param {boolean} [bindFnToScope=true]
1923 * @returns {Object} value as accessible by path
1925 //TODO(misko): this function needs to be removed
1926 function getter(obj, path, bindFnToScope) {
1927 if (!path) return obj;
1928 var keys = path.split('.');
1930 var lastInstance = obj;
1931 var len = keys.length;
1933 for (var i = 0; i < len; i++) {
1936 obj = (lastInstance = obj)[key];
1939 if (!bindFnToScope && isFunction(obj)) {
1940 return bind(lastInstance, obj);
1946 * Return the DOM siblings between the first and last node in the given array.
1947 * @param {Array} array like object
1948 * @returns {Array} the inputted object or a jqLite collection containing the nodes
1950 function getBlockNodes(nodes) {
1951 // TODO(perf): update `nodes` instead of creating a new object?
1952 var node = nodes[0];
1953 var endNode = nodes[nodes.length - 1];
1956 for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
1957 if (blockNodes || nodes[i] !== node) {
1959 blockNodes = jqLite(slice.call(nodes, 0, i));
1961 blockNodes.push(node);
1965 return blockNodes || nodes;
1970 * Creates a new object without a prototype. This object is useful for lookup without having to
1971 * guard against prototypically inherited properties via hasOwnProperty.
1973 * Related micro-benchmarks:
1974 * - http://jsperf.com/object-create2
1975 * - http://jsperf.com/proto-map-lookup/2
1976 * - http://jsperf.com/for-in-vs-object-keys2
1980 function createMap() {
1981 return Object.create(null);
1984 var NODE_TYPE_ELEMENT = 1;
1985 var NODE_TYPE_ATTRIBUTE = 2;
1986 var NODE_TYPE_TEXT = 3;
1987 var NODE_TYPE_COMMENT = 8;
1988 var NODE_TYPE_DOCUMENT = 9;
1989 var NODE_TYPE_DOCUMENT_FRAGMENT = 11;
1993 * @name angular.Module
1997 * Interface for configuring angular {@link angular.module modules}.
2000 function setupModuleLoader(window) {
2002 var $injectorMinErr = minErr('$injector');
2003 var ngMinErr = minErr('ng');
2005 function ensure(obj, name, factory) {
2006 return obj[name] || (obj[name] = factory());
2009 var angular = ensure(window, 'angular', Object);
2011 // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
2012 angular.$$minErr = angular.$$minErr || minErr;
2014 return ensure(angular, 'module', function() {
2015 /** @type {Object.<string, angular.Module>} */
2020 * @name angular.module
2024 * The `angular.module` is a global place for creating, registering and retrieving Angular
2026 * All modules (angular core or 3rd party) that should be available to an application must be
2027 * registered using this mechanism.
2029 * Passing one argument retrieves an existing {@link angular.Module},
2030 * whereas passing more than one argument creates a new {@link angular.Module}
2035 * A module is a collection of services, directives, controllers, filters, and configuration information.
2036 * `angular.module` is used to configure the {@link auto.$injector $injector}.
2039 * // Create a new module
2040 * var myModule = angular.module('myModule', []);
2042 * // register a new service
2043 * myModule.value('appName', 'MyCoolApp');
2045 * // configure existing services inside initialization blocks.
2046 * myModule.config(['$locationProvider', function($locationProvider) {
2047 * // Configure existing providers
2048 * $locationProvider.hashPrefix('!');
2052 * Then you can create an injector and load your modules like this:
2055 * var injector = angular.injector(['ng', 'myModule'])
2058 * However it's more likely that you'll just use
2059 * {@link ng.directive:ngApp ngApp} or
2060 * {@link angular.bootstrap} to simplify this process for you.
2062 * @param {!string} name The name of the module to create or retrieve.
2063 * @param {!Array.<string>=} requires If specified then new module is being created. If
2064 * unspecified then the module is being retrieved for further configuration.
2065 * @param {Function=} configFn Optional configuration function for the module. Same as
2066 * {@link angular.Module#config Module#config()}.
2067 * @returns {module} new module with the {@link angular.Module} api.
2069 return function module(name, requires, configFn) {
2070 var assertNotHasOwnProperty = function(name, context) {
2071 if (name === 'hasOwnProperty') {
2072 throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
2076 assertNotHasOwnProperty(name, 'module');
2077 if (requires && modules.hasOwnProperty(name)) {
2078 modules[name] = null;
2080 return ensure(modules, name, function() {
2082 throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
2083 "the module name or forgot to load it. If registering a module ensure that you " +
2084 "specify the dependencies as the second argument.", name);
2087 /** @type {!Array.<Array.<*>>} */
2088 var invokeQueue = [];
2090 /** @type {!Array.<Function>} */
2091 var configBlocks = [];
2093 /** @type {!Array.<Function>} */
2096 var config = invokeLater('$injector', 'invoke', 'push', configBlocks);
2098 /** @type {angular.Module} */
2099 var moduleInstance = {
2101 _invokeQueue: invokeQueue,
2102 _configBlocks: configBlocks,
2103 _runBlocks: runBlocks,
2107 * @name angular.Module#requires
2111 * Holds the list of modules which the injector will load before the current module is
2118 * @name angular.Module#name
2122 * Name of the module.
2129 * @name angular.Module#provider
2131 * @param {string} name service name
2132 * @param {Function} providerType Construction function for creating new instance of the
2135 * See {@link auto.$provide#provider $provide.provider()}.
2137 provider: invokeLaterAndSetModuleName('$provide', 'provider'),
2141 * @name angular.Module#factory
2143 * @param {string} name service name
2144 * @param {Function} providerFunction Function for creating new instance of the service.
2146 * See {@link auto.$provide#factory $provide.factory()}.
2148 factory: invokeLaterAndSetModuleName('$provide', 'factory'),
2152 * @name angular.Module#service
2154 * @param {string} name service name
2155 * @param {Function} constructor A constructor function that will be instantiated.
2157 * See {@link auto.$provide#service $provide.service()}.
2159 service: invokeLaterAndSetModuleName('$provide', 'service'),
2163 * @name angular.Module#value
2165 * @param {string} name service name
2166 * @param {*} object Service instance object.
2168 * See {@link auto.$provide#value $provide.value()}.
2170 value: invokeLater('$provide', 'value'),
2174 * @name angular.Module#constant
2176 * @param {string} name constant name
2177 * @param {*} object Constant value.
2179 * Because the constants are fixed, they get applied before other provide methods.
2180 * See {@link auto.$provide#constant $provide.constant()}.
2182 constant: invokeLater('$provide', 'constant', 'unshift'),
2186 * @name angular.Module#decorator
2188 * @param {string} The name of the service to decorate.
2189 * @param {Function} This function will be invoked when the service needs to be
2190 * instantiated and should return the decorated service instance.
2192 * See {@link auto.$provide#decorator $provide.decorator()}.
2194 decorator: invokeLaterAndSetModuleName('$provide', 'decorator'),
2198 * @name angular.Module#animation
2200 * @param {string} name animation name
2201 * @param {Function} animationFactory Factory function for creating new instance of an
2205 * **NOTE**: animations take effect only if the **ngAnimate** module is loaded.
2208 * Defines an animation hook that can be later used with
2209 * {@link $animate $animate} service and directives that use this service.
2212 * module.animation('.animation-name', function($inject1, $inject2) {
2214 * eventName : function(element, done) {
2215 * //code to run the animation
2216 * //once complete, then run done()
2217 * return function cancellationFunction(element) {
2218 * //code to cancel the animation
2225 * See {@link ng.$animateProvider#register $animateProvider.register()} and
2226 * {@link ngAnimate ngAnimate module} for more information.
2228 animation: invokeLaterAndSetModuleName('$animateProvider', 'register'),
2232 * @name angular.Module#filter
2234 * @param {string} name Filter name - this must be a valid angular expression identifier
2235 * @param {Function} filterFactory Factory function for creating new instance of filter.
2237 * See {@link ng.$filterProvider#register $filterProvider.register()}.
2239 * <div class="alert alert-warning">
2240 * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`.
2241 * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
2242 * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
2243 * (`myapp_subsection_filterx`).
2246 filter: invokeLaterAndSetModuleName('$filterProvider', 'register'),
2250 * @name angular.Module#controller
2252 * @param {string|Object} name Controller name, or an object map of controllers where the
2253 * keys are the names and the values are the constructors.
2254 * @param {Function} constructor Controller constructor function.
2256 * See {@link ng.$controllerProvider#register $controllerProvider.register()}.
2258 controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'),
2262 * @name angular.Module#directive
2264 * @param {string|Object} name Directive name, or an object map of directives where the
2265 * keys are the names and the values are the factories.
2266 * @param {Function} directiveFactory Factory function for creating new instance of
2269 * See {@link ng.$compileProvider#directive $compileProvider.directive()}.
2271 directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),
2275 * @name angular.Module#config
2277 * @param {Function} configFn Execute this function on module load. Useful for service
2280 * Use this method to register work which needs to be performed on module loading.
2281 * For more about how to configure services, see
2282 * {@link providers#provider-recipe Provider Recipe}.
2288 * @name angular.Module#run
2290 * @param {Function} initializationFn Execute this function after injector creation.
2291 * Useful for application initialization.
2293 * Use this method to register work which should be performed when the injector is done
2294 * loading all modules.
2296 run: function(block) {
2297 runBlocks.push(block);
2306 return moduleInstance;
2309 * @param {string} provider
2310 * @param {string} method
2311 * @param {String=} insertMethod
2312 * @returns {angular.Module}
2314 function invokeLater(provider, method, insertMethod, queue) {
2315 if (!queue) queue = invokeQueue;
2317 queue[insertMethod || 'push']([provider, method, arguments]);
2318 return moduleInstance;
2323 * @param {string} provider
2324 * @param {string} method
2325 * @returns {angular.Module}
2327 function invokeLaterAndSetModuleName(provider, method) {
2328 return function(recipeName, factoryFunction) {
2329 if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name;
2330 invokeQueue.push([provider, method, arguments]);
2331 return moduleInstance;
2340 /* global: toDebugString: true */
2342 function serializeObject(obj) {
2345 return JSON.stringify(obj, function(key, val) {
2346 val = toJsonReplacer(key, val);
2347 if (isObject(val)) {
2349 if (seen.indexOf(val) >= 0) return '...';
2357 function toDebugString(obj) {
2358 if (typeof obj === 'function') {
2359 return obj.toString().replace(/ \{[\s\S]*$/, '');
2360 } else if (isUndefined(obj)) {
2362 } else if (typeof obj !== 'string') {
2363 return serializeObject(obj);
2368 /* global angularModule: true,
2373 htmlAnchorDirective,
2382 ngBindHtmlDirective,
2383 ngBindTemplateDirective,
2385 ngClassEvenDirective,
2386 ngClassOddDirective,
2388 ngControllerDirective,
2393 ngIncludeFillContentDirective,
2395 ngNonBindableDirective,
2396 ngPluralizeDirective,
2401 ngSwitchWhenDirective,
2402 ngSwitchDefaultDirective,
2404 ngTranscludeDirective,
2417 ngModelOptionsDirective,
2418 ngAttributeAliasDirectives,
2421 $AnchorScrollProvider,
2423 $CoreAnimateCssProvider,
2424 $$CoreAnimateQueueProvider,
2425 $$CoreAnimateRunnerProvider,
2427 $CacheFactoryProvider,
2428 $ControllerProvider,
2430 $ExceptionHandlerProvider,
2432 $$ForceReflowProvider,
2433 $InterpolateProvider,
2437 $HttpParamSerializerProvider,
2438 $HttpParamSerializerJQLikeProvider,
2439 $HttpBackendProvider,
2440 $xhrFactoryProvider,
2447 $$SanitizeUriProvider,
2449 $SceDelegateProvider,
2451 $TemplateCacheProvider,
2452 $TemplateRequestProvider,
2453 $$TestabilityProvider,
2458 $$CookieReaderProvider
2464 * @name angular.version
2467 * An object that contains information about the current AngularJS version.
2469 * This object has the following properties:
2471 * - `full` – `{string}` – Full version string, such as "0.9.18".
2472 * - `major` – `{number}` – Major version number, such as "0".
2473 * - `minor` – `{number}` – Minor version number, such as "9".
2474 * - `dot` – `{number}` – Dot version number, such as "18".
2475 * - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat".
2478 full: '1.4.8', // all of these placeholder strings will be replaced by grunt's
2479 major: 1, // package task
2482 codeName: 'ice-manipulation'
2486 function publishExternalAPI(angular) {
2488 'bootstrap': bootstrap,
2495 'injector': createInjector,
2499 'fromJson': fromJson,
2500 'identity': identity,
2501 'isUndefined': isUndefined,
2502 'isDefined': isDefined,
2503 'isString': isString,
2504 'isFunction': isFunction,
2505 'isObject': isObject,
2506 'isNumber': isNumber,
2507 'isElement': isElement,
2511 'lowercase': lowercase,
2512 'uppercase': uppercase,
2513 'callbacks': {counter: 0},
2514 'getTestability': getTestability,
2517 'reloadWithDebugInfo': reloadWithDebugInfo
2520 angularModule = setupModuleLoader(window);
2522 angularModule('ng', ['ngLocale'], ['$provide',
2523 function ngModule($provide) {
2524 // $$sanitizeUriProvider needs to be before $compileProvider as it is used by it.
2526 $$sanitizeUri: $$SanitizeUriProvider
2528 $provide.provider('$compile', $CompileProvider).
2530 a: htmlAnchorDirective,
2531 input: inputDirective,
2532 textarea: inputDirective,
2533 form: formDirective,
2534 script: scriptDirective,
2535 select: selectDirective,
2536 style: styleDirective,
2537 option: optionDirective,
2538 ngBind: ngBindDirective,
2539 ngBindHtml: ngBindHtmlDirective,
2540 ngBindTemplate: ngBindTemplateDirective,
2541 ngClass: ngClassDirective,
2542 ngClassEven: ngClassEvenDirective,
2543 ngClassOdd: ngClassOddDirective,
2544 ngCloak: ngCloakDirective,
2545 ngController: ngControllerDirective,
2546 ngForm: ngFormDirective,
2547 ngHide: ngHideDirective,
2548 ngIf: ngIfDirective,
2549 ngInclude: ngIncludeDirective,
2550 ngInit: ngInitDirective,
2551 ngNonBindable: ngNonBindableDirective,
2552 ngPluralize: ngPluralizeDirective,
2553 ngRepeat: ngRepeatDirective,
2554 ngShow: ngShowDirective,
2555 ngStyle: ngStyleDirective,
2556 ngSwitch: ngSwitchDirective,
2557 ngSwitchWhen: ngSwitchWhenDirective,
2558 ngSwitchDefault: ngSwitchDefaultDirective,
2559 ngOptions: ngOptionsDirective,
2560 ngTransclude: ngTranscludeDirective,
2561 ngModel: ngModelDirective,
2562 ngList: ngListDirective,
2563 ngChange: ngChangeDirective,
2564 pattern: patternDirective,
2565 ngPattern: patternDirective,
2566 required: requiredDirective,
2567 ngRequired: requiredDirective,
2568 minlength: minlengthDirective,
2569 ngMinlength: minlengthDirective,
2570 maxlength: maxlengthDirective,
2571 ngMaxlength: maxlengthDirective,
2572 ngValue: ngValueDirective,
2573 ngModelOptions: ngModelOptionsDirective
2576 ngInclude: ngIncludeFillContentDirective
2578 directive(ngAttributeAliasDirectives).
2579 directive(ngEventDirectives);
2581 $anchorScroll: $AnchorScrollProvider,
2582 $animate: $AnimateProvider,
2583 $animateCss: $CoreAnimateCssProvider,
2584 $$animateQueue: $$CoreAnimateQueueProvider,
2585 $$AnimateRunner: $$CoreAnimateRunnerProvider,
2586 $browser: $BrowserProvider,
2587 $cacheFactory: $CacheFactoryProvider,
2588 $controller: $ControllerProvider,
2589 $document: $DocumentProvider,
2590 $exceptionHandler: $ExceptionHandlerProvider,
2591 $filter: $FilterProvider,
2592 $$forceReflow: $$ForceReflowProvider,
2593 $interpolate: $InterpolateProvider,
2594 $interval: $IntervalProvider,
2595 $http: $HttpProvider,
2596 $httpParamSerializer: $HttpParamSerializerProvider,
2597 $httpParamSerializerJQLike: $HttpParamSerializerJQLikeProvider,
2598 $httpBackend: $HttpBackendProvider,
2599 $xhrFactory: $xhrFactoryProvider,
2600 $location: $LocationProvider,
2602 $parse: $ParseProvider,
2603 $rootScope: $RootScopeProvider,
2607 $sceDelegate: $SceDelegateProvider,
2608 $sniffer: $SnifferProvider,
2609 $templateCache: $TemplateCacheProvider,
2610 $templateRequest: $TemplateRequestProvider,
2611 $$testability: $$TestabilityProvider,
2612 $timeout: $TimeoutProvider,
2613 $window: $WindowProvider,
2614 $$rAF: $$RAFProvider,
2615 $$jqLite: $$jqLiteProvider,
2616 $$HashMap: $$HashMapProvider,
2617 $$cookieReader: $$CookieReaderProvider
2623 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2624 * Any commits to this file should be reviewed with security in mind. *
2625 * Changes to this file can potentially create security vulnerabilities. *
2626 * An approval from 2 Core members with history of modifying *
2627 * this file is required. *
2629 * Does the change somehow allow for arbitrary javascript to be executed? *
2630 * Or allows for someone to change the prototype of built-in objects? *
2631 * Or gives undesired access to variables likes document or window? *
2632 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2634 /* global JQLitePrototype: true,
2635 addEventListenerFn: true,
2636 removeEventListenerFn: true,
2641 //////////////////////////////////
2643 //////////////////////////////////
2647 * @name angular.element
2652 * Wraps a raw DOM element or HTML string as a [jQuery](http://jquery.com) element.
2654 * If jQuery is available, `angular.element` is an alias for the
2655 * [jQuery](http://api.jquery.com/jQuery/) function. If jQuery is not available, `angular.element`
2656 * delegates to Angular's built-in subset of jQuery, called "jQuery lite" or "jqLite."
2658 * <div class="alert alert-success">jqLite is a tiny, API-compatible subset of jQuery that allows
2659 * Angular to manipulate the DOM in a cross-browser compatible way. **jqLite** implements only the most
2660 * commonly needed functionality with the goal of having a very small footprint.</div>
2662 * To use `jQuery`, simply ensure it is loaded before the `angular.js` file.
2664 * <div class="alert">**Note:** all element references in Angular are always wrapped with jQuery or
2665 * jqLite; they are never raw DOM references.</div>
2667 * ## Angular's jqLite
2668 * jqLite provides only the following jQuery methods:
2670 * - [`addClass()`](http://api.jquery.com/addClass/)
2671 * - [`after()`](http://api.jquery.com/after/)
2672 * - [`append()`](http://api.jquery.com/append/)
2673 * - [`attr()`](http://api.jquery.com/attr/) - Does not support functions as parameters
2674 * - [`bind()`](http://api.jquery.com/bind/) - Does not support namespaces, selectors or eventData
2675 * - [`children()`](http://api.jquery.com/children/) - Does not support selectors
2676 * - [`clone()`](http://api.jquery.com/clone/)
2677 * - [`contents()`](http://api.jquery.com/contents/)
2678 * - [`css()`](http://api.jquery.com/css/) - Only retrieves inline-styles, does not call `getComputedStyle()`. As a setter, does not convert numbers to strings or append 'px'.
2679 * - [`data()`](http://api.jquery.com/data/)
2680 * - [`detach()`](http://api.jquery.com/detach/)
2681 * - [`empty()`](http://api.jquery.com/empty/)
2682 * - [`eq()`](http://api.jquery.com/eq/)
2683 * - [`find()`](http://api.jquery.com/find/) - Limited to lookups by tag name
2684 * - [`hasClass()`](http://api.jquery.com/hasClass/)
2685 * - [`html()`](http://api.jquery.com/html/)
2686 * - [`next()`](http://api.jquery.com/next/) - Does not support selectors
2687 * - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
2688 * - [`off()`](http://api.jquery.com/off/) - Does not support namespaces, selectors or event object as parameter
2689 * - [`one()`](http://api.jquery.com/one/) - Does not support namespaces or selectors
2690 * - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors
2691 * - [`prepend()`](http://api.jquery.com/prepend/)
2692 * - [`prop()`](http://api.jquery.com/prop/)
2693 * - [`ready()`](http://api.jquery.com/ready/)
2694 * - [`remove()`](http://api.jquery.com/remove/)
2695 * - [`removeAttr()`](http://api.jquery.com/removeAttr/)
2696 * - [`removeClass()`](http://api.jquery.com/removeClass/)
2697 * - [`removeData()`](http://api.jquery.com/removeData/)
2698 * - [`replaceWith()`](http://api.jquery.com/replaceWith/)
2699 * - [`text()`](http://api.jquery.com/text/)
2700 * - [`toggleClass()`](http://api.jquery.com/toggleClass/)
2701 * - [`triggerHandler()`](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers.
2702 * - [`unbind()`](http://api.jquery.com/unbind/) - Does not support namespaces or event object as parameter
2703 * - [`val()`](http://api.jquery.com/val/)
2704 * - [`wrap()`](http://api.jquery.com/wrap/)
2706 * ## jQuery/jqLite Extras
2707 * Angular also provides the following additional methods and events to both jQuery and jqLite:
2710 * - `$destroy` - AngularJS intercepts all jqLite/jQuery's DOM destruction apis and fires this event
2711 * on all DOM nodes being removed. This can be used to clean up any 3rd party bindings to the DOM
2712 * element before it is removed.
2715 * - `controller(name)` - retrieves the controller of the current element or its parent. By default
2716 * retrieves controller associated with the `ngController` directive. If `name` is provided as
2717 * camelCase directive name, then the controller for this directive will be retrieved (e.g.
2719 * - `injector()` - retrieves the injector of the current element or its parent.
2720 * - `scope()` - retrieves the {@link ng.$rootScope.Scope scope} of the current
2721 * element or its parent. Requires {@link guide/production#disabling-debug-data Debug Data} to
2723 * - `isolateScope()` - retrieves an isolate {@link ng.$rootScope.Scope scope} if one is attached directly to the
2724 * current element. This getter should be used only on elements that contain a directive which starts a new isolate
2725 * scope. Calling `scope()` on this element always returns the original non-isolate scope.
2726 * Requires {@link guide/production#disabling-debug-data Debug Data} to be enabled.
2727 * - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
2728 * parent element is reached.
2730 * @param {string|DOMElement} element HTML string or DOMElement to be wrapped into jQuery.
2731 * @returns {Object} jQuery object.
2734 JQLite.expando = 'ng339';
2736 var jqCache = JQLite.cache = {},
2738 addEventListenerFn = function(element, type, fn) {
2739 element.addEventListener(type, fn, false);
2741 removeEventListenerFn = function(element, type, fn) {
2742 element.removeEventListener(type, fn, false);
2746 * !!! This is an undocumented "private" function !!!
2748 JQLite._data = function(node) {
2749 //jQuery always returns an object on cache miss
2750 return this.cache[node[this.expando]] || {};
2753 function jqNextId() { return ++jqId; }
2756 var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
2757 var MOZ_HACK_REGEXP = /^moz([A-Z])/;
2758 var MOUSE_EVENT_MAP= { mouseleave: "mouseout", mouseenter: "mouseover"};
2759 var jqLiteMinErr = minErr('jqLite');
2762 * Converts snake_case to camelCase.
2763 * Also there is special case for Moz prefix starting with upper case letter.
2764 * @param name Name to normalize
2766 function camelCase(name) {
2768 replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
2769 return offset ? letter.toUpperCase() : letter;
2771 replace(MOZ_HACK_REGEXP, 'Moz$1');
2774 var SINGLE_TAG_REGEXP = /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/;
2775 var HTML_REGEXP = /<|&#?\w+;/;
2776 var TAG_NAME_REGEXP = /<([\w:-]+)/;
2777 var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi;
2780 'option': [1, '<select multiple="multiple">', '</select>'],
2782 'thead': [1, '<table>', '</table>'],
2783 'col': [2, '<table><colgroup>', '</colgroup></table>'],
2784 'tr': [2, '<table><tbody>', '</tbody></table>'],
2785 'td': [3, '<table><tbody><tr>', '</tr></tbody></table>'],
2786 '_default': [0, "", ""]
2789 wrapMap.optgroup = wrapMap.option;
2790 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
2791 wrapMap.th = wrapMap.td;
2794 function jqLiteIsTextNode(html) {
2795 return !HTML_REGEXP.test(html);
2798 function jqLiteAcceptsData(node) {
2799 // The window object can accept data but has no nodeType
2800 // Otherwise we are only interested in elements (1) and documents (9)
2801 var nodeType = node.nodeType;
2802 return nodeType === NODE_TYPE_ELEMENT || !nodeType || nodeType === NODE_TYPE_DOCUMENT;
2805 function jqLiteHasData(node) {
2806 for (var key in jqCache[node.ng339]) {
2812 function jqLiteBuildFragment(html, context) {
2814 fragment = context.createDocumentFragment(),
2817 if (jqLiteIsTextNode(html)) {
2818 // Convert non-html into a text node
2819 nodes.push(context.createTextNode(html));
2821 // Convert html into DOM nodes
2822 tmp = tmp || fragment.appendChild(context.createElement("div"));
2823 tag = (TAG_NAME_REGEXP.exec(html) || ["", ""])[1].toLowerCase();
2824 wrap = wrapMap[tag] || wrapMap._default;
2825 tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1></$2>") + wrap[2];
2827 // Descend through wrappers to the right content
2830 tmp = tmp.lastChild;
2833 nodes = concat(nodes, tmp.childNodes);
2835 tmp = fragment.firstChild;
2836 tmp.textContent = "";
2839 // Remove wrapper from fragment
2840 fragment.textContent = "";
2841 fragment.innerHTML = ""; // Clear inner HTML
2842 forEach(nodes, function(node) {
2843 fragment.appendChild(node);
2849 function jqLiteParseHTML(html, context) {
2850 context = context || document;
2853 if ((parsed = SINGLE_TAG_REGEXP.exec(html))) {
2854 return [context.createElement(parsed[1])];
2857 if ((parsed = jqLiteBuildFragment(html, context))) {
2858 return parsed.childNodes;
2865 // IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259.
2866 var jqLiteContains = Node.prototype.contains || function(arg) {
2867 // jshint bitwise: false
2868 return !!(this.compareDocumentPosition(arg) & 16);
2869 // jshint bitwise: true
2872 /////////////////////////////////////////////
2873 function JQLite(element) {
2874 if (element instanceof JQLite) {
2880 if (isString(element)) {
2881 element = trim(element);
2884 if (!(this instanceof JQLite)) {
2885 if (argIsString && element.charAt(0) != '<') {
2886 throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
2888 return new JQLite(element);
2892 jqLiteAddNodes(this, jqLiteParseHTML(element));
2894 jqLiteAddNodes(this, element);
2898 function jqLiteClone(element) {
2899 return element.cloneNode(true);
2902 function jqLiteDealoc(element, onlyDescendants) {
2903 if (!onlyDescendants) jqLiteRemoveData(element);
2905 if (element.querySelectorAll) {
2906 var descendants = element.querySelectorAll('*');
2907 for (var i = 0, l = descendants.length; i < l; i++) {
2908 jqLiteRemoveData(descendants[i]);
2913 function jqLiteOff(element, type, fn, unsupported) {
2914 if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
2916 var expandoStore = jqLiteExpandoStore(element);
2917 var events = expandoStore && expandoStore.events;
2918 var handle = expandoStore && expandoStore.handle;
2920 if (!handle) return; //no listeners registered
2923 for (type in events) {
2924 if (type !== '$destroy') {
2925 removeEventListenerFn(element, type, handle);
2927 delete events[type];
2931 var removeHandler = function(type) {
2932 var listenerFns = events[type];
2933 if (isDefined(fn)) {
2934 arrayRemove(listenerFns || [], fn);
2936 if (!(isDefined(fn) && listenerFns && listenerFns.length > 0)) {
2937 removeEventListenerFn(element, type, handle);
2938 delete events[type];
2942 forEach(type.split(' '), function(type) {
2943 removeHandler(type);
2944 if (MOUSE_EVENT_MAP[type]) {
2945 removeHandler(MOUSE_EVENT_MAP[type]);
2951 function jqLiteRemoveData(element, name) {
2952 var expandoId = element.ng339;
2953 var expandoStore = expandoId && jqCache[expandoId];
2957 delete expandoStore.data[name];
2961 if (expandoStore.handle) {
2962 if (expandoStore.events.$destroy) {
2963 expandoStore.handle({}, '$destroy');
2967 delete jqCache[expandoId];
2968 element.ng339 = undefined; // don't delete DOM expandos. IE and Chrome don't like it
2973 function jqLiteExpandoStore(element, createIfNecessary) {
2974 var expandoId = element.ng339,
2975 expandoStore = expandoId && jqCache[expandoId];
2977 if (createIfNecessary && !expandoStore) {
2978 element.ng339 = expandoId = jqNextId();
2979 expandoStore = jqCache[expandoId] = {events: {}, data: {}, handle: undefined};
2982 return expandoStore;
2986 function jqLiteData(element, key, value) {
2987 if (jqLiteAcceptsData(element)) {
2989 var isSimpleSetter = isDefined(value);
2990 var isSimpleGetter = !isSimpleSetter && key && !isObject(key);
2991 var massGetter = !key;
2992 var expandoStore = jqLiteExpandoStore(element, !isSimpleGetter);
2993 var data = expandoStore && expandoStore.data;
2995 if (isSimpleSetter) { // data('key', value)
2998 if (massGetter) { // data()
3001 if (isSimpleGetter) { // data('key')
3002 // don't force creation of expandoStore if it doesn't exist yet
3003 return data && data[key];
3004 } else { // mass-setter: data({key1: val1, key2: val2})
3012 function jqLiteHasClass(element, selector) {
3013 if (!element.getAttribute) return false;
3014 return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " ").
3015 indexOf(" " + selector + " ") > -1);
3018 function jqLiteRemoveClass(element, cssClasses) {
3019 if (cssClasses && element.setAttribute) {
3020 forEach(cssClasses.split(' '), function(cssClass) {
3021 element.setAttribute('class', trim(
3022 (" " + (element.getAttribute('class') || '') + " ")
3023 .replace(/[\n\t]/g, " ")
3024 .replace(" " + trim(cssClass) + " ", " "))
3030 function jqLiteAddClass(element, cssClasses) {
3031 if (cssClasses && element.setAttribute) {
3032 var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ')
3033 .replace(/[\n\t]/g, " ");
3035 forEach(cssClasses.split(' '), function(cssClass) {
3036 cssClass = trim(cssClass);
3037 if (existingClasses.indexOf(' ' + cssClass + ' ') === -1) {
3038 existingClasses += cssClass + ' ';
3042 element.setAttribute('class', trim(existingClasses));
3047 function jqLiteAddNodes(root, elements) {
3048 // THIS CODE IS VERY HOT. Don't make changes without benchmarking.
3052 // if a Node (the most common case)
3053 if (elements.nodeType) {
3054 root[root.length++] = elements;
3056 var length = elements.length;
3058 // if an Array or NodeList and not a Window
3059 if (typeof length === 'number' && elements.window !== elements) {
3061 for (var i = 0; i < length; i++) {
3062 root[root.length++] = elements[i];
3066 root[root.length++] = elements;
3073 function jqLiteController(element, name) {
3074 return jqLiteInheritedData(element, '$' + (name || 'ngController') + 'Controller');
3077 function jqLiteInheritedData(element, name, value) {
3078 // if element is the document object work with the html element instead
3079 // this makes $(document).scope() possible
3080 if (element.nodeType == NODE_TYPE_DOCUMENT) {
3081 element = element.documentElement;
3083 var names = isArray(name) ? name : [name];
3086 for (var i = 0, ii = names.length; i < ii; i++) {
3087 if (isDefined(value = jqLite.data(element, names[i]))) return value;
3090 // If dealing with a document fragment node with a host element, and no parent, use the host
3091 // element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
3092 // to lookup parent controllers.
3093 element = element.parentNode || (element.nodeType === NODE_TYPE_DOCUMENT_FRAGMENT && element.host);
3097 function jqLiteEmpty(element) {
3098 jqLiteDealoc(element, true);
3099 while (element.firstChild) {
3100 element.removeChild(element.firstChild);
3104 function jqLiteRemove(element, keepData) {
3105 if (!keepData) jqLiteDealoc(element);
3106 var parent = element.parentNode;
3107 if (parent) parent.removeChild(element);
3111 function jqLiteDocumentLoaded(action, win) {
3112 win = win || window;
3113 if (win.document.readyState === 'complete') {
3114 // Force the action to be run async for consistent behaviour
3115 // from the action's point of view
3116 // i.e. it will definitely not be in a $apply
3117 win.setTimeout(action);
3119 // No need to unbind this handler as load is only ever called once
3120 jqLite(win).on('load', action);
3124 //////////////////////////////////////////
3125 // Functions which are declared directly.
3126 //////////////////////////////////////////
3127 var JQLitePrototype = JQLite.prototype = {
3128 ready: function(fn) {
3131 function trigger() {
3137 // check if document is already loaded
3138 if (document.readyState === 'complete') {
3139 setTimeout(trigger);
3141 this.on('DOMContentLoaded', trigger); // works for modern browsers and IE9
3142 // we can not use jqLite since we are not done loading and jQuery could be loaded later.
3144 JQLite(window).on('load', trigger); // fallback to window.onload for others
3148 toString: function() {
3150 forEach(this, function(e) { value.push('' + e);});
3151 return '[' + value.join(', ') + ']';
3154 eq: function(index) {
3155 return (index >= 0) ? jqLite(this[index]) : jqLite(this[this.length + index]);
3164 //////////////////////////////////////////
3165 // Functions iterating getter/setters.
3166 // these functions return self on setter and
3168 //////////////////////////////////////////
3169 var BOOLEAN_ATTR = {};
3170 forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) {
3171 BOOLEAN_ATTR[lowercase(value)] = value;
3173 var BOOLEAN_ELEMENTS = {};
3174 forEach('input,select,option,textarea,button,form,details'.split(','), function(value) {
3175 BOOLEAN_ELEMENTS[value] = true;
3177 var ALIASED_ATTR = {
3178 'ngMinlength': 'minlength',
3179 'ngMaxlength': 'maxlength',
3182 'ngPattern': 'pattern'
3185 function getBooleanAttrName(element, name) {
3186 // check dom last since we will most likely fail on name
3187 var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()];
3189 // booleanAttr is here twice to minimize DOM access
3190 return booleanAttr && BOOLEAN_ELEMENTS[nodeName_(element)] && booleanAttr;
3193 function getAliasedAttrName(name) {
3194 return ALIASED_ATTR[name];
3199 removeData: jqLiteRemoveData,
3200 hasData: jqLiteHasData
3201 }, function(fn, name) {
3207 inheritedData: jqLiteInheritedData,
3209 scope: function(element) {
3210 // Can't use jqLiteData here directly so we stay compatible with jQuery!
3211 return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
3214 isolateScope: function(element) {
3215 // Can't use jqLiteData here directly so we stay compatible with jQuery!
3216 return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate');
3219 controller: jqLiteController,
3221 injector: function(element) {
3222 return jqLiteInheritedData(element, '$injector');
3225 removeAttr: function(element, name) {
3226 element.removeAttribute(name);
3229 hasClass: jqLiteHasClass,
3231 css: function(element, name, value) {
3232 name = camelCase(name);
3234 if (isDefined(value)) {
3235 element.style[name] = value;
3237 return element.style[name];
3241 attr: function(element, name, value) {
3242 var nodeType = element.nodeType;
3243 if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT) {
3246 var lowercasedName = lowercase(name);
3247 if (BOOLEAN_ATTR[lowercasedName]) {
3248 if (isDefined(value)) {
3250 element[name] = true;
3251 element.setAttribute(name, lowercasedName);
3253 element[name] = false;
3254 element.removeAttribute(lowercasedName);
3257 return (element[name] ||
3258 (element.attributes.getNamedItem(name) || noop).specified)
3262 } else if (isDefined(value)) {
3263 element.setAttribute(name, value);
3264 } else if (element.getAttribute) {
3265 // the extra argument "2" is to get the right thing for a.href in IE, see jQuery code
3266 // some elements (e.g. Document) don't have get attribute, so return undefined
3267 var ret = element.getAttribute(name, 2);
3268 // normalize non-existing attributes to undefined (as jQuery)
3269 return ret === null ? undefined : ret;
3273 prop: function(element, name, value) {
3274 if (isDefined(value)) {
3275 element[name] = value;
3277 return element[name];
3285 function getText(element, value) {
3286 if (isUndefined(value)) {
3287 var nodeType = element.nodeType;
3288 return (nodeType === NODE_TYPE_ELEMENT || nodeType === NODE_TYPE_TEXT) ? element.textContent : '';
3290 element.textContent = value;
3294 val: function(element, value) {
3295 if (isUndefined(value)) {
3296 if (element.multiple && nodeName_(element) === 'select') {
3298 forEach(element.options, function(option) {
3299 if (option.selected) {
3300 result.push(option.value || option.text);
3303 return result.length === 0 ? null : result;
3305 return element.value;
3307 element.value = value;
3310 html: function(element, value) {
3311 if (isUndefined(value)) {
3312 return element.innerHTML;
3314 jqLiteDealoc(element, true);
3315 element.innerHTML = value;
3319 }, function(fn, name) {
3321 * Properties: writes return selection, reads return first value
3323 JQLite.prototype[name] = function(arg1, arg2) {
3325 var nodeCount = this.length;
3327 // jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
3328 // in a way that survives minification.
3329 // jqLiteEmpty takes no arguments but is a setter.
3330 if (fn !== jqLiteEmpty &&
3331 (isUndefined((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2))) {
3332 if (isObject(arg1)) {
3334 // we are a write, but the object properties are the key/values
3335 for (i = 0; i < nodeCount; i++) {
3336 if (fn === jqLiteData) {
3337 // data() takes the whole object in jQuery
3341 fn(this[i], key, arg1[key]);
3345 // return self for chaining
3348 // we are a read, so read the first child.
3349 // TODO: do we still need this?
3351 // Only if we have $dv do we iterate over all, otherwise it is just the first element.
3352 var jj = (isUndefined(value)) ? Math.min(nodeCount, 1) : nodeCount;
3353 for (var j = 0; j < jj; j++) {
3354 var nodeValue = fn(this[j], arg1, arg2);
3355 value = value ? value + nodeValue : nodeValue;
3360 // we are a write, so apply to all children
3361 for (i = 0; i < nodeCount; i++) {
3362 fn(this[i], arg1, arg2);
3364 // return self for chaining
3370 function createEventHandler(element, events) {
3371 var eventHandler = function(event, type) {
3372 // jQuery specific api
3373 event.isDefaultPrevented = function() {
3374 return event.defaultPrevented;
3377 var eventFns = events[type || event.type];
3378 var eventFnsLength = eventFns ? eventFns.length : 0;
3380 if (!eventFnsLength) return;
3382 if (isUndefined(event.immediatePropagationStopped)) {
3383 var originalStopImmediatePropagation = event.stopImmediatePropagation;
3384 event.stopImmediatePropagation = function() {
3385 event.immediatePropagationStopped = true;
3387 if (event.stopPropagation) {
3388 event.stopPropagation();
3391 if (originalStopImmediatePropagation) {
3392 originalStopImmediatePropagation.call(event);
3397 event.isImmediatePropagationStopped = function() {
3398 return event.immediatePropagationStopped === true;
3401 // Some events have special handlers that wrap the real handler
3402 var handlerWrapper = eventFns.specialHandlerWrapper || defaultHandlerWrapper;
3404 // Copy event handlers in case event handlers array is modified during execution.
3405 if ((eventFnsLength > 1)) {
3406 eventFns = shallowCopy(eventFns);
3409 for (var i = 0; i < eventFnsLength; i++) {
3410 if (!event.isImmediatePropagationStopped()) {
3411 handlerWrapper(element, event, eventFns[i]);
3416 // TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all
3417 // events on `element`
3418 eventHandler.elem = element;
3419 return eventHandler;
3422 function defaultHandlerWrapper(element, event, handler) {
3423 handler.call(element, event);
3426 function specialMouseHandlerWrapper(target, event, handler) {
3427 // Refer to jQuery's implementation of mouseenter & mouseleave
3428 // Read about mouseenter and mouseleave:
3429 // http://www.quirksmode.org/js/events_mouse.html#link8
3430 var related = event.relatedTarget;
3431 // For mousenter/leave call the handler if related is outside the target.
3432 // NB: No relatedTarget if the mouse left/entered the browser window
3433 if (!related || (related !== target && !jqLiteContains.call(target, related))) {
3434 handler.call(target, event);
3438 //////////////////////////////////////////
3439 // Functions iterating traversal.
3440 // These functions chain results into a single
3442 //////////////////////////////////////////
3444 removeData: jqLiteRemoveData,
3446 on: function jqLiteOn(element, type, fn, unsupported) {
3447 if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');
3449 // Do not add event handlers to non-elements because they will not be cleaned up.
3450 if (!jqLiteAcceptsData(element)) {
3454 var expandoStore = jqLiteExpandoStore(element, true);
3455 var events = expandoStore.events;
3456 var handle = expandoStore.handle;
3459 handle = expandoStore.handle = createEventHandler(element, events);
3462 // http://jsperf.com/string-indexof-vs-split
3463 var types = type.indexOf(' ') >= 0 ? type.split(' ') : [type];
3464 var i = types.length;
3466 var addHandler = function(type, specialHandlerWrapper, noEventListener) {
3467 var eventFns = events[type];
3470 eventFns = events[type] = [];
3471 eventFns.specialHandlerWrapper = specialHandlerWrapper;
3472 if (type !== '$destroy' && !noEventListener) {
3473 addEventListenerFn(element, type, handle);
3482 if (MOUSE_EVENT_MAP[type]) {
3483 addHandler(MOUSE_EVENT_MAP[type], specialMouseHandlerWrapper);
3484 addHandler(type, undefined, true);
3493 one: function(element, type, fn) {
3494 element = jqLite(element);
3496 //add the listener twice so that when it is called
3497 //you can remove the original function and still be
3498 //able to call element.off(ev, fn) normally
3499 element.on(type, function onFn() {
3500 element.off(type, fn);
3501 element.off(type, onFn);
3503 element.on(type, fn);
3506 replaceWith: function(element, replaceNode) {
3507 var index, parent = element.parentNode;
3508 jqLiteDealoc(element);
3509 forEach(new JQLite(replaceNode), function(node) {
3511 parent.insertBefore(node, index.nextSibling);
3513 parent.replaceChild(node, element);
3519 children: function(element) {
3521 forEach(element.childNodes, function(element) {
3522 if (element.nodeType === NODE_TYPE_ELEMENT) {
3523 children.push(element);
3529 contents: function(element) {
3530 return element.contentDocument || element.childNodes || [];
3533 append: function(element, node) {
3534 var nodeType = element.nodeType;
3535 if (nodeType !== NODE_TYPE_ELEMENT && nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT) return;
3537 node = new JQLite(node);
3539 for (var i = 0, ii = node.length; i < ii; i++) {
3540 var child = node[i];
3541 element.appendChild(child);
3545 prepend: function(element, node) {
3546 if (element.nodeType === NODE_TYPE_ELEMENT) {
3547 var index = element.firstChild;
3548 forEach(new JQLite(node), function(child) {
3549 element.insertBefore(child, index);
3554 wrap: function(element, wrapNode) {
3555 wrapNode = jqLite(wrapNode).eq(0).clone()[0];
3556 var parent = element.parentNode;
3558 parent.replaceChild(wrapNode, element);
3560 wrapNode.appendChild(element);
3563 remove: jqLiteRemove,
3565 detach: function(element) {
3566 jqLiteRemove(element, true);
3569 after: function(element, newElement) {
3570 var index = element, parent = element.parentNode;
3571 newElement = new JQLite(newElement);
3573 for (var i = 0, ii = newElement.length; i < ii; i++) {
3574 var node = newElement[i];
3575 parent.insertBefore(node, index.nextSibling);
3580 addClass: jqLiteAddClass,
3581 removeClass: jqLiteRemoveClass,
3583 toggleClass: function(element, selector, condition) {
3585 forEach(selector.split(' '), function(className) {
3586 var classCondition = condition;
3587 if (isUndefined(classCondition)) {
3588 classCondition = !jqLiteHasClass(element, className);
3590 (classCondition ? jqLiteAddClass : jqLiteRemoveClass)(element, className);
3595 parent: function(element) {
3596 var parent = element.parentNode;
3597 return parent && parent.nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT ? parent : null;
3600 next: function(element) {
3601 return element.nextElementSibling;
3604 find: function(element, selector) {
3605 if (element.getElementsByTagName) {
3606 return element.getElementsByTagName(selector);
3614 triggerHandler: function(element, event, extraParameters) {
3616 var dummyEvent, eventFnsCopy, handlerArgs;
3617 var eventName = event.type || event;
3618 var expandoStore = jqLiteExpandoStore(element);
3619 var events = expandoStore && expandoStore.events;
3620 var eventFns = events && events[eventName];
3623 // Create a dummy event to pass to the handlers
3625 preventDefault: function() { this.defaultPrevented = true; },
3626 isDefaultPrevented: function() { return this.defaultPrevented === true; },
3627 stopImmediatePropagation: function() { this.immediatePropagationStopped = true; },
3628 isImmediatePropagationStopped: function() { return this.immediatePropagationStopped === true; },
3629 stopPropagation: noop,
3634 // If a custom event was provided then extend our dummy event with it
3636 dummyEvent = extend(dummyEvent, event);
3639 // Copy event handlers in case event handlers array is modified during execution.
3640 eventFnsCopy = shallowCopy(eventFns);
3641 handlerArgs = extraParameters ? [dummyEvent].concat(extraParameters) : [dummyEvent];
3643 forEach(eventFnsCopy, function(fn) {
3644 if (!dummyEvent.isImmediatePropagationStopped()) {
3645 fn.apply(element, handlerArgs);
3650 }, function(fn, name) {
3652 * chaining functions
3654 JQLite.prototype[name] = function(arg1, arg2, arg3) {
3657 for (var i = 0, ii = this.length; i < ii; i++) {
3658 if (isUndefined(value)) {
3659 value = fn(this[i], arg1, arg2, arg3);
3660 if (isDefined(value)) {
3661 // any function which returns a value needs to be wrapped
3662 value = jqLite(value);
3665 jqLiteAddNodes(value, fn(this[i], arg1, arg2, arg3));
3668 return isDefined(value) ? value : this;
3671 // bind legacy bind/unbind to on/off
3672 JQLite.prototype.bind = JQLite.prototype.on;
3673 JQLite.prototype.unbind = JQLite.prototype.off;
3677 // Provider for private $$jqLite service
3678 function $$jqLiteProvider() {
3679 this.$get = function $$jqLite() {
3680 return extend(JQLite, {
3681 hasClass: function(node, classes) {
3682 if (node.attr) node = node[0];
3683 return jqLiteHasClass(node, classes);
3685 addClass: function(node, classes) {
3686 if (node.attr) node = node[0];
3687 return jqLiteAddClass(node, classes);
3689 removeClass: function(node, classes) {
3690 if (node.attr) node = node[0];
3691 return jqLiteRemoveClass(node, classes);
3698 * Computes a hash of an 'obj'.
3701 * number is number as string
3702 * object is either result of calling $$hashKey function on the object or uniquely generated id,
3703 * that is also assigned to the $$hashKey property of the object.
3706 * @returns {string} hash string such that the same input will have the same hash string.
3707 * The resulting string key is in 'type:hashKey' format.
3709 function hashKey(obj, nextUidFn) {
3710 var key = obj && obj.$$hashKey;
3713 if (typeof key === 'function') {
3714 key = obj.$$hashKey();
3719 var objType = typeof obj;
3720 if (objType == 'function' || (objType == 'object' && obj !== null)) {
3721 key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
3723 key = objType + ':' + obj;
3730 * HashMap which can use objects as keys
3732 function HashMap(array, isolatedUid) {
3735 this.nextUid = function() {
3739 forEach(array, this.put, this);
3741 HashMap.prototype = {
3743 * Store key value pair
3744 * @param key key to store can be any type
3745 * @param value value to store can be any type
3747 put: function(key, value) {
3748 this[hashKey(key, this.nextUid)] = value;
3753 * @returns {Object} the value for the key
3755 get: function(key) {
3756 return this[hashKey(key, this.nextUid)];
3760 * Remove the key/value pair
3763 remove: function(key) {
3764 var value = this[key = hashKey(key, this.nextUid)];
3770 var $$HashMapProvider = [function() {
3771 this.$get = [function() {
3779 * @name angular.injector
3783 * Creates an injector object that can be used for retrieving services as well as for
3784 * dependency injection (see {@link guide/di dependency injection}).
3786 * @param {Array.<string|Function>} modules A list of module functions or their aliases. See
3787 * {@link angular.module}. The `ng` module must be explicitly added.
3788 * @param {boolean=} [strictDi=false] Whether the injector should be in strict mode, which
3789 * disallows argument name annotation inference.
3790 * @returns {injector} Injector object. See {@link auto.$injector $injector}.
3795 * // create an injector
3796 * var $injector = angular.injector(['ng']);
3798 * // use the injector to kick off your application
3799 * // use the type inference to auto inject arguments, or use implicit injection
3800 * $injector.invoke(function($rootScope, $compile, $document) {
3801 * $compile($document)($rootScope);
3802 * $rootScope.$digest();
3806 * Sometimes you want to get access to the injector of a currently running Angular app
3807 * from outside Angular. Perhaps, you want to inject and compile some markup after the
3808 * application has been bootstrapped. You can do this using the extra `injector()` added
3809 * to JQuery/jqLite elements. See {@link angular.element}.
3811 * *This is fairly rare but could be the case if a third party library is injecting the
3814 * In the following example a new block of HTML containing a `ng-controller`
3815 * directive is added to the end of the document body by JQuery. We then compile and link
3816 * it into the current AngularJS scope.
3819 * var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>');
3820 * $(document.body).append($div);
3822 * angular.element(document).injector().invoke(function($compile) {
3823 * var scope = angular.element($div).scope();
3824 * $compile($div)(scope);
3835 * Implicit module which gets automatically added to each {@link auto.$injector $injector}.
3838 var FN_ARGS = /^[^\(]*\(\s*([^\)]*)\)/m;
3839 var FN_ARG_SPLIT = /,/;
3840 var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
3841 var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
3842 var $injectorMinErr = minErr('$injector');
3844 function anonFn(fn) {
3845 // For anonymous functions, showing at the very least the function signature can help in
3847 var fnText = fn.toString().replace(STRIP_COMMENTS, ''),
3848 args = fnText.match(FN_ARGS);
3850 return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')';
3855 function annotate(fn, strictDi, name) {
3861 if (typeof fn === 'function') {
3862 if (!($inject = fn.$inject)) {
3866 if (!isString(name) || !name) {
3867 name = fn.name || anonFn(fn);
3869 throw $injectorMinErr('strictdi',
3870 '{0} is not using explicit annotation and cannot be invoked in strict mode', name);
3872 fnText = fn.toString().replace(STRIP_COMMENTS, '');
3873 argDecl = fnText.match(FN_ARGS);
3874 forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
3875 arg.replace(FN_ARG, function(all, underscore, name) {
3880 fn.$inject = $inject;
3882 } else if (isArray(fn)) {
3883 last = fn.length - 1;
3884 assertArgFn(fn[last], 'fn');
3885 $inject = fn.slice(0, last);
3887 assertArgFn(fn, 'fn', true);
3892 ///////////////////////////////////////
3900 * `$injector` is used to retrieve object instances as defined by
3901 * {@link auto.$provide provider}, instantiate types, invoke methods,
3904 * The following always holds true:
3907 * var $injector = angular.injector();
3908 * expect($injector.get('$injector')).toBe($injector);
3909 * expect($injector.invoke(function($injector) {
3911 * })).toBe($injector);
3914 * # Injection Function Annotation
3916 * JavaScript does not have annotations, and annotations are needed for dependency injection. The
3917 * following are all valid ways of annotating function with injection arguments and are equivalent.
3920 * // inferred (only works if code not minified/obfuscated)
3921 * $injector.invoke(function(serviceA){});
3924 * function explicit(serviceA) {};
3925 * explicit.$inject = ['serviceA'];
3926 * $injector.invoke(explicit);
3929 * $injector.invoke(['serviceA', function(serviceA){}]);
3934 * In JavaScript calling `toString()` on a function returns the function definition. The definition
3935 * can then be parsed and the function arguments can be extracted. This method of discovering
3936 * annotations is disallowed when the injector is in strict mode.
3937 * *NOTE:* This does not work with minification, and obfuscation tools since these tools change the
3940 * ## `$inject` Annotation
3941 * By adding an `$inject` property onto a function the injection parameters can be specified.
3944 * As an array of injection names, where the last item in the array is the function to call.
3949 * @name $injector#get
3952 * Return an instance of the service.
3954 * @param {string} name The name of the instance to retrieve.
3955 * @param {string=} caller An optional string to provide the origin of the function call for error messages.
3956 * @return {*} The instance.
3961 * @name $injector#invoke
3964 * Invoke the method and supply the method arguments from the `$injector`.
3966 * @param {Function|Array.<string|Function>} fn The injectable function to invoke. Function parameters are
3967 * injected according to the {@link guide/di $inject Annotation} rules.
3968 * @param {Object=} self The `this` for the invoked method.
3969 * @param {Object=} locals Optional object. If preset then any argument names are read from this
3970 * object first, before the `$injector` is consulted.
3971 * @returns {*} the value returned by the invoked `fn` function.
3976 * @name $injector#has
3979 * Allows the user to query if the particular service exists.
3981 * @param {string} name Name of the service to query.
3982 * @returns {boolean} `true` if injector has given service.
3987 * @name $injector#instantiate
3989 * Create a new instance of JS type. The method takes a constructor function, invokes the new
3990 * operator, and supplies all of the arguments to the constructor function as specified by the
3991 * constructor annotation.
3993 * @param {Function} Type Annotated constructor function.
3994 * @param {Object=} locals Optional object. If preset then any argument names are read from this
3995 * object first, before the `$injector` is consulted.
3996 * @returns {Object} new instance of `Type`.
4001 * @name $injector#annotate
4004 * Returns an array of service names which the function is requesting for injection. This API is
4005 * used by the injector to determine which services need to be injected into the function when the
4006 * function is invoked. There are three ways in which the function can be annotated with the needed
4011 * The simplest form is to extract the dependencies from the arguments of the function. This is done
4012 * by converting the function into a string using `toString()` method and extracting the argument
4016 * function MyController($scope, $route) {
4021 * expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
4024 * You can disallow this method by using strict injection mode.
4026 * This method does not work with code minification / obfuscation. For this reason the following
4027 * annotation strategies are supported.
4029 * # The `$inject` property
4031 * If a function has an `$inject` property and its value is an array of strings, then the strings
4032 * represent names of services to be injected into the function.
4035 * var MyController = function(obfuscatedScope, obfuscatedRoute) {
4038 * // Define function dependencies
4039 * MyController['$inject'] = ['$scope', '$route'];
4042 * expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
4045 * # The array notation
4047 * It is often desirable to inline Injected functions and that's when setting the `$inject` property
4048 * is very inconvenient. In these situations using the array notation to specify the dependencies in
4049 * a way that survives minification is a better choice:
4052 * // We wish to write this (not minification / obfuscation safe)
4053 * injector.invoke(function($compile, $rootScope) {
4057 * // We are forced to write break inlining
4058 * var tmpFn = function(obfuscatedCompile, obfuscatedRootScope) {
4061 * tmpFn.$inject = ['$compile', '$rootScope'];
4062 * injector.invoke(tmpFn);
4064 * // To better support inline function the inline annotation is supported
4065 * injector.invoke(['$compile', '$rootScope', function(obfCompile, obfRootScope) {
4070 * expect(injector.annotate(
4071 * ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
4072 * ).toEqual(['$compile', '$rootScope']);
4075 * @param {Function|Array.<string|Function>} fn Function for which dependent service names need to
4076 * be retrieved as described above.
4078 * @param {boolean=} [strictDi=false] Disallow argument name annotation inference.
4080 * @returns {Array.<string>} The names of the services which the function requires.
4092 * The {@link auto.$provide $provide} service has a number of methods for registering components
4093 * with the {@link auto.$injector $injector}. Many of these functions are also exposed on
4094 * {@link angular.Module}.
4096 * An Angular **service** is a singleton object created by a **service factory**. These **service
4097 * factories** are functions which, in turn, are created by a **service provider**.
4098 * The **service providers** are constructor functions. When instantiated they must contain a
4099 * property called `$get`, which holds the **service factory** function.
4101 * When you request a service, the {@link auto.$injector $injector} is responsible for finding the
4102 * correct **service provider**, instantiating it and then calling its `$get` **service factory**
4103 * function to get the instance of the **service**.
4105 * Often services have no configuration options and there is no need to add methods to the service
4106 * provider. The provider will be no more than a constructor function with a `$get` property. For
4107 * these cases the {@link auto.$provide $provide} service has additional helper methods to register
4108 * services without specifying a provider.
4110 * * {@link auto.$provide#provider provider(provider)} - registers a **service provider** with the
4111 * {@link auto.$injector $injector}
4112 * * {@link auto.$provide#constant constant(obj)} - registers a value/object that can be accessed by
4113 * providers and services.
4114 * * {@link auto.$provide#value value(obj)} - registers a value/object that can only be accessed by
4115 * services, not providers.
4116 * * {@link auto.$provide#factory factory(fn)} - registers a service **factory function**, `fn`,
4117 * that will be wrapped in a **service provider** object, whose `$get` property will contain the
4118 * given factory function.
4119 * * {@link auto.$provide#service service(class)} - registers a **constructor function**, `class`
4120 * that will be wrapped in a **service provider** object, whose `$get` property will instantiate
4121 * a new object using the given constructor function.
4123 * See the individual methods for more information and examples.
4128 * @name $provide#provider
4131 * Register a **provider function** with the {@link auto.$injector $injector}. Provider functions
4132 * are constructor functions, whose instances are responsible for "providing" a factory for a
4135 * Service provider names start with the name of the service they provide followed by `Provider`.
4136 * For example, the {@link ng.$log $log} service has a provider called
4137 * {@link ng.$logProvider $logProvider}.
4139 * Service provider objects can have additional methods which allow configuration of the provider
4140 * and its service. Importantly, you can configure what kind of service is created by the `$get`
4141 * method, or how that service will act. For example, the {@link ng.$logProvider $logProvider} has a
4142 * method {@link ng.$logProvider#debugEnabled debugEnabled}
4143 * which lets you specify whether the {@link ng.$log $log} service will log debug messages to the
4146 * @param {string} name The name of the instance. NOTE: the provider will be available under `name +
4148 * @param {(Object|function())} provider If the provider is:
4150 * - `Object`: then it should have a `$get` method. The `$get` method will be invoked using
4151 * {@link auto.$injector#invoke $injector.invoke()} when an instance needs to be created.
4152 * - `Constructor`: a new instance of the provider will be created using
4153 * {@link auto.$injector#instantiate $injector.instantiate()}, then treated as `object`.
4155 * @returns {Object} registered provider instance
4159 * The following example shows how to create a simple event tracking service and register it using
4160 * {@link auto.$provide#provider $provide.provider()}.
4163 * // Define the eventTracker provider
4164 * function EventTrackerProvider() {
4165 * var trackingUrl = '/track';
4167 * // A provider method for configuring where the tracked events should been saved
4168 * this.setTrackingUrl = function(url) {
4169 * trackingUrl = url;
4172 * // The service factory function
4173 * this.$get = ['$http', function($http) {
4174 * var trackedEvents = {};
4176 * // Call this to track an event
4177 * event: function(event) {
4178 * var count = trackedEvents[event] || 0;
4180 * trackedEvents[event] = count;
4183 * // Call this to save the tracked events to the trackingUrl
4184 * save: function() {
4185 * $http.post(trackingUrl, trackedEvents);
4191 * describe('eventTracker', function() {
4194 * beforeEach(module(function($provide) {
4195 * // Register the eventTracker provider
4196 * $provide.provider('eventTracker', EventTrackerProvider);
4199 * beforeEach(module(function(eventTrackerProvider) {
4200 * // Configure eventTracker provider
4201 * eventTrackerProvider.setTrackingUrl('/custom-track');
4204 * it('tracks events', inject(function(eventTracker) {
4205 * expect(eventTracker.event('login')).toEqual(1);
4206 * expect(eventTracker.event('login')).toEqual(2);
4209 * it('saves to the tracking url', inject(function(eventTracker, $http) {
4210 * postSpy = spyOn($http, 'post');
4211 * eventTracker.event('login');
4212 * eventTracker.save();
4213 * expect(postSpy).toHaveBeenCalled();
4214 * expect(postSpy.mostRecentCall.args[0]).not.toEqual('/track');
4215 * expect(postSpy.mostRecentCall.args[0]).toEqual('/custom-track');
4216 * expect(postSpy.mostRecentCall.args[1]).toEqual({ 'login': 1 });
4224 * @name $provide#factory
4227 * Register a **service factory**, which will be called to return the service instance.
4228 * This is short for registering a service where its provider consists of only a `$get` property,
4229 * which is the given service factory function.
4230 * You should use {@link auto.$provide#factory $provide.factory(getFn)} if you do not need to
4231 * configure your service in a provider.
4233 * @param {string} name The name of the instance.
4234 * @param {Function|Array.<string|Function>} $getFn The injectable $getFn for the instance creation.
4235 * Internally this is a short hand for `$provide.provider(name, {$get: $getFn})`.
4236 * @returns {Object} registered provider instance
4239 * Here is an example of registering a service
4241 * $provide.factory('ping', ['$http', function($http) {
4242 * return function ping() {
4243 * return $http.send('/ping');
4247 * You would then inject and use this service like this:
4249 * someModule.controller('Ctrl', ['ping', function(ping) {
4258 * @name $provide#service
4261 * Register a **service constructor**, which will be invoked with `new` to create the service
4263 * This is short for registering a service where its provider's `$get` property is the service
4264 * constructor function that will be used to instantiate the service instance.
4266 * You should use {@link auto.$provide#service $provide.service(class)} if you define your service
4269 * @param {string} name The name of the instance.
4270 * @param {Function|Array.<string|Function>} constructor An injectable class (constructor function)
4271 * that will be instantiated.
4272 * @returns {Object} registered provider instance
4275 * Here is an example of registering a service using
4276 * {@link auto.$provide#service $provide.service(class)}.
4278 * var Ping = function($http) {
4279 * this.$http = $http;
4282 * Ping.$inject = ['$http'];
4284 * Ping.prototype.send = function() {
4285 * return this.$http.get('/ping');
4287 * $provide.service('ping', Ping);
4289 * You would then inject and use this service like this:
4291 * someModule.controller('Ctrl', ['ping', function(ping) {
4300 * @name $provide#value
4303 * Register a **value service** with the {@link auto.$injector $injector}, such as a string, a
4304 * number, an array, an object or a function. This is short for registering a service where its
4305 * provider's `$get` property is a factory function that takes no arguments and returns the **value
4308 * Value services are similar to constant services, except that they cannot be injected into a
4309 * module configuration function (see {@link angular.Module#config}) but they can be overridden by
4311 * {@link auto.$provide#decorator decorator}.
4313 * @param {string} name The name of the instance.
4314 * @param {*} value The value.
4315 * @returns {Object} registered provider instance
4318 * Here are some examples of creating value services.
4320 * $provide.value('ADMIN_USER', 'admin');
4322 * $provide.value('RoleLookup', { admin: 0, writer: 1, reader: 2 });
4324 * $provide.value('halfOf', function(value) {
4333 * @name $provide#constant
4336 * Register a **constant service**, such as a string, a number, an array, an object or a function,
4337 * with the {@link auto.$injector $injector}. Unlike {@link auto.$provide#value value} it can be
4338 * injected into a module configuration function (see {@link angular.Module#config}) and it cannot
4339 * be overridden by an Angular {@link auto.$provide#decorator decorator}.
4341 * @param {string} name The name of the constant.
4342 * @param {*} value The constant value.
4343 * @returns {Object} registered instance
4346 * Here a some examples of creating constants:
4348 * $provide.constant('SHARD_HEIGHT', 306);
4350 * $provide.constant('MY_COLOURS', ['red', 'blue', 'grey']);
4352 * $provide.constant('double', function(value) {
4361 * @name $provide#decorator
4364 * Register a **service decorator** with the {@link auto.$injector $injector}. A service decorator
4365 * intercepts the creation of a service, allowing it to override or modify the behaviour of the
4366 * service. The object returned by the decorator may be the original service, or a new service
4367 * object which replaces or wraps and delegates to the original service.
4369 * @param {string} name The name of the service to decorate.
4370 * @param {Function|Array.<string|Function>} decorator This function will be invoked when the service needs to be
4371 * instantiated and should return the decorated service instance. The function is called using
4372 * the {@link auto.$injector#invoke injector.invoke} method and is therefore fully injectable.
4373 * Local injection arguments:
4375 * * `$delegate` - The original service instance, which can be monkey patched, configured,
4376 * decorated or delegated to.
4379 * Here we decorate the {@link ng.$log $log} service to convert warnings to errors by intercepting
4380 * calls to {@link ng.$log#error $log.warn()}.
4382 * $provide.decorator('$log', ['$delegate', function($delegate) {
4383 * $delegate.warn = $delegate.error;
4390 function createInjector(modulesToLoad, strictDi) {
4391 strictDi = (strictDi === true);
4392 var INSTANTIATING = {},
4393 providerSuffix = 'Provider',
4395 loadedModules = new HashMap([], true),
4398 provider: supportObject(provider),
4399 factory: supportObject(factory),
4400 service: supportObject(service),
4401 value: supportObject(value),
4402 constant: supportObject(constant),
4403 decorator: decorator
4406 providerInjector = (providerCache.$injector =
4407 createInternalInjector(providerCache, function(serviceName, caller) {
4408 if (angular.isString(caller)) {
4411 throw $injectorMinErr('unpr', "Unknown provider: {0}", path.join(' <- '));
4414 instanceInjector = (instanceCache.$injector =
4415 createInternalInjector(instanceCache, function(serviceName, caller) {
4416 var provider = providerInjector.get(serviceName + providerSuffix, caller);
4417 return instanceInjector.invoke(provider.$get, provider, undefined, serviceName);
4421 forEach(loadModules(modulesToLoad), function(fn) { if (fn) instanceInjector.invoke(fn); });
4423 return instanceInjector;
4425 ////////////////////////////////////
4427 ////////////////////////////////////
4429 function supportObject(delegate) {
4430 return function(key, value) {
4431 if (isObject(key)) {
4432 forEach(key, reverseParams(delegate));
4434 return delegate(key, value);
4439 function provider(name, provider_) {
4440 assertNotHasOwnProperty(name, 'service');
4441 if (isFunction(provider_) || isArray(provider_)) {
4442 provider_ = providerInjector.instantiate(provider_);
4444 if (!provider_.$get) {
4445 throw $injectorMinErr('pget', "Provider '{0}' must define $get factory method.", name);
4447 return providerCache[name + providerSuffix] = provider_;
4450 function enforceReturnValue(name, factory) {
4451 return function enforcedReturnValue() {
4452 var result = instanceInjector.invoke(factory, this);
4453 if (isUndefined(result)) {
4454 throw $injectorMinErr('undef', "Provider '{0}' must return a value from $get factory method.", name);
4460 function factory(name, factoryFn, enforce) {
4461 return provider(name, {
4462 $get: enforce !== false ? enforceReturnValue(name, factoryFn) : factoryFn
4466 function service(name, constructor) {
4467 return factory(name, ['$injector', function($injector) {
4468 return $injector.instantiate(constructor);
4472 function value(name, val) { return factory(name, valueFn(val), false); }
4474 function constant(name, value) {
4475 assertNotHasOwnProperty(name, 'constant');
4476 providerCache[name] = value;
4477 instanceCache[name] = value;
4480 function decorator(serviceName, decorFn) {
4481 var origProvider = providerInjector.get(serviceName + providerSuffix),
4482 orig$get = origProvider.$get;
4484 origProvider.$get = function() {
4485 var origInstance = instanceInjector.invoke(orig$get, origProvider);
4486 return instanceInjector.invoke(decorFn, null, {$delegate: origInstance});
4490 ////////////////////////////////////
4492 ////////////////////////////////////
4493 function loadModules(modulesToLoad) {
4494 assertArg(isUndefined(modulesToLoad) || isArray(modulesToLoad), 'modulesToLoad', 'not an array');
4495 var runBlocks = [], moduleFn;
4496 forEach(modulesToLoad, function(module) {
4497 if (loadedModules.get(module)) return;
4498 loadedModules.put(module, true);
4500 function runInvokeQueue(queue) {
4502 for (i = 0, ii = queue.length; i < ii; i++) {
4503 var invokeArgs = queue[i],
4504 provider = providerInjector.get(invokeArgs[0]);
4506 provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
4511 if (isString(module)) {
4512 moduleFn = angularModule(module);
4513 runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
4514 runInvokeQueue(moduleFn._invokeQueue);
4515 runInvokeQueue(moduleFn._configBlocks);
4516 } else if (isFunction(module)) {
4517 runBlocks.push(providerInjector.invoke(module));
4518 } else if (isArray(module)) {
4519 runBlocks.push(providerInjector.invoke(module));
4521 assertArgFn(module, 'module');
4524 if (isArray(module)) {
4525 module = module[module.length - 1];
4527 if (e.message && e.stack && e.stack.indexOf(e.message) == -1) {
4528 // Safari & FF's stack traces don't contain error.message content
4529 // unlike those of Chrome and IE
4530 // So if stack doesn't contain message, we create a new string that contains both.
4531 // Since error.stack is read-only in Safari, I'm overriding e and not e.stack here.
4533 e = e.message + '\n' + e.stack;
4535 throw $injectorMinErr('modulerr', "Failed to instantiate module {0} due to:\n{1}",
4536 module, e.stack || e.message || e);
4542 ////////////////////////////////////
4543 // internal Injector
4544 ////////////////////////////////////
4546 function createInternalInjector(cache, factory) {
4548 function getService(serviceName, caller) {
4549 if (cache.hasOwnProperty(serviceName)) {
4550 if (cache[serviceName] === INSTANTIATING) {
4551 throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
4552 serviceName + ' <- ' + path.join(' <- '));
4554 return cache[serviceName];
4557 path.unshift(serviceName);
4558 cache[serviceName] = INSTANTIATING;
4559 return cache[serviceName] = factory(serviceName, caller);
4561 if (cache[serviceName] === INSTANTIATING) {
4562 delete cache[serviceName];
4571 function invoke(fn, self, locals, serviceName) {
4572 if (typeof locals === 'string') {
4573 serviceName = locals;
4578 $inject = createInjector.$$annotate(fn, strictDi, serviceName),
4582 for (i = 0, length = $inject.length; i < length; i++) {
4584 if (typeof key !== 'string') {
4585 throw $injectorMinErr('itkn',
4586 'Incorrect injection token! Expected service name as string, got {0}', key);
4589 locals && locals.hasOwnProperty(key)
4591 : getService(key, serviceName)
4598 // http://jsperf.com/angularjs-invoke-apply-vs-switch
4600 return fn.apply(self, args);
4603 function instantiate(Type, locals, serviceName) {
4604 // Check if Type is annotated and use just the given function at n-1 as parameter
4605 // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
4606 // Object creation: http://jsperf.com/create-constructor/2
4607 var instance = Object.create((isArray(Type) ? Type[Type.length - 1] : Type).prototype || null);
4608 var returnedValue = invoke(Type, instance, locals, serviceName);
4610 return isObject(returnedValue) || isFunction(returnedValue) ? returnedValue : instance;
4615 instantiate: instantiate,
4617 annotate: createInjector.$$annotate,
4618 has: function(name) {
4619 return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
4625 createInjector.$$annotate = annotate;
4629 * @name $anchorScrollProvider
4632 * Use `$anchorScrollProvider` to disable automatic scrolling whenever
4633 * {@link ng.$location#hash $location.hash()} changes.
4635 function $AnchorScrollProvider() {
4637 var autoScrollingEnabled = true;
4641 * @name $anchorScrollProvider#disableAutoScrolling
4644 * By default, {@link ng.$anchorScroll $anchorScroll()} will automatically detect changes to
4645 * {@link ng.$location#hash $location.hash()} and scroll to the element matching the new hash.<br />
4646 * Use this method to disable automatic scrolling.
4648 * If automatic scrolling is disabled, one must explicitly call
4649 * {@link ng.$anchorScroll $anchorScroll()} in order to scroll to the element related to the
4652 this.disableAutoScrolling = function() {
4653 autoScrollingEnabled = false;
4658 * @name $anchorScroll
4661 * @requires $location
4662 * @requires $rootScope
4665 * When called, it scrolls to the element related to the specified `hash` or (if omitted) to the
4666 * current value of {@link ng.$location#hash $location.hash()}, according to the rules specified
4668 * [HTML5 spec](http://www.w3.org/html/wg/drafts/html/master/browsers.html#the-indicated-part-of-the-document).
4670 * It also watches the {@link ng.$location#hash $location.hash()} and automatically scrolls to
4671 * match any anchor whenever it changes. This can be disabled by calling
4672 * {@link ng.$anchorScrollProvider#disableAutoScrolling $anchorScrollProvider.disableAutoScrolling()}.
4674 * Additionally, you can use its {@link ng.$anchorScroll#yOffset yOffset} property to specify a
4675 * vertical scroll-offset (either fixed or dynamic).
4677 * @param {string=} hash The hash specifying the element to scroll to. If omitted, the value of
4678 * {@link ng.$location#hash $location.hash()} will be used.
4680 * @property {(number|function|jqLite)} yOffset
4681 * If set, specifies a vertical scroll-offset. This is often useful when there are fixed
4682 * positioned elements at the top of the page, such as navbars, headers etc.
4684 * `yOffset` can be specified in various ways:
4685 * - **number**: A fixed number of pixels to be used as offset.<br /><br />
4686 * - **function**: A getter function called everytime `$anchorScroll()` is executed. Must return
4687 * a number representing the offset (in pixels).<br /><br />
4688 * - **jqLite**: A jqLite/jQuery element to be used for specifying the offset. The distance from
4689 * the top of the page to the element's bottom will be used as offset.<br />
4690 * **Note**: The element will be taken into account only as long as its `position` is set to
4691 * `fixed`. This option is useful, when dealing with responsive navbars/headers that adjust
4692 * their height and/or positioning according to the viewport's size.
4695 * <div class="alert alert-warning">
4696 * In order for `yOffset` to work properly, scrolling should take place on the document's root and
4697 * not some child element.
4701 <example module="anchorScrollExample">
4702 <file name="index.html">
4703 <div id="scrollArea" ng-controller="ScrollController">
4704 <a ng-click="gotoBottom()">Go to bottom</a>
4705 <a id="bottom"></a> You're at the bottom!
4708 <file name="script.js">
4709 angular.module('anchorScrollExample', [])
4710 .controller('ScrollController', ['$scope', '$location', '$anchorScroll',
4711 function ($scope, $location, $anchorScroll) {
4712 $scope.gotoBottom = function() {
4713 // set the location.hash to the id of
4714 // the element you wish to scroll to.
4715 $location.hash('bottom');
4717 // call $anchorScroll()
4722 <file name="style.css">
4736 * The example below illustrates the use of a vertical scroll-offset (specified as a fixed value).
4737 * See {@link ng.$anchorScroll#yOffset $anchorScroll.yOffset} for more details.
4740 <example module="anchorScrollOffsetExample">
4741 <file name="index.html">
4742 <div class="fixed-header" ng-controller="headerCtrl">
4743 <a href="" ng-click="gotoAnchor(x)" ng-repeat="x in [1,2,3,4,5]">
4747 <div id="anchor{{x}}" class="anchor" ng-repeat="x in [1,2,3,4,5]">
4751 <file name="script.js">
4752 angular.module('anchorScrollOffsetExample', [])
4753 .run(['$anchorScroll', function($anchorScroll) {
4754 $anchorScroll.yOffset = 50; // always scroll by 50 extra pixels
4756 .controller('headerCtrl', ['$anchorScroll', '$location', '$scope',
4757 function ($anchorScroll, $location, $scope) {
4758 $scope.gotoAnchor = function(x) {
4759 var newHash = 'anchor' + x;
4760 if ($location.hash() !== newHash) {
4761 // set the $location.hash to `newHash` and
4762 // $anchorScroll will automatically scroll to it
4763 $location.hash('anchor' + x);
4765 // call $anchorScroll() explicitly,
4766 // since $location.hash hasn't changed
4773 <file name="style.css">
4779 border: 2px dashed DarkOrchid;
4780 padding: 10px 10px 200px 10px;
4784 background-color: rgba(0, 0, 0, 0.2);
4787 top: 0; left: 0; right: 0;
4791 display: inline-block;
4797 this.$get = ['$window', '$location', '$rootScope', function($window, $location, $rootScope) {
4798 var document = $window.document;
4800 // Helper function to get first anchor from a NodeList
4801 // (using `Array#some()` instead of `angular#forEach()` since it's more performant
4802 // and working in all supported browsers.)
4803 function getFirstAnchor(list) {
4805 Array.prototype.some.call(list, function(element) {
4806 if (nodeName_(element) === 'a') {
4814 function getYOffset() {
4816 var offset = scroll.yOffset;
4818 if (isFunction(offset)) {
4820 } else if (isElement(offset)) {
4821 var elem = offset[0];
4822 var style = $window.getComputedStyle(elem);
4823 if (style.position !== 'fixed') {
4826 offset = elem.getBoundingClientRect().bottom;
4828 } else if (!isNumber(offset)) {
4835 function scrollTo(elem) {
4837 elem.scrollIntoView();
4839 var offset = getYOffset();
4842 // `offset` is the number of pixels we should scroll UP in order to align `elem` properly.
4843 // This is true ONLY if the call to `elem.scrollIntoView()` initially aligns `elem` at the
4844 // top of the viewport.
4846 // IF the number of pixels from the top of `elem` to the end of the page's content is less
4847 // than the height of the viewport, then `elem.scrollIntoView()` will align the `elem` some
4848 // way down the page.
4850 // This is often the case for elements near the bottom of the page.
4852 // In such cases we do not need to scroll the whole `offset` up, just the difference between
4853 // the top of the element and the offset, which is enough to align the top of `elem` at the
4854 // desired position.
4855 var elemTop = elem.getBoundingClientRect().top;
4856 $window.scrollBy(0, elemTop - offset);
4859 $window.scrollTo(0, 0);
4863 function scroll(hash) {
4864 hash = isString(hash) ? hash : $location.hash();
4867 // empty hash, scroll to the top of the page
4868 if (!hash) scrollTo(null);
4870 // element with given id
4871 else if ((elm = document.getElementById(hash))) scrollTo(elm);
4873 // first anchor with given name :-D
4874 else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) scrollTo(elm);
4876 // no element and hash == 'top', scroll to the top of the page
4877 else if (hash === 'top') scrollTo(null);
4880 // does not scroll when user clicks on anchor link that is currently on
4881 // (no url change, no $location.hash() change), browser native does scroll
4882 if (autoScrollingEnabled) {
4883 $rootScope.$watch(function autoScrollWatch() {return $location.hash();},
4884 function autoScrollWatchAction(newVal, oldVal) {
4885 // skip the initial scroll if $location.hash is empty
4886 if (newVal === oldVal && newVal === '') return;
4888 jqLiteDocumentLoaded(function() {
4889 $rootScope.$evalAsync(scroll);
4898 var $animateMinErr = minErr('$animate');
4899 var ELEMENT_NODE = 1;
4900 var NG_ANIMATE_CLASSNAME = 'ng-animate';
4902 function mergeClasses(a,b) {
4903 if (!a && !b) return '';
4906 if (isArray(a)) a = a.join(' ');
4907 if (isArray(b)) b = b.join(' ');
4911 function extractElementNode(element) {
4912 for (var i = 0; i < element.length; i++) {
4913 var elm = element[i];
4914 if (elm.nodeType === ELEMENT_NODE) {
4920 function splitClasses(classes) {
4921 if (isString(classes)) {
4922 classes = classes.split(' ');
4925 // Use createMap() to prevent class assumptions involving property names in
4927 var obj = createMap();
4928 forEach(classes, function(klass) {
4929 // sometimes the split leaves empty string values
4930 // incase extra spaces were applied to the options
4938 // if any other type of options value besides an Object value is
4939 // passed into the $animate.method() animation then this helper code
4940 // will be run which will ignore it. While this patch is not the
4941 // greatest solution to this, a lot of existing plugins depend on
4942 // $animate to either call the callback (< 1.2) or return a promise
4943 // that can be changed. This helper function ensures that the options
4944 // are wiped clean incase a callback function is provided.
4945 function prepareAnimateOptions(options) {
4946 return isObject(options)
4951 var $$CoreAnimateRunnerProvider = function() {
4952 this.$get = ['$q', '$$rAF', function($q, $$rAF) {
4953 function AnimateRunner() {}
4954 AnimateRunner.all = noop;
4955 AnimateRunner.chain = noop;
4956 AnimateRunner.prototype = {
4962 then: function(pass, fail) {
4963 return $q(function(resolve) {
4967 }).then(pass, fail);
4970 return AnimateRunner;
4974 // this is prefixed with Core since it conflicts with
4975 // the animateQueueProvider defined in ngAnimate/animateQueue.js
4976 var $$CoreAnimateQueueProvider = function() {
4977 var postDigestQueue = new HashMap();
4978 var postDigestElements = [];
4980 this.$get = ['$$AnimateRunner', '$rootScope',
4981 function($$AnimateRunner, $rootScope) {
4988 push: function(element, event, options, domOperation) {
4989 domOperation && domOperation();
4991 options = options || {};
4992 options.from && element.css(options.from);
4993 options.to && element.css(options.to);
4995 if (options.addClass || options.removeClass) {
4996 addRemoveClassesPostDigest(element, options.addClass, options.removeClass);
4999 return new $$AnimateRunner(); // jshint ignore:line
5004 function updateData(data, classes, value) {
5005 var changed = false;
5007 classes = isString(classes) ? classes.split(' ') :
5008 isArray(classes) ? classes : [];
5009 forEach(classes, function(className) {
5012 data[className] = value;
5019 function handleCSSClassChanges() {
5020 forEach(postDigestElements, function(element) {
5021 var data = postDigestQueue.get(element);
5023 var existing = splitClasses(element.attr('class'));
5026 forEach(data, function(status, className) {
5027 var hasClass = !!existing[className];
5028 if (status !== hasClass) {
5030 toAdd += (toAdd.length ? ' ' : '') + className;
5032 toRemove += (toRemove.length ? ' ' : '') + className;
5037 forEach(element, function(elm) {
5038 toAdd && jqLiteAddClass(elm, toAdd);
5039 toRemove && jqLiteRemoveClass(elm, toRemove);
5041 postDigestQueue.remove(element);
5044 postDigestElements.length = 0;
5048 function addRemoveClassesPostDigest(element, add, remove) {
5049 var data = postDigestQueue.get(element) || {};
5051 var classesAdded = updateData(data, add, true);
5052 var classesRemoved = updateData(data, remove, false);
5054 if (classesAdded || classesRemoved) {
5056 postDigestQueue.put(element, data);
5057 postDigestElements.push(element);
5059 if (postDigestElements.length === 1) {
5060 $rootScope.$$postDigest(handleCSSClassChanges);
5069 * @name $animateProvider
5072 * Default implementation of $animate that doesn't perform any animations, instead just
5073 * synchronously performs DOM updates and resolves the returned runner promise.
5075 * In order to enable animations the `ngAnimate` module has to be loaded.
5077 * To see the functional implementation check out `src/ngAnimate/animate.js`.
5079 var $AnimateProvider = ['$provide', function($provide) {
5080 var provider = this;
5082 this.$$registeredAnimations = Object.create(null);
5086 * @name $animateProvider#register
5089 * Registers a new injectable animation factory function. The factory function produces the
5090 * animation object which contains callback functions for each event that is expected to be
5093 * * `eventFn`: `function(element, ... , doneFunction, options)`
5094 * The element to animate, the `doneFunction` and the options fed into the animation. Depending
5095 * on the type of animation additional arguments will be injected into the animation function. The
5096 * list below explains the function signatures for the different animation methods:
5098 * - setClass: function(element, addedClasses, removedClasses, doneFunction, options)
5099 * - addClass: function(element, addedClasses, doneFunction, options)
5100 * - removeClass: function(element, removedClasses, doneFunction, options)
5101 * - enter, leave, move: function(element, doneFunction, options)
5102 * - animate: function(element, fromStyles, toStyles, doneFunction, options)
5104 * Make sure to trigger the `doneFunction` once the animation is fully complete.
5108 * //enter, leave, move signature
5109 * eventFn : function(element, done, options) {
5110 * //code to run the animation
5111 * //once complete, then run done()
5112 * return function endFunction(wasCancelled) {
5113 * //code to cancel the animation
5119 * @param {string} name The name of the animation (this is what the class-based CSS value will be compared to).
5120 * @param {Function} factory The factory function that will be executed to return the animation
5123 this.register = function(name, factory) {
5124 if (name && name.charAt(0) !== '.') {
5125 throw $animateMinErr('notcsel', "Expecting class selector starting with '.' got '{0}'.", name);
5128 var key = name + '-animation';
5129 provider.$$registeredAnimations[name.substr(1)] = key;
5130 $provide.factory(key, factory);
5135 * @name $animateProvider#classNameFilter
5138 * Sets and/or returns the CSS class regular expression that is checked when performing
5139 * an animation. Upon bootstrap the classNameFilter value is not set at all and will
5140 * therefore enable $animate to attempt to perform an animation on any element that is triggered.
5141 * When setting the `classNameFilter` value, animations will only be performed on elements
5142 * that successfully match the filter expression. This in turn can boost performance
5143 * for low-powered devices as well as applications containing a lot of structural operations.
5144 * @param {RegExp=} expression The className expression which will be checked against all animations
5145 * @return {RegExp} The current CSS className expression value. If null then there is no expression value
5147 this.classNameFilter = function(expression) {
5148 if (arguments.length === 1) {
5149 this.$$classNameFilter = (expression instanceof RegExp) ? expression : null;
5150 if (this.$$classNameFilter) {
5151 var reservedRegex = new RegExp("(\\s+|\\/)" + NG_ANIMATE_CLASSNAME + "(\\s+|\\/)");
5152 if (reservedRegex.test(this.$$classNameFilter.toString())) {
5153 throw $animateMinErr('nongcls','$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
5158 return this.$$classNameFilter;
5161 this.$get = ['$$animateQueue', function($$animateQueue) {
5162 function domInsert(element, parentElement, afterElement) {
5163 // if for some reason the previous element was removed
5164 // from the dom sometime before this code runs then let's
5165 // just stick to using the parent element as the anchor
5167 var afterNode = extractElementNode(afterElement);
5168 if (afterNode && !afterNode.parentNode && !afterNode.previousElementSibling) {
5169 afterElement = null;
5172 afterElement ? afterElement.after(element) : parentElement.prepend(element);
5178 * @description The $animate service exposes a series of DOM utility methods that provide support
5179 * for animation hooks. The default behavior is the application of DOM operations, however,
5180 * when an animation is detected (and animations are enabled), $animate will do the heavy lifting
5181 * to ensure that animation runs with the triggered DOM operation.
5183 * By default $animate doesn't trigger any animations. This is because the `ngAnimate` module isn't
5184 * included and only when it is active then the animation hooks that `$animate` triggers will be
5185 * functional. Once active then all structural `ng-` directives will trigger animations as they perform
5186 * their DOM-related operations (enter, leave and move). Other directives such as `ngClass`,
5187 * `ngShow`, `ngHide` and `ngMessages` also provide support for animations.
5189 * It is recommended that the`$animate` service is always used when executing DOM-related procedures within directives.
5191 * To learn more about enabling animation support, click here to visit the
5192 * {@link ngAnimate ngAnimate module page}.
5195 // we don't call it directly since non-existant arguments may
5196 // be interpreted as null within the sub enabled function
5203 * @description Sets up an event listener to fire whenever the animation event (enter, leave, move, etc...)
5204 * has fired on the given element or among any of its children. Once the listener is fired, the provided callback
5205 * is fired with the following params:
5208 * $animate.on('enter', container,
5209 * function callback(element, phase) {
5210 * // cool we detected an enter animation within the container
5215 * @param {string} event the animation event that will be captured (e.g. enter, leave, move, addClass, removeClass, etc...)
5216 * @param {DOMElement} container the container element that will capture each of the animation events that are fired on itself
5217 * as well as among its children
5218 * @param {Function} callback the callback function that will be fired when the listener is triggered
5220 * The arguments present in the callback function are:
5221 * * `element` - The captured DOM element that the animation was fired on.
5222 * * `phase` - The phase of the animation. The two possible phases are **start** (when the animation starts) and **close** (when it ends).
5224 on: $$animateQueue.on,
5229 * @name $animate#off
5231 * @description Deregisters an event listener based on the event which has been associated with the provided element. This method
5232 * can be used in three different ways depending on the arguments:
5235 * // remove all the animation event listeners listening for `enter`
5236 * $animate.off('enter');
5238 * // remove all the animation event listeners listening for `enter` on the given element and its children
5239 * $animate.off('enter', container);
5241 * // remove the event listener function provided by `listenerFn` that is set
5242 * // to listen for `enter` on the given `element` as well as its children
5243 * $animate.off('enter', container, callback);
5246 * @param {string} event the animation event (e.g. enter, leave, move, addClass, removeClass, etc...)
5247 * @param {DOMElement=} container the container element the event listener was placed on
5248 * @param {Function=} callback the callback function that was registered as the listener
5250 off: $$animateQueue.off,
5254 * @name $animate#pin
5256 * @description Associates the provided element with a host parent element to allow the element to be animated even if it exists
5257 * outside of the DOM structure of the Angular application. By doing so, any animation triggered via `$animate` can be issued on the
5258 * element despite being outside the realm of the application or within another application. Say for example if the application
5259 * was bootstrapped on an element that is somewhere inside of the `<body>` tag, but we wanted to allow for an element to be situated
5260 * as a direct child of `document.body`, then this can be achieved by pinning the element via `$animate.pin(element)`. Keep in mind
5261 * that calling `$animate.pin(element, parentElement)` will not actually insert into the DOM anywhere; it will just create the association.
5263 * Note that this feature is only active when the `ngAnimate` module is used.
5265 * @param {DOMElement} element the external element that will be pinned
5266 * @param {DOMElement} parentElement the host parent element that will be associated with the external element
5268 pin: $$animateQueue.pin,
5273 * @name $animate#enabled
5275 * @description Used to get and set whether animations are enabled or not on the entire application or on an element and its children. This
5276 * function can be called in four ways:
5279 * // returns true or false
5280 * $animate.enabled();
5282 * // changes the enabled state for all animations
5283 * $animate.enabled(false);
5284 * $animate.enabled(true);
5286 * // returns true or false if animations are enabled for an element
5287 * $animate.enabled(element);
5289 * // changes the enabled state for an element and its children
5290 * $animate.enabled(element, true);
5291 * $animate.enabled(element, false);
5294 * @param {DOMElement=} element the element that will be considered for checking/setting the enabled state
5295 * @param {boolean=} enabled whether or not the animations will be enabled for the element
5297 * @return {boolean} whether or not animations are enabled
5299 enabled: $$animateQueue.enabled,
5303 * @name $animate#cancel
5305 * @description Cancels the provided animation.
5307 * @param {Promise} animationPromise The animation promise that is returned when an animation is started.
5309 cancel: function(runner) {
5310 runner.end && runner.end();
5316 * @name $animate#enter
5318 * @description Inserts the element into the DOM either after the `after` element (if provided) or
5319 * as the first child within the `parent` element and then triggers an animation.
5320 * A promise is returned that will be resolved during the next digest once the animation
5323 * @param {DOMElement} element the element which will be inserted into the DOM
5324 * @param {DOMElement} parent the parent element which will append the element as
5325 * a child (so long as the after element is not present)
5326 * @param {DOMElement=} after the sibling element after which the element will be appended
5327 * @param {object=} options an optional collection of options/styles that will be applied to the element
5329 * @return {Promise} the animation callback promise
5331 enter: function(element, parent, after, options) {
5332 parent = parent && jqLite(parent);
5333 after = after && jqLite(after);
5334 parent = parent || after.parent();
5335 domInsert(element, parent, after);
5336 return $$animateQueue.push(element, 'enter', prepareAnimateOptions(options));
5342 * @name $animate#move
5344 * @description Inserts (moves) the element into its new position in the DOM either after
5345 * the `after` element (if provided) or as the first child within the `parent` element
5346 * and then triggers an animation. A promise is returned that will be resolved
5347 * during the next digest once the animation has completed.
5349 * @param {DOMElement} element the element which will be moved into the new DOM position
5350 * @param {DOMElement} parent the parent element which will append the element as
5351 * a child (so long as the after element is not present)
5352 * @param {DOMElement=} after the sibling element after which the element will be appended
5353 * @param {object=} options an optional collection of options/styles that will be applied to the element
5355 * @return {Promise} the animation callback promise
5357 move: function(element, parent, after, options) {
5358 parent = parent && jqLite(parent);
5359 after = after && jqLite(after);
5360 parent = parent || after.parent();
5361 domInsert(element, parent, after);
5362 return $$animateQueue.push(element, 'move', prepareAnimateOptions(options));
5367 * @name $animate#leave
5369 * @description Triggers an animation and then removes the element from the DOM.
5370 * When the function is called a promise is returned that will be resolved during the next
5371 * digest once the animation has completed.
5373 * @param {DOMElement} element the element which will be removed from the DOM
5374 * @param {object=} options an optional collection of options/styles that will be applied to the element
5376 * @return {Promise} the animation callback promise
5378 leave: function(element, options) {
5379 return $$animateQueue.push(element, 'leave', prepareAnimateOptions(options), function() {
5386 * @name $animate#addClass
5389 * @description Triggers an addClass animation surrounding the addition of the provided CSS class(es). Upon
5390 * execution, the addClass operation will only be handled after the next digest and it will not trigger an
5391 * animation if element already contains the CSS class or if the class is removed at a later step.
5392 * Note that class-based animations are treated differently compared to structural animations
5393 * (like enter, move and leave) since the CSS classes may be added/removed at different points
5394 * depending if CSS or JavaScript animations are used.
5396 * @param {DOMElement} element the element which the CSS classes will be applied to
5397 * @param {string} className the CSS class(es) that will be added (multiple classes are separated via spaces)
5398 * @param {object=} options an optional collection of options/styles that will be applied to the element
5400 * @return {Promise} the animation callback promise
5402 addClass: function(element, className, options) {
5403 options = prepareAnimateOptions(options);
5404 options.addClass = mergeClasses(options.addclass, className);
5405 return $$animateQueue.push(element, 'addClass', options);
5410 * @name $animate#removeClass
5413 * @description Triggers a removeClass animation surrounding the removal of the provided CSS class(es). Upon
5414 * execution, the removeClass operation will only be handled after the next digest and it will not trigger an
5415 * animation if element does not contain the CSS class or if the class is added at a later step.
5416 * Note that class-based animations are treated differently compared to structural animations
5417 * (like enter, move and leave) since the CSS classes may be added/removed at different points
5418 * depending if CSS or JavaScript animations are used.
5420 * @param {DOMElement} element the element which the CSS classes will be applied to
5421 * @param {string} className the CSS class(es) that will be removed (multiple classes are separated via spaces)
5422 * @param {object=} options an optional collection of options/styles that will be applied to the element
5424 * @return {Promise} the animation callback promise
5426 removeClass: function(element, className, options) {
5427 options = prepareAnimateOptions(options);
5428 options.removeClass = mergeClasses(options.removeClass, className);
5429 return $$animateQueue.push(element, 'removeClass', options);
5434 * @name $animate#setClass
5437 * @description Performs both the addition and removal of a CSS classes on an element and (during the process)
5438 * triggers an animation surrounding the class addition/removal. Much like `$animate.addClass` and
5439 * `$animate.removeClass`, `setClass` will only evaluate the classes being added/removed once a digest has
5440 * passed. Note that class-based animations are treated differently compared to structural animations
5441 * (like enter, move and leave) since the CSS classes may be added/removed at different points
5442 * depending if CSS or JavaScript animations are used.
5444 * @param {DOMElement} element the element which the CSS classes will be applied to
5445 * @param {string} add the CSS class(es) that will be added (multiple classes are separated via spaces)
5446 * @param {string} remove the CSS class(es) that will be removed (multiple classes are separated via spaces)
5447 * @param {object=} options an optional collection of options/styles that will be applied to the element
5449 * @return {Promise} the animation callback promise
5451 setClass: function(element, add, remove, options) {
5452 options = prepareAnimateOptions(options);
5453 options.addClass = mergeClasses(options.addClass, add);
5454 options.removeClass = mergeClasses(options.removeClass, remove);
5455 return $$animateQueue.push(element, 'setClass', options);
5460 * @name $animate#animate
5463 * @description Performs an inline animation on the element which applies the provided to and from CSS styles to the element.
5464 * If any detected CSS transition, keyframe or JavaScript matches the provided className value then the animation will take
5465 * on the provided styles. For example, if a transition animation is set for the given className then the provided from and
5466 * to styles will be applied alongside the given transition. If a JavaScript animation is detected then the provided styles
5467 * will be given in as function paramters into the `animate` method (or as apart of the `options` parameter).
5469 * @param {DOMElement} element the element which the CSS styles will be applied to
5470 * @param {object} from the from (starting) CSS styles that will be applied to the element and across the animation.
5471 * @param {object} to the to (destination) CSS styles that will be applied to the element and across the animation.
5472 * @param {string=} className an optional CSS class that will be applied to the element for the duration of the animation. If
5473 * this value is left as empty then a CSS class of `ng-inline-animate` will be applied to the element.
5474 * (Note that if no animation is detected then this value will not be appplied to the element.)
5475 * @param {object=} options an optional collection of options/styles that will be applied to the element
5477 * @return {Promise} the animation callback promise
5479 animate: function(element, from, to, className, options) {
5480 options = prepareAnimateOptions(options);
5481 options.from = options.from ? extend(options.from, from) : from;
5482 options.to = options.to ? extend(options.to, to) : to;
5484 className = className || 'ng-inline-animate';
5485 options.tempClasses = mergeClasses(options.tempClasses, className);
5486 return $$animateQueue.push(element, 'animate', options);
5498 * This is the core version of `$animateCss`. By default, only when the `ngAnimate` is included,
5499 * then the `$animateCss` service will actually perform animations.
5501 * Click here {@link ngAnimate.$animateCss to read the documentation for $animateCss}.
5503 var $CoreAnimateCssProvider = function() {
5504 this.$get = ['$$rAF', '$q', function($$rAF, $q) {
5506 var RAFPromise = function() {};
5507 RAFPromise.prototype = {
5508 done: function(cancel) {
5509 this.defer && this.defer[cancel === true ? 'reject' : 'resolve']();
5514 cancel: function() {
5517 getPromise: function() {
5519 this.defer = $q.defer();
5521 return this.defer.promise;
5523 then: function(f1,f2) {
5524 return this.getPromise().then(f1,f2);
5526 'catch': function(f1) {
5527 return this.getPromise()['catch'](f1);
5529 'finally': function(f1) {
5530 return this.getPromise()['finally'](f1);
5534 return function(element, options) {
5535 // there is no point in applying the styles since
5536 // there is no animation that goes on at all in
5537 // this version of $animateCss.
5538 if (options.cleanupStyles) {
5539 options.from = options.to = null;
5543 element.css(options.from);
5544 options.from = null;
5547 var closed, runner = new RAFPromise();
5565 if (options.addClass) {
5566 element.addClass(options.addClass);
5567 options.addClass = null;
5569 if (options.removeClass) {
5570 element.removeClass(options.removeClass);
5571 options.removeClass = null;
5574 element.css(options.to);
5582 /* global stripHash: true */
5585 * ! This is a private undocumented service !
5590 * This object has two goals:
5592 * - hide all the global state in the browser caused by the window object
5593 * - abstract away all the browser specific features and inconsistencies
5595 * For tests we provide {@link ngMock.$browser mock implementation} of the `$browser`
5596 * service, which can be used for convenient testing of the application without the interaction with
5597 * the real browser apis.
5600 * @param {object} window The global window object.
5601 * @param {object} document jQuery wrapped document.
5602 * @param {object} $log window.console or an object with the same interface.
5603 * @param {object} $sniffer $sniffer service
5605 function Browser(window, document, $log, $sniffer) {
5607 rawDocument = document[0],
5608 location = window.location,
5609 history = window.history,
5610 setTimeout = window.setTimeout,
5611 clearTimeout = window.clearTimeout,
5612 pendingDeferIds = {};
5614 self.isMock = false;
5616 var outstandingRequestCount = 0;
5617 var outstandingRequestCallbacks = [];
5619 // TODO(vojta): remove this temporary api
5620 self.$$completeOutstandingRequest = completeOutstandingRequest;
5621 self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; };
5624 * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks`
5625 * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed.
5627 function completeOutstandingRequest(fn) {
5629 fn.apply(null, sliceArgs(arguments, 1));
5631 outstandingRequestCount--;
5632 if (outstandingRequestCount === 0) {
5633 while (outstandingRequestCallbacks.length) {
5635 outstandingRequestCallbacks.pop()();
5644 function getHash(url) {
5645 var index = url.indexOf('#');
5646 return index === -1 ? '' : url.substr(index);
5651 * Note: this method is used only by scenario runner
5652 * TODO(vojta): prefix this method with $$ ?
5653 * @param {function()} callback Function that will be called when no outstanding request
5655 self.notifyWhenNoOutstandingRequests = function(callback) {
5656 if (outstandingRequestCount === 0) {
5659 outstandingRequestCallbacks.push(callback);
5663 //////////////////////////////////////////////////////////////
5665 //////////////////////////////////////////////////////////////
5667 var cachedState, lastHistoryState,
5668 lastBrowserUrl = location.href,
5669 baseElement = document.find('base'),
5670 pendingLocation = null;
5673 lastHistoryState = cachedState;
5676 * @name $browser#url
5680 * Without any argument, this method just returns current value of location.href.
5683 * With at least one argument, this method sets url to new value.
5684 * If html5 history api supported, pushState/replaceState is used, otherwise
5685 * location.href/location.replace is used.
5686 * Returns its own instance to allow chaining
5688 * NOTE: this api is intended for use only by the $location service. Please use the
5689 * {@link ng.$location $location service} to change url.
5691 * @param {string} url New url (when used as setter)
5692 * @param {boolean=} replace Should new url replace current history record?
5693 * @param {object=} state object to use with pushState/replaceState
5695 self.url = function(url, replace, state) {
5696 // In modern browsers `history.state` is `null` by default; treating it separately
5697 // from `undefined` would cause `$browser.url('/foo')` to change `history.state`
5698 // to undefined via `pushState`. Instead, let's change `undefined` to `null` here.
5699 if (isUndefined(state)) {
5703 // Android Browser BFCache causes location, history reference to become stale.
5704 if (location !== window.location) location = window.location;
5705 if (history !== window.history) history = window.history;
5709 var sameState = lastHistoryState === state;
5711 // Don't change anything if previous and current URLs and states match. This also prevents
5712 // IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode.
5713 // See https://github.com/angular/angular.js/commit/ffb2701
5714 if (lastBrowserUrl === url && (!$sniffer.history || sameState)) {
5717 var sameBase = lastBrowserUrl && stripHash(lastBrowserUrl) === stripHash(url);
5718 lastBrowserUrl = url;
5719 lastHistoryState = state;
5720 // Don't use history API if only the hash changed
5721 // due to a bug in IE10/IE11 which leads
5722 // to not firing a `hashchange` nor `popstate` event
5723 // in some cases (see #9143).
5724 if ($sniffer.history && (!sameBase || !sameState)) {
5725 history[replace ? 'replaceState' : 'pushState'](state, '', url);
5727 // Do the assignment again so that those two variables are referentially identical.
5728 lastHistoryState = cachedState;
5730 if (!sameBase || pendingLocation) {
5731 pendingLocation = url;
5734 location.replace(url);
5735 } else if (!sameBase) {
5736 location.href = url;
5738 location.hash = getHash(url);
5740 if (location.href !== url) {
5741 pendingLocation = url;
5747 // - pendingLocation is needed as browsers don't allow to read out
5748 // the new location.href if a reload happened or if there is a bug like in iOS 9 (see
5749 // https://openradar.appspot.com/22186109).
5750 // - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
5751 return pendingLocation || location.href.replace(/%27/g,"'");
5756 * @name $browser#state
5759 * This method is a getter.
5761 * Return history.state or null if history.state is undefined.
5763 * @returns {object} state
5765 self.state = function() {
5769 var urlChangeListeners = [],
5770 urlChangeInit = false;
5772 function cacheStateAndFireUrlChange() {
5773 pendingLocation = null;
5778 function getCurrentState() {
5780 return history.state;
5782 // MSIE can reportedly throw when there is no state (UNCONFIRMED).
5786 // This variable should be used *only* inside the cacheState function.
5787 var lastCachedState = null;
5788 function cacheState() {
5789 // This should be the only place in $browser where `history.state` is read.
5790 cachedState = getCurrentState();
5791 cachedState = isUndefined(cachedState) ? null : cachedState;
5793 // Prevent callbacks fo fire twice if both hashchange & popstate were fired.
5794 if (equals(cachedState, lastCachedState)) {
5795 cachedState = lastCachedState;
5797 lastCachedState = cachedState;
5800 function fireUrlChange() {
5801 if (lastBrowserUrl === self.url() && lastHistoryState === cachedState) {
5805 lastBrowserUrl = self.url();
5806 lastHistoryState = cachedState;
5807 forEach(urlChangeListeners, function(listener) {
5808 listener(self.url(), cachedState);
5813 * @name $browser#onUrlChange
5816 * Register callback function that will be called, when url changes.
5818 * It's only called when the url is changed from outside of angular:
5819 * - user types different url into address bar
5820 * - user clicks on history (forward/back) button
5821 * - user clicks on a link
5823 * It's not called when url is changed by $browser.url() method
5825 * The listener gets called with new url as parameter.
5827 * NOTE: this api is intended for use only by the $location service. Please use the
5828 * {@link ng.$location $location service} to monitor url changes in angular apps.
5830 * @param {function(string)} listener Listener function to be called when url changes.
5831 * @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous.
5833 self.onUrlChange = function(callback) {
5834 // TODO(vojta): refactor to use node's syntax for events
5835 if (!urlChangeInit) {
5836 // We listen on both (hashchange/popstate) when available, as some browsers (e.g. Opera)
5837 // don't fire popstate when user change the address bar and don't fire hashchange when url
5838 // changed by push/replaceState
5840 // html5 history api - popstate event
5841 if ($sniffer.history) jqLite(window).on('popstate', cacheStateAndFireUrlChange);
5843 jqLite(window).on('hashchange', cacheStateAndFireUrlChange);
5845 urlChangeInit = true;
5848 urlChangeListeners.push(callback);
5854 * Remove popstate and hashchange handler from window.
5856 * NOTE: this api is intended for use only by $rootScope.
5858 self.$$applicationDestroyed = function() {
5859 jqLite(window).off('hashchange popstate', cacheStateAndFireUrlChange);
5863 * Checks whether the url has changed outside of Angular.
5864 * Needs to be exported to be able to check for changes that have been done in sync,
5865 * as hashchange/popstate events fire in async.
5867 self.$$checkUrlChange = fireUrlChange;
5869 //////////////////////////////////////////////////////////////
5871 //////////////////////////////////////////////////////////////
5874 * @name $browser#baseHref
5877 * Returns current <base href>
5878 * (always relative - without domain)
5880 * @returns {string} The current base href
5882 self.baseHref = function() {
5883 var href = baseElement.attr('href');
5884 return href ? href.replace(/^(https?\:)?\/\/[^\/]*/, '') : '';
5888 * @name $browser#defer
5889 * @param {function()} fn A function, who's execution should be deferred.
5890 * @param {number=} [delay=0] of milliseconds to defer the function execution.
5891 * @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`.
5894 * Executes a fn asynchronously via `setTimeout(fn, delay)`.
5896 * Unlike when calling `setTimeout` directly, in test this function is mocked and instead of using
5897 * `setTimeout` in tests, the fns are queued in an array, which can be programmatically flushed
5898 * via `$browser.defer.flush()`.
5901 self.defer = function(fn, delay) {
5903 outstandingRequestCount++;
5904 timeoutId = setTimeout(function() {
5905 delete pendingDeferIds[timeoutId];
5906 completeOutstandingRequest(fn);
5908 pendingDeferIds[timeoutId] = true;
5914 * @name $browser#defer.cancel
5917 * Cancels a deferred task identified with `deferId`.
5919 * @param {*} deferId Token returned by the `$browser.defer` function.
5920 * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
5923 self.defer.cancel = function(deferId) {
5924 if (pendingDeferIds[deferId]) {
5925 delete pendingDeferIds[deferId];
5926 clearTimeout(deferId);
5927 completeOutstandingRequest(noop);
5935 function $BrowserProvider() {
5936 this.$get = ['$window', '$log', '$sniffer', '$document',
5937 function($window, $log, $sniffer, $document) {
5938 return new Browser($window, $document, $log, $sniffer);
5944 * @name $cacheFactory
5947 * Factory that constructs {@link $cacheFactory.Cache Cache} objects and gives access to
5952 * var cache = $cacheFactory('cacheId');
5953 * expect($cacheFactory.get('cacheId')).toBe(cache);
5954 * expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
5956 * cache.put("key", "value");
5957 * cache.put("another key", "another value");
5959 * // We've specified no options on creation
5960 * expect(cache.info()).toEqual({id: 'cacheId', size: 2});
5965 * @param {string} cacheId Name or id of the newly created cache.
5966 * @param {object=} options Options object that specifies the cache behavior. Properties:
5968 * - `{number=}` `capacity` — turns the cache into LRU cache.
5970 * @returns {object} Newly created cache object with the following set of methods:
5972 * - `{object}` `info()` — Returns id, size, and options of cache.
5973 * - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns
5975 * - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss.
5976 * - `{void}` `remove({string} key)` — Removes a key-value pair from the cache.
5977 * - `{void}` `removeAll()` — Removes all cached values.
5978 * - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
5981 <example module="cacheExampleApp">
5982 <file name="index.html">
5983 <div ng-controller="CacheController">
5984 <input ng-model="newCacheKey" placeholder="Key">
5985 <input ng-model="newCacheValue" placeholder="Value">
5986 <button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
5988 <p ng-if="keys.length">Cached Values</p>
5989 <div ng-repeat="key in keys">
5990 <span ng-bind="key"></span>
5992 <b ng-bind="cache.get(key)"></b>
5996 <div ng-repeat="(key, value) in cache.info()">
5997 <span ng-bind="key"></span>
5999 <b ng-bind="value"></b>
6003 <file name="script.js">
6004 angular.module('cacheExampleApp', []).
6005 controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
6007 $scope.cache = $cacheFactory('cacheId');
6008 $scope.put = function(key, value) {
6009 if (angular.isUndefined($scope.cache.get(key))) {
6010 $scope.keys.push(key);
6012 $scope.cache.put(key, angular.isUndefined(value) ? null : value);
6016 <file name="style.css">
6023 function $CacheFactoryProvider() {
6025 this.$get = function() {
6028 function cacheFactory(cacheId, options) {
6029 if (cacheId in caches) {
6030 throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
6034 stats = extend({}, options, {id: cacheId}),
6036 capacity = (options && options.capacity) || Number.MAX_VALUE,
6037 lruHash = createMap(),
6043 * @name $cacheFactory.Cache
6046 * A cache object used to store and retrieve data, primarily used by
6047 * {@link $http $http} and the {@link ng.directive:script script} directive to cache
6048 * templates and other data.
6051 * angular.module('superCache')
6052 * .factory('superCache', ['$cacheFactory', function($cacheFactory) {
6053 * return $cacheFactory('super-cache');
6060 * it('should behave like a cache', inject(function(superCache) {
6061 * superCache.put('key', 'value');
6062 * superCache.put('another key', 'another value');
6064 * expect(superCache.info()).toEqual({
6065 * id: 'super-cache',
6069 * superCache.remove('another key');
6070 * expect(superCache.get('another key')).toBeUndefined();
6072 * superCache.removeAll();
6073 * expect(superCache.info()).toEqual({
6074 * id: 'super-cache',
6080 return caches[cacheId] = {
6084 * @name $cacheFactory.Cache#put
6088 * Inserts a named entry into the {@link $cacheFactory.Cache Cache} object to be
6089 * retrieved later, and incrementing the size of the cache if the key was not already
6090 * present in the cache. If behaving like an LRU cache, it will also remove stale
6091 * entries from the set.
6093 * It will not insert undefined values into the cache.
6095 * @param {string} key the key under which the cached data is stored.
6096 * @param {*} value the value to store alongside the key. If it is undefined, the key
6097 * will not be stored.
6098 * @returns {*} the value stored.
6100 put: function(key, value) {
6101 if (isUndefined(value)) return;
6102 if (capacity < Number.MAX_VALUE) {
6103 var lruEntry = lruHash[key] || (lruHash[key] = {key: key});
6108 if (!(key in data)) size++;
6111 if (size > capacity) {
6112 this.remove(staleEnd.key);
6120 * @name $cacheFactory.Cache#get
6124 * Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object.
6126 * @param {string} key the key of the data to be retrieved
6127 * @returns {*} the value stored.
6129 get: function(key) {
6130 if (capacity < Number.MAX_VALUE) {
6131 var lruEntry = lruHash[key];
6133 if (!lruEntry) return;
6144 * @name $cacheFactory.Cache#remove
6148 * Removes an entry from the {@link $cacheFactory.Cache Cache} object.
6150 * @param {string} key the key of the entry to be removed
6152 remove: function(key) {
6153 if (capacity < Number.MAX_VALUE) {
6154 var lruEntry = lruHash[key];
6156 if (!lruEntry) return;
6158 if (lruEntry == freshEnd) freshEnd = lruEntry.p;
6159 if (lruEntry == staleEnd) staleEnd = lruEntry.n;
6160 link(lruEntry.n,lruEntry.p);
6162 delete lruHash[key];
6165 if (!(key in data)) return;
6174 * @name $cacheFactory.Cache#removeAll
6178 * Clears the cache object of any entries.
6180 removeAll: function() {
6183 lruHash = createMap();
6184 freshEnd = staleEnd = null;
6190 * @name $cacheFactory.Cache#destroy
6194 * Destroys the {@link $cacheFactory.Cache Cache} object entirely,
6195 * removing it from the {@link $cacheFactory $cacheFactory} set.
6197 destroy: function() {
6201 delete caches[cacheId];
6207 * @name $cacheFactory.Cache#info
6211 * Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}.
6213 * @returns {object} an object with the following properties:
6215 * <li>**id**: the id of the cache instance</li>
6216 * <li>**size**: the number of entries kept in the cache instance</li>
6217 * <li>**...**: any additional properties from the options object when creating the
6222 return extend({}, stats, {size: size});
6228 * makes the `entry` the freshEnd of the LRU linked list
6230 function refresh(entry) {
6231 if (entry != freshEnd) {
6234 } else if (staleEnd == entry) {
6238 link(entry.n, entry.p);
6239 link(entry, freshEnd);
6247 * bidirectionally links two entries of the LRU linked list
6249 function link(nextEntry, prevEntry) {
6250 if (nextEntry != prevEntry) {
6251 if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify
6252 if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify
6260 * @name $cacheFactory#info
6263 * Get information about all the caches that have been created
6265 * @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
6267 cacheFactory.info = function() {
6269 forEach(caches, function(cache, cacheId) {
6270 info[cacheId] = cache.info();
6278 * @name $cacheFactory#get
6281 * Get access to a cache object by the `cacheId` used when it was created.
6283 * @param {string} cacheId Name or id of a cache to access.
6284 * @returns {object} Cache object identified by the cacheId or undefined if no such cache.
6286 cacheFactory.get = function(cacheId) {
6287 return caches[cacheId];
6291 return cacheFactory;
6297 * @name $templateCache
6300 * The first time a template is used, it is loaded in the template cache for quick retrieval. You
6301 * can load templates directly into the cache in a `script` tag, or by consuming the
6302 * `$templateCache` service directly.
6304 * Adding via the `script` tag:
6307 * <script type="text/ng-template" id="templateId.html">
6308 * <p>This is the content of the template</p>
6312 * **Note:** the `script` tag containing the template does not need to be included in the `head` of
6313 * the document, but it must be a descendent of the {@link ng.$rootElement $rootElement} (IE,
6314 * element with ng-app attribute), otherwise the template will be ignored.
6316 * Adding via the `$templateCache` service:
6319 * var myApp = angular.module('myApp', []);
6320 * myApp.run(function($templateCache) {
6321 * $templateCache.put('templateId.html', 'This is the content of the template');
6325 * To retrieve the template later, simply use it in your HTML:
6327 * <div ng-include=" 'templateId.html' "></div>
6330 * or get it via Javascript:
6332 * $templateCache.get('templateId.html')
6335 * See {@link ng.$cacheFactory $cacheFactory}.
6338 function $TemplateCacheProvider() {
6339 this.$get = ['$cacheFactory', function($cacheFactory) {
6340 return $cacheFactory('templates');
6344 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
6345 * Any commits to this file should be reviewed with security in mind. *
6346 * Changes to this file can potentially create security vulnerabilities. *
6347 * An approval from 2 Core members with history of modifying *
6348 * this file is required. *
6350 * Does the change somehow allow for arbitrary javascript to be executed? *
6351 * Or allows for someone to change the prototype of built-in objects? *
6352 * Or gives undesired access to variables likes document or window? *
6353 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
6355 /* ! VARIABLE/FUNCTION NAMING CONVENTIONS THAT APPLY TO THIS FILE!
6357 * DOM-related variables:
6359 * - "node" - DOM Node
6360 * - "element" - DOM Element or Node
6361 * - "$node" or "$element" - jqLite-wrapped node or element
6364 * Compiler related stuff:
6366 * - "linkFn" - linking fn of a single directive
6367 * - "nodeLinkFn" - function that aggregates all linking fns for a particular node
6368 * - "childLinkFn" - function that aggregates all linking fns for child nodes of a particular node
6369 * - "compositeLinkFn" - function that aggregates all linking fns for a compilation root (nodeList)
6379 * Compiles an HTML string or DOM into a template and produces a template function, which
6380 * can then be used to link {@link ng.$rootScope.Scope `scope`} and the template together.
6382 * The compilation is a process of walking the DOM tree and matching DOM elements to
6383 * {@link ng.$compileProvider#directive directives}.
6385 * <div class="alert alert-warning">
6386 * **Note:** This document is an in-depth reference of all directive options.
6387 * For a gentle introduction to directives with examples of common use cases,
6388 * see the {@link guide/directive directive guide}.
6391 * ## Comprehensive Directive API
6393 * There are many different options for a directive.
6395 * The difference resides in the return value of the factory function.
6396 * You can either return a "Directive Definition Object" (see below) that defines the directive properties,
6397 * or just the `postLink` function (all other properties will have the default values).
6399 * <div class="alert alert-success">
6400 * **Best Practice:** It's recommended to use the "directive definition object" form.
6403 * Here's an example directive declared with a Directive Definition Object:
6406 * var myModule = angular.module(...);
6408 * myModule.directive('directiveName', function factory(injectables) {
6409 * var directiveDefinitionObject = {
6411 * template: '<div></div>', // or // function(tElement, tAttrs) { ... },
6413 * // templateUrl: 'directive.html', // or // function(tElement, tAttrs) { ... },
6414 * transclude: false,
6416 * templateNamespace: 'html',
6418 * controller: function($scope, $element, $attrs, $transclude, otherInjectables) { ... },
6419 * controllerAs: 'stringIdentifier',
6420 * bindToController: false,
6421 * require: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'],
6422 * compile: function compile(tElement, tAttrs, transclude) {
6424 * pre: function preLink(scope, iElement, iAttrs, controller) { ... },
6425 * post: function postLink(scope, iElement, iAttrs, controller) { ... }
6428 * // return function postLink( ... ) { ... }
6432 * // pre: function preLink(scope, iElement, iAttrs, controller) { ... },
6433 * // post: function postLink(scope, iElement, iAttrs, controller) { ... }
6436 * // link: function postLink( ... ) { ... }
6438 * return directiveDefinitionObject;
6442 * <div class="alert alert-warning">
6443 * **Note:** Any unspecified options will use the default value. You can see the default values below.
6446 * Therefore the above can be simplified as:
6449 * var myModule = angular.module(...);
6451 * myModule.directive('directiveName', function factory(injectables) {
6452 * var directiveDefinitionObject = {
6453 * link: function postLink(scope, iElement, iAttrs) { ... }
6455 * return directiveDefinitionObject;
6457 * // return function postLink(scope, iElement, iAttrs) { ... }
6463 * ### Directive Definition Object
6465 * The directive definition object provides instructions to the {@link ng.$compile
6466 * compiler}. The attributes are:
6468 * #### `multiElement`
6469 * When this property is set to true, the HTML compiler will collect DOM nodes between
6470 * nodes with the attributes `directive-name-start` and `directive-name-end`, and group them
6471 * together as the directive elements. It is recommended that this feature be used on directives
6472 * which are not strictly behavioural (such as {@link ngClick}), and which
6473 * do not manipulate or replace child nodes (such as {@link ngInclude}).
6476 * When there are multiple directives defined on a single DOM element, sometimes it
6477 * is necessary to specify the order in which the directives are applied. The `priority` is used
6478 * to sort the directives before their `compile` functions get called. Priority is defined as a
6479 * number. Directives with greater numerical `priority` are compiled first. Pre-link functions
6480 * are also run in priority order, but post-link functions are run in reverse order. The order
6481 * of directives with the same priority is undefined. The default priority is `0`.
6484 * If set to true then the current `priority` will be the last set of directives
6485 * which will execute (any directives at the current priority will still execute
6486 * as the order of execution on same `priority` is undefined). Note that expressions
6487 * and other directives used in the directive's template will also be excluded from execution.
6490 * The scope property can be `true`, an object or a falsy value:
6492 * * **falsy:** No scope will be created for the directive. The directive will use its parent's scope.
6494 * * **`true`:** A new child scope that prototypically inherits from its parent will be created for
6495 * the directive's element. If multiple directives on the same element request a new scope,
6496 * only one new scope is created. The new scope rule does not apply for the root of the template
6497 * since the root of the template always gets a new scope.
6499 * * **`{...}` (an object hash):** A new "isolate" scope is created for the directive's element. The
6500 * 'isolate' scope differs from normal scope in that it does not prototypically inherit from its parent
6501 * scope. This is useful when creating reusable components, which should not accidentally read or modify
6502 * data in the parent scope.
6504 * The 'isolate' scope object hash defines a set of local scope properties derived from attributes on the
6505 * directive's element. These local properties are useful for aliasing values for templates. The keys in
6506 * the object hash map to the name of the property on the isolate scope; the values define how the property
6507 * is bound to the parent scope, via matching attributes on the directive's element:
6509 * * `@` or `@attr` - bind a local scope property to the value of DOM attribute. The result is
6510 * always a string since DOM attributes are strings. If no `attr` name is specified then the
6511 * attribute name is assumed to be the same as the local name.
6512 * Given `<widget my-attr="hello {{name}}">` and widget definition
6513 * of `scope: { localName:'@myAttr' }`, then widget scope property `localName` will reflect
6514 * the interpolated value of `hello {{name}}`. As the `name` attribute changes so will the
6515 * `localName` property on the widget scope. The `name` is read from the parent scope (not
6518 * * `=` or `=attr` - set up bi-directional binding between a local scope property and the
6519 * parent scope property of name defined via the value of the `attr` attribute. If no `attr`
6520 * name is specified then the attribute name is assumed to be the same as the local name.
6521 * Given `<widget my-attr="parentModel">` and widget definition of
6522 * `scope: { localModel:'=myAttr' }`, then widget scope property `localModel` will reflect the
6523 * value of `parentModel` on the parent scope. Any changes to `parentModel` will be reflected
6524 * in `localModel` and any changes in `localModel` will reflect in `parentModel`. If the parent
6525 * scope property doesn't exist, it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception. You
6526 * can avoid this behavior using `=?` or `=?attr` in order to flag the property as optional. If
6527 * you want to shallow watch for changes (i.e. $watchCollection instead of $watch) you can use
6528 * `=*` or `=*attr` (`=*?` or `=*?attr` if the property is optional).
6530 * * `&` or `&attr` - provides a way to execute an expression in the context of the parent scope.
6531 * If no `attr` name is specified then the attribute name is assumed to be the same as the
6532 * local name. Given `<widget my-attr="count = count + value">` and widget definition of
6533 * `scope: { localFn:'&myAttr' }`, then isolate scope property `localFn` will point to
6534 * a function wrapper for the `count = count + value` expression. Often it's desirable to
6535 * pass data from the isolated scope via an expression to the parent scope, this can be
6536 * done by passing a map of local variable names and values into the expression wrapper fn.
6537 * For example, if the expression is `increment(amount)` then we can specify the amount value
6538 * by calling the `localFn` as `localFn({amount: 22})`.
6540 * In general it's possible to apply more than one directive to one element, but there might be limitations
6541 * depending on the type of scope required by the directives. The following points will help explain these limitations.
6542 * For simplicity only two directives are taken into account, but it is also applicable for several directives:
6544 * * **no scope** + **no scope** => Two directives which don't require their own scope will use their parent's scope
6545 * * **child scope** + **no scope** => Both directives will share one single child scope
6546 * * **child scope** + **child scope** => Both directives will share one single child scope
6547 * * **isolated scope** + **no scope** => The isolated directive will use it's own created isolated scope. The other directive will use
6548 * its parent's scope
6549 * * **isolated scope** + **child scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives cannot
6550 * be applied to the same element.
6551 * * **isolated scope** + **isolated scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives
6552 * cannot be applied to the same element.
6555 * #### `bindToController`
6556 * When an isolate scope is used for a component (see above), and `controllerAs` is used, `bindToController: true` will
6557 * allow a component to have its properties bound to the controller, rather than to scope. When the controller
6558 * is instantiated, the initial values of the isolate scope bindings are already available.
6561 * Controller constructor function. The controller is instantiated before the
6562 * pre-linking phase and can be accessed by other directives (see
6563 * `require` attribute). This allows the directives to communicate with each other and augment
6564 * each other's behavior. The controller is injectable (and supports bracket notation) with the following locals:
6566 * * `$scope` - Current scope associated with the element
6567 * * `$element` - Current element
6568 * * `$attrs` - Current attributes object for the element
6569 * * `$transclude` - A transclude linking function pre-bound to the correct transclusion scope:
6570 * `function([scope], cloneLinkingFn, futureParentElement)`.
6571 * * `scope`: optional argument to override the scope.
6572 * * `cloneLinkingFn`: optional argument to create clones of the original transcluded content.
6573 * * `futureParentElement`:
6574 * * defines the parent to which the `cloneLinkingFn` will add the cloned elements.
6575 * * default: `$element.parent()` resp. `$element` for `transclude:'element'` resp. `transclude:true`.
6576 * * only needed for transcludes that are allowed to contain non html elements (e.g. SVG elements)
6577 * and when the `cloneLinkinFn` is passed,
6578 * as those elements need to created and cloned in a special way when they are defined outside their
6579 * usual containers (e.g. like `<svg>`).
6580 * * See also the `directive.templateNamespace` property.
6584 * Require another directive and inject its controller as the fourth argument to the linking function. The
6585 * `require` takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the
6586 * injected argument will be an array in corresponding order. If no such directive can be
6587 * found, or if the directive does not have a controller, then an error is raised (unless no link function
6588 * is specified, in which case error checking is skipped). The name can be prefixed with:
6590 * * (no prefix) - Locate the required controller on the current element. Throw an error if not found.
6591 * * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found.
6592 * * `^` - Locate the required controller by searching the element and its parents. Throw an error if not found.
6593 * * `^^` - Locate the required controller by searching the element's parents. Throw an error if not found.
6594 * * `?^` - Attempt to locate the required controller by searching the element and its parents or pass
6595 * `null` to the `link` fn if not found.
6596 * * `?^^` - Attempt to locate the required controller by searching the element's parents, or pass
6597 * `null` to the `link` fn if not found.
6600 * #### `controllerAs`
6601 * Identifier name for a reference to the controller in the directive's scope.
6602 * This allows the controller to be referenced from the directive template. This is especially
6603 * useful when a directive is used as component, i.e. with an `isolate` scope. It's also possible
6604 * to use it in a directive without an `isolate` / `new` scope, but you need to be aware that the
6605 * `controllerAs` reference might overwrite a property that already exists on the parent scope.
6609 * String of subset of `EACM` which restricts the directive to a specific directive
6610 * declaration style. If omitted, the defaults (elements and attributes) are used.
6612 * * `E` - Element name (default): `<my-directive></my-directive>`
6613 * * `A` - Attribute (default): `<div my-directive="exp"></div>`
6614 * * `C` - Class: `<div class="my-directive: exp;"></div>`
6615 * * `M` - Comment: `<!-- directive: my-directive exp -->`
6618 * #### `templateNamespace`
6619 * String representing the document type used by the markup in the template.
6620 * AngularJS needs this information as those elements need to be created and cloned
6621 * in a special way when they are defined outside their usual containers like `<svg>` and `<math>`.
6623 * * `html` - All root nodes in the template are HTML. Root nodes may also be
6624 * top-level elements such as `<svg>` or `<math>`.
6625 * * `svg` - The root nodes in the template are SVG elements (excluding `<math>`).
6626 * * `math` - The root nodes in the template are MathML elements (excluding `<svg>`).
6628 * If no `templateNamespace` is specified, then the namespace is considered to be `html`.
6631 * HTML markup that may:
6632 * * Replace the contents of the directive's element (default).
6633 * * Replace the directive's element itself (if `replace` is true - DEPRECATED).
6634 * * Wrap the contents of the directive's element (if `transclude` is true).
6638 * * A string. For example `<div red-on-hover>{{delete_str}}</div>`.
6639 * * A function which takes two arguments `tElement` and `tAttrs` (described in the `compile`
6640 * function api below) and returns a string value.
6643 * #### `templateUrl`
6644 * This is similar to `template` but the template is loaded from the specified URL, asynchronously.
6646 * Because template loading is asynchronous the compiler will suspend compilation of directives on that element
6647 * for later when the template has been resolved. In the meantime it will continue to compile and link
6648 * sibling and parent elements as though this element had not contained any directives.
6650 * The compiler does not suspend the entire compilation to wait for templates to be loaded because this
6651 * would result in the whole app "stalling" until all templates are loaded asynchronously - even in the
6652 * case when only one deeply nested directive has `templateUrl`.
6654 * Template loading is asynchronous even if the template has been preloaded into the {@link $templateCache}
6656 * You can specify `templateUrl` as a string representing the URL or as a function which takes two
6657 * arguments `tElement` and `tAttrs` (described in the `compile` function api below) and returns
6658 * a string value representing the url. In either case, the template URL is passed through {@link
6659 * $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
6662 * #### `replace` ([*DEPRECATED*!], will be removed in next major release - i.e. v2.0)
6663 * specify what the template should replace. Defaults to `false`.
6665 * * `true` - the template will replace the directive's element.
6666 * * `false` - the template will replace the contents of the directive's element.
6668 * The replacement process migrates all of the attributes / classes from the old element to the new
6669 * one. See the {@link guide/directive#template-expanding-directive
6670 * Directives Guide} for an example.
6672 * There are very few scenarios where element replacement is required for the application function,
6673 * the main one being reusable custom components that are used within SVG contexts
6674 * (because SVG doesn't work with custom elements in the DOM tree).
6677 * Extract the contents of the element where the directive appears and make it available to the directive.
6678 * The contents are compiled and provided to the directive as a **transclusion function**. See the
6679 * {@link $compile#transclusion Transclusion} section below.
6681 * There are two kinds of transclusion depending upon whether you want to transclude just the contents of the
6682 * directive's element or the entire element:
6684 * * `true` - transclude the content (i.e. the child nodes) of the directive's element.
6685 * * `'element'` - transclude the whole of the directive's element including any directives on this
6686 * element that defined at a lower priority than this directive. When used, the `template`
6687 * property is ignored.
6693 * function compile(tElement, tAttrs, transclude) { ... }
6696 * The compile function deals with transforming the template DOM. Since most directives do not do
6697 * template transformation, it is not used often. The compile function takes the following arguments:
6699 * * `tElement` - template element - The element where the directive has been declared. It is
6700 * safe to do template transformation on the element and child elements only.
6702 * * `tAttrs` - template attributes - Normalized list of attributes declared on this element shared
6703 * between all directive compile functions.
6705 * * `transclude` - [*DEPRECATED*!] A transclude linking function: `function(scope, cloneLinkingFn)`
6707 * <div class="alert alert-warning">
6708 * **Note:** The template instance and the link instance may be different objects if the template has
6709 * been cloned. For this reason it is **not** safe to do anything other than DOM transformations that
6710 * apply to all cloned DOM nodes within the compile function. Specifically, DOM listener registration
6711 * should be done in a linking function rather than in a compile function.
6714 * <div class="alert alert-warning">
6715 * **Note:** The compile function cannot handle directives that recursively use themselves in their
6716 * own templates or compile functions. Compiling these directives results in an infinite loop and a
6717 * stack overflow errors.
6719 * This can be avoided by manually using $compile in the postLink function to imperatively compile
6720 * a directive's template instead of relying on automatic template compilation via `template` or
6721 * `templateUrl` declaration or manual compilation inside the compile function.
6724 * <div class="alert alert-danger">
6725 * **Note:** The `transclude` function that is passed to the compile function is deprecated, as it
6726 * e.g. does not know about the right outer scope. Please use the transclude function that is passed
6727 * to the link function instead.
6730 * A compile function can have a return value which can be either a function or an object.
6732 * * returning a (post-link) function - is equivalent to registering the linking function via the
6733 * `link` property of the config object when the compile function is empty.
6735 * * returning an object with function(s) registered via `pre` and `post` properties - allows you to
6736 * control when a linking function should be called during the linking phase. See info about
6737 * pre-linking and post-linking functions below.
6741 * This property is used only if the `compile` property is not defined.
6744 * function link(scope, iElement, iAttrs, controller, transcludeFn) { ... }
6747 * The link function is responsible for registering DOM listeners as well as updating the DOM. It is
6748 * executed after the template has been cloned. This is where most of the directive logic will be
6751 * * `scope` - {@link ng.$rootScope.Scope Scope} - The scope to be used by the
6752 * directive for registering {@link ng.$rootScope.Scope#$watch watches}.
6754 * * `iElement` - instance element - The element where the directive is to be used. It is safe to
6755 * manipulate the children of the element only in `postLink` function since the children have
6756 * already been linked.
6758 * * `iAttrs` - instance attributes - Normalized list of attributes declared on this element shared
6759 * between all directive linking functions.
6761 * * `controller` - the directive's required controller instance(s) - Instances are shared
6762 * among all directives, which allows the directives to use the controllers as a communication
6763 * channel. The exact value depends on the directive's `require` property:
6764 * * no controller(s) required: the directive's own controller, or `undefined` if it doesn't have one
6765 * * `string`: the controller instance
6766 * * `array`: array of controller instances
6768 * If a required controller cannot be found, and it is optional, the instance is `null`,
6769 * otherwise the {@link error:$compile:ctreq Missing Required Controller} error is thrown.
6771 * Note that you can also require the directive's own controller - it will be made available like
6772 * any other controller.
6774 * * `transcludeFn` - A transclude linking function pre-bound to the correct transclusion scope.
6775 * This is the same as the `$transclude`
6776 * parameter of directive controllers, see there for details.
6777 * `function([scope], cloneLinkingFn, futureParentElement)`.
6779 * #### Pre-linking function
6781 * Executed before the child elements are linked. Not safe to do DOM transformation since the
6782 * compiler linking function will fail to locate the correct elements for linking.
6784 * #### Post-linking function
6786 * Executed after the child elements are linked.
6788 * Note that child elements that contain `templateUrl` directives will not have been compiled
6789 * and linked since they are waiting for their template to load asynchronously and their own
6790 * compilation and linking has been suspended until that occurs.
6792 * It is safe to do DOM transformation in the post-linking function on elements that are not waiting
6793 * for their async templates to be resolved.
6798 * Transclusion is the process of extracting a collection of DOM elements from one part of the DOM and
6799 * copying them to another part of the DOM, while maintaining their connection to the original AngularJS
6800 * scope from where they were taken.
6802 * Transclusion is used (often with {@link ngTransclude}) to insert the
6803 * original contents of a directive's element into a specified place in the template of the directive.
6804 * The benefit of transclusion, over simply moving the DOM elements manually, is that the transcluded
6805 * content has access to the properties on the scope from which it was taken, even if the directive
6806 * has isolated scope.
6807 * See the {@link guide/directive#creating-a-directive-that-wraps-other-elements Directives Guide}.
6809 * This makes it possible for the widget to have private state for its template, while the transcluded
6810 * content has access to its originating scope.
6812 * <div class="alert alert-warning">
6813 * **Note:** When testing an element transclude directive you must not place the directive at the root of the
6814 * DOM fragment that is being compiled. See {@link guide/unit-testing#testing-transclusion-directives
6815 * Testing Transclusion Directives}.
6818 * #### Transclusion Functions
6820 * When a directive requests transclusion, the compiler extracts its contents and provides a **transclusion
6821 * function** to the directive's `link` function and `controller`. This transclusion function is a special
6822 * **linking function** that will return the compiled contents linked to a new transclusion scope.
6824 * <div class="alert alert-info">
6825 * If you are just using {@link ngTransclude} then you don't need to worry about this function, since
6826 * ngTransclude will deal with it for us.
6829 * If you want to manually control the insertion and removal of the transcluded content in your directive
6830 * then you must use this transclude function. When you call a transclude function it returns a a jqLite/JQuery
6831 * object that contains the compiled DOM, which is linked to the correct transclusion scope.
6833 * When you call a transclusion function you can pass in a **clone attach function**. This function accepts
6834 * two parameters, `function(clone, scope) { ... }`, where the `clone` is a fresh compiled copy of your transcluded
6835 * content and the `scope` is the newly created transclusion scope, to which the clone is bound.
6837 * <div class="alert alert-info">
6838 * **Best Practice**: Always provide a `cloneFn` (clone attach function) when you call a translude function
6839 * since you then get a fresh clone of the original DOM and also have access to the new transclusion scope.
6842 * It is normal practice to attach your transcluded content (`clone`) to the DOM inside your **clone
6843 * attach function**:
6846 * var transcludedContent, transclusionScope;
6848 * $transclude(function(clone, scope) {
6849 * element.append(clone);
6850 * transcludedContent = clone;
6851 * transclusionScope = scope;
6855 * Later, if you want to remove the transcluded content from your DOM then you should also destroy the
6856 * associated transclusion scope:
6859 * transcludedContent.remove();
6860 * transclusionScope.$destroy();
6863 * <div class="alert alert-info">
6864 * **Best Practice**: if you intend to add and remove transcluded content manually in your directive
6865 * (by calling the transclude function to get the DOM and calling `element.remove()` to remove it),
6866 * then you are also responsible for calling `$destroy` on the transclusion scope.
6869 * The built-in DOM manipulation directives, such as {@link ngIf}, {@link ngSwitch} and {@link ngRepeat}
6870 * automatically destroy their transluded clones as necessary so you do not need to worry about this if
6871 * you are simply using {@link ngTransclude} to inject the transclusion into your directive.
6874 * #### Transclusion Scopes
6876 * When you call a transclude function it returns a DOM fragment that is pre-bound to a **transclusion
6877 * scope**. This scope is special, in that it is a child of the directive's scope (and so gets destroyed
6878 * when the directive's scope gets destroyed) but it inherits the properties of the scope from which it
6881 * For example consider a directive that uses transclusion and isolated scope. The DOM hierarchy might look
6887 * <div transclusion>
6893 * The `$parent` scope hierarchy will look like this:
6901 * but the scopes will inherit prototypically from different scopes to their `$parent`.
6912 * The {@link ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the
6913 * `link()` or `compile()` functions. It has a variety of uses.
6915 * accessing *Normalized attribute names:*
6916 * Directives like 'ngBind' can be expressed in many ways: 'ng:bind', `data-ng-bind`, or 'x-ng-bind'.
6917 * the attributes object allows for normalized access to
6920 * * *Directive inter-communication:* All directives share the same instance of the attributes
6921 * object which allows the directives to use the attributes object as inter directive
6924 * * *Supports interpolation:* Interpolation attributes are assigned to the attribute object
6925 * allowing other directives to read the interpolated value.
6927 * * *Observing interpolated attributes:* Use `$observe` to observe the value changes of attributes
6928 * that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also
6929 * the only way to easily get the actual value because during the linking phase the interpolation
6930 * hasn't been evaluated yet and so the value is at this time set to `undefined`.
6933 * function linkingFn(scope, elm, attrs, ctrl) {
6934 * // get the attribute value
6935 * console.log(attrs.ngModel);
6937 * // change the attribute
6938 * attrs.$set('ngModel', 'new value');
6940 * // observe changes to interpolated attribute
6941 * attrs.$observe('ngModel', function(value) {
6942 * console.log('ngModel has changed value to ' + value);
6949 * <div class="alert alert-warning">
6950 * **Note**: Typically directives are registered with `module.directive`. The example below is
6951 * to illustrate how `$compile` works.
6954 <example module="compileExample">
6955 <file name="index.html">
6957 angular.module('compileExample', [], function($compileProvider) {
6958 // configure new 'compile' directive by passing a directive
6959 // factory function. The factory function injects the '$compile'
6960 $compileProvider.directive('compile', function($compile) {
6961 // directive factory creates a link function
6962 return function(scope, element, attrs) {
6965 // watch the 'compile' expression for changes
6966 return scope.$eval(attrs.compile);
6969 // when the 'compile' expression changes
6970 // assign it into the current DOM
6971 element.html(value);
6973 // compile the new DOM and link it to the current
6975 // NOTE: we only compile .childNodes so that
6976 // we don't get into infinite loop compiling ourselves
6977 $compile(element.contents())(scope);
6983 .controller('GreeterController', ['$scope', function($scope) {
6984 $scope.name = 'Angular';
6985 $scope.html = 'Hello {{name}}';
6988 <div ng-controller="GreeterController">
6989 <input ng-model="name"> <br/>
6990 <textarea ng-model="html"></textarea> <br/>
6991 <div compile="html"></div>
6994 <file name="protractor.js" type="protractor">
6995 it('should auto compile', function() {
6996 var textarea = $('textarea');
6997 var output = $('div[compile]');
6998 // The initial state reads 'Hello Angular'.
6999 expect(output.getText()).toBe('Hello Angular');
7001 textarea.sendKeys('{{name}}!');
7002 expect(output.getText()).toBe('Angular!');
7009 * @param {string|DOMElement} element Element or HTML string to compile into a template function.
7010 * @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives - DEPRECATED.
7012 * <div class="alert alert-danger">
7013 * **Note:** Passing a `transclude` function to the $compile function is deprecated, as it
7014 * e.g. will not use the right outer scope. Please pass the transclude function as a
7015 * `parentBoundTranscludeFn` to the link function instead.
7018 * @param {number} maxPriority only apply directives lower than given priority (Only effects the
7019 * root element(s), not their children)
7020 * @returns {function(scope, cloneAttachFn=, options=)} a link function which is used to bind template
7021 * (a DOM element/tree) to a scope. Where:
7023 * * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
7024 * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
7025 * `template` and call the `cloneAttachFn` function allowing the caller to attach the
7026 * cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
7027 * called as: <br/> `cloneAttachFn(clonedElement, scope)` where:
7029 * * `clonedElement` - is a clone of the original `element` passed into the compiler.
7030 * * `scope` - is the current scope with which the linking function is working with.
7032 * * `options` - An optional object hash with linking options. If `options` is provided, then the following
7033 * keys may be used to control linking behavior:
7035 * * `parentBoundTranscludeFn` - the transclude function made available to
7036 * directives; if given, it will be passed through to the link functions of
7037 * directives found in `element` during compilation.
7038 * * `transcludeControllers` - an object hash with keys that map controller names
7039 * to controller instances; if given, it will make the controllers
7040 * available to directives.
7041 * * `futureParentElement` - defines the parent to which the `cloneAttachFn` will add
7042 * the cloned elements; only needed for transcludes that are allowed to contain non html
7043 * elements (e.g. SVG elements). See also the directive.controller property.
7045 * Calling the linking function returns the element of the template. It is either the original
7046 * element passed in, or the clone of the element if the `cloneAttachFn` is provided.
7048 * After linking the view is not updated until after a call to $digest which typically is done by
7049 * Angular automatically.
7051 * If you need access to the bound view, there are two ways to do it:
7053 * - If you are not asking the linking function to clone the template, create the DOM element(s)
7054 * before you send them to the compiler and keep this reference around.
7056 * var element = $compile('<p>{{total}}</p>')(scope);
7059 * - if on the other hand, you need the element to be cloned, the view reference from the original
7060 * example would not point to the clone, but rather to the original template that was cloned. In
7061 * this case, you can access the clone via the cloneAttachFn:
7063 * var templateElement = angular.element('<p>{{total}}</p>'),
7066 * var clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) {
7067 * //attach the clone to DOM document at the right place
7070 * //now we have reference to the cloned DOM via `clonedElement`
7074 * For information on how the compiler works, see the
7075 * {@link guide/compiler Angular HTML Compiler} section of the Developer Guide.
7078 var $compileMinErr = minErr('$compile');
7082 * @name $compileProvider
7086 $CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider'];
7087 function $CompileProvider($provide, $$sanitizeUriProvider) {
7088 var hasDirectives = {},
7089 Suffix = 'Directive',
7090 COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\w\-]+)\s+(.*)$/,
7091 CLASS_DIRECTIVE_REGEXP = /(([\w\-]+)(?:\:([^;]+))?;?)/,
7092 ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'),
7093 REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/;
7095 // Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
7096 // The assumption is that future DOM event attribute names will begin with
7097 // 'on' and be composed of only English letters.
7098 var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
7100 function parseIsolateBindings(scope, directiveName, isController) {
7101 var LOCAL_REGEXP = /^\s*([@&]|=(\*?))(\??)\s*(\w*)\s*$/;
7105 forEach(scope, function(definition, scopeName) {
7106 var match = definition.match(LOCAL_REGEXP);
7109 throw $compileMinErr('iscp',
7110 "Invalid {3} for directive '{0}'." +
7111 " Definition: {... {1}: '{2}' ...}",
7112 directiveName, scopeName, definition,
7113 (isController ? "controller bindings definition" :
7114 "isolate scope definition"));
7117 bindings[scopeName] = {
7119 collection: match[2] === '*',
7120 optional: match[3] === '?',
7121 attrName: match[4] || scopeName
7128 function parseDirectiveBindings(directive, directiveName) {
7131 bindToController: null
7133 if (isObject(directive.scope)) {
7134 if (directive.bindToController === true) {
7135 bindings.bindToController = parseIsolateBindings(directive.scope,
7136 directiveName, true);
7137 bindings.isolateScope = {};
7139 bindings.isolateScope = parseIsolateBindings(directive.scope,
7140 directiveName, false);
7143 if (isObject(directive.bindToController)) {
7144 bindings.bindToController =
7145 parseIsolateBindings(directive.bindToController, directiveName, true);
7147 if (isObject(bindings.bindToController)) {
7148 var controller = directive.controller;
7149 var controllerAs = directive.controllerAs;
7151 // There is no controller, there may or may not be a controllerAs property
7152 throw $compileMinErr('noctrl',
7153 "Cannot bind to controller without directive '{0}'s controller.",
7155 } else if (!identifierForController(controller, controllerAs)) {
7156 // There is a controller, but no identifier or controllerAs property
7157 throw $compileMinErr('noident',
7158 "Cannot bind to controller without identifier for directive '{0}'.",
7165 function assertValidDirectiveName(name) {
7166 var letter = name.charAt(0);
7167 if (!letter || letter !== lowercase(letter)) {
7168 throw $compileMinErr('baddir', "Directive name '{0}' is invalid. The first character must be a lowercase letter", name);
7170 if (name !== name.trim()) {
7171 throw $compileMinErr('baddir',
7172 "Directive name '{0}' is invalid. The name should not contain leading or trailing whitespaces",
7179 * @name $compileProvider#directive
7183 * Register a new directive with the compiler.
7185 * @param {string|Object} name Name of the directive in camel-case (i.e. <code>ngBind</code> which
7186 * will match as <code>ng-bind</code>), or an object map of directives where the keys are the
7187 * names and the values are the factories.
7188 * @param {Function|Array} directiveFactory An injectable directive factory function. See
7189 * {@link guide/directive} for more info.
7190 * @returns {ng.$compileProvider} Self for chaining.
7192 this.directive = function registerDirective(name, directiveFactory) {
7193 assertNotHasOwnProperty(name, 'directive');
7194 if (isString(name)) {
7195 assertValidDirectiveName(name);
7196 assertArg(directiveFactory, 'directiveFactory');
7197 if (!hasDirectives.hasOwnProperty(name)) {
7198 hasDirectives[name] = [];
7199 $provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
7200 function($injector, $exceptionHandler) {
7201 var directives = [];
7202 forEach(hasDirectives[name], function(directiveFactory, index) {
7204 var directive = $injector.invoke(directiveFactory);
7205 if (isFunction(directive)) {
7206 directive = { compile: valueFn(directive) };
7207 } else if (!directive.compile && directive.link) {
7208 directive.compile = valueFn(directive.link);
7210 directive.priority = directive.priority || 0;
7211 directive.index = index;
7212 directive.name = directive.name || name;
7213 directive.require = directive.require || (directive.controller && directive.name);
7214 directive.restrict = directive.restrict || 'EA';
7215 var bindings = directive.$$bindings =
7216 parseDirectiveBindings(directive, directive.name);
7217 if (isObject(bindings.isolateScope)) {
7218 directive.$$isolateBindings = bindings.isolateScope;
7220 directive.$$moduleName = directiveFactory.$$moduleName;
7221 directives.push(directive);
7223 $exceptionHandler(e);
7229 hasDirectives[name].push(directiveFactory);
7231 forEach(name, reverseParams(registerDirective));
7239 * @name $compileProvider#aHrefSanitizationWhitelist
7243 * Retrieves or overrides the default regular expression that is used for whitelisting of safe
7244 * urls during a[href] sanitization.
7246 * The sanitization is a security measure aimed at preventing XSS attacks via html links.
7248 * Any url about to be assigned to a[href] via data-binding is first normalized and turned into
7249 * an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist`
7250 * regular expression. If a match is found, the original url is written into the dom. Otherwise,
7251 * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
7253 * @param {RegExp=} regexp New regexp to whitelist urls with.
7254 * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
7255 * chaining otherwise.
7257 this.aHrefSanitizationWhitelist = function(regexp) {
7258 if (isDefined(regexp)) {
7259 $$sanitizeUriProvider.aHrefSanitizationWhitelist(regexp);
7262 return $$sanitizeUriProvider.aHrefSanitizationWhitelist();
7269 * @name $compileProvider#imgSrcSanitizationWhitelist
7273 * Retrieves or overrides the default regular expression that is used for whitelisting of safe
7274 * urls during img[src] sanitization.
7276 * The sanitization is a security measure aimed at prevent XSS attacks via html links.
7278 * Any url about to be assigned to img[src] via data-binding is first normalized and turned into
7279 * an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist`
7280 * regular expression. If a match is found, the original url is written into the dom. Otherwise,
7281 * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
7283 * @param {RegExp=} regexp New regexp to whitelist urls with.
7284 * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
7285 * chaining otherwise.
7287 this.imgSrcSanitizationWhitelist = function(regexp) {
7288 if (isDefined(regexp)) {
7289 $$sanitizeUriProvider.imgSrcSanitizationWhitelist(regexp);
7292 return $$sanitizeUriProvider.imgSrcSanitizationWhitelist();
7298 * @name $compileProvider#debugInfoEnabled
7300 * @param {boolean=} enabled update the debugInfoEnabled state if provided, otherwise just return the
7301 * current debugInfoEnabled state
7302 * @returns {*} current value if used as getter or itself (chaining) if used as setter
7307 * Call this method to enable/disable various debug runtime information in the compiler such as adding
7308 * binding information and a reference to the current scope on to DOM elements.
7309 * If enabled, the compiler will add the following to DOM elements that have been bound to the scope
7310 * * `ng-binding` CSS class
7311 * * `$binding` data property containing an array of the binding expressions
7313 * You may want to disable this in production for a significant performance boost. See
7314 * {@link guide/production#disabling-debug-data Disabling Debug Data} for more.
7316 * The default value is true.
7318 var debugInfoEnabled = true;
7319 this.debugInfoEnabled = function(enabled) {
7320 if (isDefined(enabled)) {
7321 debugInfoEnabled = enabled;
7324 return debugInfoEnabled;
7328 '$injector', '$interpolate', '$exceptionHandler', '$templateRequest', '$parse',
7329 '$controller', '$rootScope', '$document', '$sce', '$animate', '$$sanitizeUri',
7330 function($injector, $interpolate, $exceptionHandler, $templateRequest, $parse,
7331 $controller, $rootScope, $document, $sce, $animate, $$sanitizeUri) {
7333 var Attributes = function(element, attributesToCopy) {
7334 if (attributesToCopy) {
7335 var keys = Object.keys(attributesToCopy);
7338 for (i = 0, l = keys.length; i < l; i++) {
7340 this[key] = attributesToCopy[key];
7346 this.$$element = element;
7349 Attributes.prototype = {
7352 * @name $compile.directive.Attributes#$normalize
7356 * Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with `x-` or
7357 * `data-`) to its normalized, camelCase form.
7359 * Also there is special case for Moz prefix starting with upper case letter.
7361 * For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
7363 * @param {string} name Name to normalize
7365 $normalize: directiveNormalize,
7370 * @name $compile.directive.Attributes#$addClass
7374 * Adds the CSS class value specified by the classVal parameter to the element. If animations
7375 * are enabled then an animation will be triggered for the class addition.
7377 * @param {string} classVal The className value that will be added to the element
7379 $addClass: function(classVal) {
7380 if (classVal && classVal.length > 0) {
7381 $animate.addClass(this.$$element, classVal);
7387 * @name $compile.directive.Attributes#$removeClass
7391 * Removes the CSS class value specified by the classVal parameter from the element. If
7392 * animations are enabled then an animation will be triggered for the class removal.
7394 * @param {string} classVal The className value that will be removed from the element
7396 $removeClass: function(classVal) {
7397 if (classVal && classVal.length > 0) {
7398 $animate.removeClass(this.$$element, classVal);
7404 * @name $compile.directive.Attributes#$updateClass
7408 * Adds and removes the appropriate CSS class values to the element based on the difference
7409 * between the new and old CSS class values (specified as newClasses and oldClasses).
7411 * @param {string} newClasses The current CSS className value
7412 * @param {string} oldClasses The former CSS className value
7414 $updateClass: function(newClasses, oldClasses) {
7415 var toAdd = tokenDifference(newClasses, oldClasses);
7416 if (toAdd && toAdd.length) {
7417 $animate.addClass(this.$$element, toAdd);
7420 var toRemove = tokenDifference(oldClasses, newClasses);
7421 if (toRemove && toRemove.length) {
7422 $animate.removeClass(this.$$element, toRemove);
7427 * Set a normalized attribute on the element in a way such that all directives
7428 * can share the attribute. This function properly handles boolean attributes.
7429 * @param {string} key Normalized key. (ie ngAttribute)
7430 * @param {string|boolean} value The value to set. If `null` attribute will be deleted.
7431 * @param {boolean=} writeAttr If false, does not write the value to DOM element attribute.
7433 * @param {string=} attrName Optional none normalized name. Defaults to key.
7435 $set: function(key, value, writeAttr, attrName) {
7436 // TODO: decide whether or not to throw an error if "class"
7437 //is set through this function since it may cause $updateClass to
7440 var node = this.$$element[0],
7441 booleanKey = getBooleanAttrName(node, key),
7442 aliasedKey = getAliasedAttrName(key),
7447 this.$$element.prop(key, value);
7448 attrName = booleanKey;
7449 } else if (aliasedKey) {
7450 this[aliasedKey] = value;
7451 observer = aliasedKey;
7456 // translate normalized key to actual key
7458 this.$attr[key] = attrName;
7460 attrName = this.$attr[key];
7462 this.$attr[key] = attrName = snake_case(key, '-');
7466 nodeName = nodeName_(this.$$element);
7468 if ((nodeName === 'a' && key === 'href') ||
7469 (nodeName === 'img' && key === 'src')) {
7470 // sanitize a[href] and img[src] values
7471 this[key] = value = $$sanitizeUri(value, key === 'src');
7472 } else if (nodeName === 'img' && key === 'srcset') {
7473 // sanitize img[srcset] values
7476 // first check if there are spaces because it's not the same pattern
7477 var trimmedSrcset = trim(value);
7478 // ( 999x ,| 999w ,| ,|, )
7479 var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/;
7480 var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/;
7482 // split srcset into tuple of uri and descriptor except for the last item
7483 var rawUris = trimmedSrcset.split(pattern);
7486 var nbrUrisWith2parts = Math.floor(rawUris.length / 2);
7487 for (var i = 0; i < nbrUrisWith2parts; i++) {
7488 var innerIdx = i * 2;
7490 result += $$sanitizeUri(trim(rawUris[innerIdx]), true);
7491 // add the descriptor
7492 result += (" " + trim(rawUris[innerIdx + 1]));
7495 // split the last item into uri and descriptor
7496 var lastTuple = trim(rawUris[i * 2]).split(/\s/);
7498 // sanitize the last uri
7499 result += $$sanitizeUri(trim(lastTuple[0]), true);
7501 // and add the last descriptor if any
7502 if (lastTuple.length === 2) {
7503 result += (" " + trim(lastTuple[1]));
7505 this[key] = value = result;
7508 if (writeAttr !== false) {
7509 if (value === null || isUndefined(value)) {
7510 this.$$element.removeAttr(attrName);
7512 this.$$element.attr(attrName, value);
7517 var $$observers = this.$$observers;
7518 $$observers && forEach($$observers[observer], function(fn) {
7522 $exceptionHandler(e);
7530 * @name $compile.directive.Attributes#$observe
7534 * Observes an interpolated attribute.
7536 * The observer function will be invoked once during the next `$digest` following
7537 * compilation. The observer is then invoked whenever the interpolated value
7540 * @param {string} key Normalized key. (ie ngAttribute) .
7541 * @param {function(interpolatedValue)} fn Function that will be called whenever
7542 the interpolated value of the attribute changes.
7543 * See the {@link guide/directive#text-and-attribute-bindings Directives} guide for more info.
7544 * @returns {function()} Returns a deregistration function for this observer.
7546 $observe: function(key, fn) {
7548 $$observers = (attrs.$$observers || (attrs.$$observers = createMap())),
7549 listeners = ($$observers[key] || ($$observers[key] = []));
7552 $rootScope.$evalAsync(function() {
7553 if (!listeners.$$inter && attrs.hasOwnProperty(key) && !isUndefined(attrs[key])) {
7554 // no one registered attribute interpolation function, so lets call it manually
7560 arrayRemove(listeners, fn);
7566 function safeAddClass($element, className) {
7568 $element.addClass(className);
7570 // ignore, since it means that we are trying to set class on
7571 // SVG element, where class name is read-only.
7576 var startSymbol = $interpolate.startSymbol(),
7577 endSymbol = $interpolate.endSymbol(),
7578 denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
7580 : function denormalizeTemplate(template) {
7581 return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
7583 NG_ATTR_BINDING = /^ngAttr[A-Z]/;
7584 var MULTI_ELEMENT_DIR_RE = /^(.+)Start$/;
7586 compile.$$addBindingInfo = debugInfoEnabled ? function $$addBindingInfo($element, binding) {
7587 var bindings = $element.data('$binding') || [];
7589 if (isArray(binding)) {
7590 bindings = bindings.concat(binding);
7592 bindings.push(binding);
7595 $element.data('$binding', bindings);
7598 compile.$$addBindingClass = debugInfoEnabled ? function $$addBindingClass($element) {
7599 safeAddClass($element, 'ng-binding');
7602 compile.$$addScopeInfo = debugInfoEnabled ? function $$addScopeInfo($element, scope, isolated, noTemplate) {
7603 var dataName = isolated ? (noTemplate ? '$isolateScopeNoTemplate' : '$isolateScope') : '$scope';
7604 $element.data(dataName, scope);
7607 compile.$$addScopeClass = debugInfoEnabled ? function $$addScopeClass($element, isolated) {
7608 safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope');
7613 //================================
7615 function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
7616 previousCompileContext) {
7617 if (!($compileNodes instanceof jqLite)) {
7618 // jquery always rewraps, whereas we need to preserve the original selector so that we can
7620 $compileNodes = jqLite($compileNodes);
7622 // We can not compile top level text elements since text nodes can be merged and we will
7623 // not be able to attach scope data to them, so we will wrap them in <span>
7624 forEach($compileNodes, function(node, index) {
7625 if (node.nodeType == NODE_TYPE_TEXT && node.nodeValue.match(/\S+/) /* non-empty */ ) {
7626 $compileNodes[index] = jqLite(node).wrap('<span></span>').parent()[0];
7629 var compositeLinkFn =
7630 compileNodes($compileNodes, transcludeFn, $compileNodes,
7631 maxPriority, ignoreDirective, previousCompileContext);
7632 compile.$$addScopeClass($compileNodes);
7633 var namespace = null;
7634 return function publicLinkFn(scope, cloneConnectFn, options) {
7635 assertArg(scope, 'scope');
7637 if (previousCompileContext && previousCompileContext.needsNewScope) {
7638 // A parent directive did a replace and a directive on this element asked
7639 // for transclusion, which caused us to lose a layer of element on which
7640 // we could hold the new transclusion scope, so we will create it manually
7642 scope = scope.$parent.$new();
7645 options = options || {};
7646 var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
7647 transcludeControllers = options.transcludeControllers,
7648 futureParentElement = options.futureParentElement;
7650 // When `parentBoundTranscludeFn` is passed, it is a
7651 // `controllersBoundTransclude` function (it was previously passed
7652 // as `transclude` to directive.link) so we must unwrap it to get
7653 // its `boundTranscludeFn`
7654 if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
7655 parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
7659 namespace = detectNamespaceForChildElements(futureParentElement);
7662 if (namespace !== 'html') {
7663 // When using a directive with replace:true and templateUrl the $compileNodes
7664 // (or a child element inside of them)
7665 // might change, so we need to recreate the namespace adapted compileNodes
7666 // for call to the link function.
7667 // Note: This will already clone the nodes...
7669 wrapTemplate(namespace, jqLite('<div>').append($compileNodes).html())
7671 } else if (cloneConnectFn) {
7672 // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
7673 // and sometimes changes the structure of the DOM.
7674 $linkNode = JQLitePrototype.clone.call($compileNodes);
7676 $linkNode = $compileNodes;
7679 if (transcludeControllers) {
7680 for (var controllerName in transcludeControllers) {
7681 $linkNode.data('$' + controllerName + 'Controller', transcludeControllers[controllerName].instance);
7685 compile.$$addScopeInfo($linkNode, scope);
7687 if (cloneConnectFn) cloneConnectFn($linkNode, scope);
7688 if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode, parentBoundTranscludeFn);
7693 function detectNamespaceForChildElements(parentElement) {
7694 // TODO: Make this detect MathML as well...
7695 var node = parentElement && parentElement[0];
7699 return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg' : 'html';
7704 * Compile function matches each node in nodeList against the directives. Once all directives
7705 * for a particular node are collected their compile functions are executed. The compile
7706 * functions return values - the linking functions - are combined into a composite linking
7707 * function, which is the a linking function for the node.
7709 * @param {NodeList} nodeList an array of nodes or NodeList to compile
7710 * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
7711 * scope argument is auto-generated to the new child of the transcluded parent scope.
7712 * @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then
7713 * the rootElement must be set the jqLite collection of the compile root. This is
7714 * needed so that the jqLite collection items can be replaced with widgets.
7715 * @param {number=} maxPriority Max directive priority.
7716 * @returns {Function} A composite linking function of all of the matched directives or null.
7718 function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
7719 previousCompileContext) {
7721 attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound;
7723 for (var i = 0; i < nodeList.length; i++) {
7724 attrs = new Attributes();
7726 // we must always refer to nodeList[i] since the nodes can be replaced underneath us.
7727 directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined,
7730 nodeLinkFn = (directives.length)
7731 ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement,
7732 null, [], [], previousCompileContext)
7735 if (nodeLinkFn && nodeLinkFn.scope) {
7736 compile.$$addScopeClass(attrs.$$element);
7739 childLinkFn = (nodeLinkFn && nodeLinkFn.terminal ||
7740 !(childNodes = nodeList[i].childNodes) ||
7743 : compileNodes(childNodes,
7745 (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement)
7746 && nodeLinkFn.transclude) : transcludeFn);
7748 if (nodeLinkFn || childLinkFn) {
7749 linkFns.push(i, nodeLinkFn, childLinkFn);
7751 nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn;
7754 //use the previous context only for the first element in the virtual group
7755 previousCompileContext = null;
7758 // return a linking function if we have found anything, null otherwise
7759 return linkFnFound ? compositeLinkFn : null;
7761 function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) {
7762 var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn;
7766 if (nodeLinkFnFound) {
7767 // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our
7768 // offsets don't get screwed up
7769 var nodeListLength = nodeList.length;
7770 stableNodeList = new Array(nodeListLength);
7772 // create a sparse array by only copying the elements which have a linkFn
7773 for (i = 0; i < linkFns.length; i+=3) {
7775 stableNodeList[idx] = nodeList[idx];
7778 stableNodeList = nodeList;
7781 for (i = 0, ii = linkFns.length; i < ii;) {
7782 node = stableNodeList[linkFns[i++]];
7783 nodeLinkFn = linkFns[i++];
7784 childLinkFn = linkFns[i++];
7787 if (nodeLinkFn.scope) {
7788 childScope = scope.$new();
7789 compile.$$addScopeInfo(jqLite(node), childScope);
7794 if (nodeLinkFn.transcludeOnThisElement) {
7795 childBoundTranscludeFn = createBoundTranscludeFn(
7796 scope, nodeLinkFn.transclude, parentBoundTranscludeFn);
7798 } else if (!nodeLinkFn.templateOnThisElement && parentBoundTranscludeFn) {
7799 childBoundTranscludeFn = parentBoundTranscludeFn;
7801 } else if (!parentBoundTranscludeFn && transcludeFn) {
7802 childBoundTranscludeFn = createBoundTranscludeFn(scope, transcludeFn);
7805 childBoundTranscludeFn = null;
7808 nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn);
7810 } else if (childLinkFn) {
7811 childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn);
7817 function createBoundTranscludeFn(scope, transcludeFn, previousBoundTranscludeFn) {
7819 var boundTranscludeFn = function(transcludedScope, cloneFn, controllers, futureParentElement, containingScope) {
7821 if (!transcludedScope) {
7822 transcludedScope = scope.$new(false, containingScope);
7823 transcludedScope.$$transcluded = true;
7826 return transcludeFn(transcludedScope, cloneFn, {
7827 parentBoundTranscludeFn: previousBoundTranscludeFn,
7828 transcludeControllers: controllers,
7829 futureParentElement: futureParentElement
7833 return boundTranscludeFn;
7837 * Looks for directives on the given node and adds them to the directive collection which is
7840 * @param node Node to search.
7841 * @param directives An array to which the directives are added to. This array is sorted before
7842 * the function returns.
7843 * @param attrs The shared attrs object which is used to populate the normalized attributes.
7844 * @param {number=} maxPriority Max directive priority.
7846 function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
7847 var nodeType = node.nodeType,
7848 attrsMap = attrs.$attr,
7853 case NODE_TYPE_ELEMENT: /* Element */
7854 // use the node name: <directive>
7855 addDirective(directives,
7856 directiveNormalize(nodeName_(node)), 'E', maxPriority, ignoreDirective);
7858 // iterate over the attributes
7859 for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes,
7860 j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
7861 var attrStartName = false;
7862 var attrEndName = false;
7866 value = trim(attr.value);
7868 // support ngAttr attribute binding
7869 ngAttrName = directiveNormalize(name);
7870 if (isNgAttr = NG_ATTR_BINDING.test(ngAttrName)) {
7871 name = name.replace(PREFIX_REGEXP, '')
7872 .substr(8).replace(/_(.)/g, function(match, letter) {
7873 return letter.toUpperCase();
7877 var multiElementMatch = ngAttrName.match(MULTI_ELEMENT_DIR_RE);
7878 if (multiElementMatch && directiveIsMultiElement(multiElementMatch[1])) {
7879 attrStartName = name;
7880 attrEndName = name.substr(0, name.length - 5) + 'end';
7881 name = name.substr(0, name.length - 6);
7884 nName = directiveNormalize(name.toLowerCase());
7885 attrsMap[nName] = name;
7886 if (isNgAttr || !attrs.hasOwnProperty(nName)) {
7887 attrs[nName] = value;
7888 if (getBooleanAttrName(node, nName)) {
7889 attrs[nName] = true; // presence means true
7892 addAttrInterpolateDirective(node, directives, value, nName, isNgAttr);
7893 addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName,
7897 // use class as directive
7898 className = node.className;
7899 if (isObject(className)) {
7900 // Maybe SVGAnimatedString
7901 className = className.animVal;
7903 if (isString(className) && className !== '') {
7904 while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) {
7905 nName = directiveNormalize(match[2]);
7906 if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) {
7907 attrs[nName] = trim(match[3]);
7909 className = className.substr(match.index + match[0].length);
7913 case NODE_TYPE_TEXT: /* Text Node */
7915 // Workaround for #11781
7916 while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === NODE_TYPE_TEXT) {
7917 node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
7918 node.parentNode.removeChild(node.nextSibling);
7921 addTextInterpolateDirective(directives, node.nodeValue);
7923 case NODE_TYPE_COMMENT: /* Comment */
7925 match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
7927 nName = directiveNormalize(match[1]);
7928 if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
7929 attrs[nName] = trim(match[2]);
7933 // turns out that under some circumstances IE9 throws errors when one attempts to read
7934 // comment's node value.
7935 // Just ignore it and continue. (Can't seem to reproduce in test case.)
7940 directives.sort(byPriority);
7945 * Given a node with an directive-start it collects all of the siblings until it finds
7952 function groupScan(node, attrStart, attrEnd) {
7955 if (attrStart && node.hasAttribute && node.hasAttribute(attrStart)) {
7958 throw $compileMinErr('uterdir',
7959 "Unterminated attribute, found '{0}' but no matching '{1}' found.",
7960 attrStart, attrEnd);
7962 if (node.nodeType == NODE_TYPE_ELEMENT) {
7963 if (node.hasAttribute(attrStart)) depth++;
7964 if (node.hasAttribute(attrEnd)) depth--;
7967 node = node.nextSibling;
7968 } while (depth > 0);
7973 return jqLite(nodes);
7977 * Wrapper for linking function which converts normal linking function into a grouped
7982 * @returns {Function}
7984 function groupElementsLinkFnWrapper(linkFn, attrStart, attrEnd) {
7985 return function(scope, element, attrs, controllers, transcludeFn) {
7986 element = groupScan(element[0], attrStart, attrEnd);
7987 return linkFn(scope, element, attrs, controllers, transcludeFn);
7992 * Once the directives have been collected, their compile functions are executed. This method
7993 * is responsible for inlining directive templates as well as terminating the application
7994 * of the directives if the terminal directive has been reached.
7996 * @param {Array} directives Array of collected directives to execute their compile function.
7997 * this needs to be pre-sorted by priority order.
7998 * @param {Node} compileNode The raw DOM node to apply the compile functions to
7999 * @param {Object} templateAttrs The shared attribute function
8000 * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
8001 * scope argument is auto-generated to the new
8002 * child of the transcluded parent scope.
8003 * @param {JQLite} jqCollection If we are working on the root of the compile tree then this
8004 * argument has the root jqLite array so that we can replace nodes
8006 * @param {Object=} originalReplaceDirective An optional directive that will be ignored when
8007 * compiling the transclusion.
8008 * @param {Array.<Function>} preLinkFns
8009 * @param {Array.<Function>} postLinkFns
8010 * @param {Object} previousCompileContext Context used for previous compilation of the current
8012 * @returns {Function} linkFn
8014 function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn,
8015 jqCollection, originalReplaceDirective, preLinkFns, postLinkFns,
8016 previousCompileContext) {
8017 previousCompileContext = previousCompileContext || {};
8019 var terminalPriority = -Number.MAX_VALUE,
8020 newScopeDirective = previousCompileContext.newScopeDirective,
8021 controllerDirectives = previousCompileContext.controllerDirectives,
8022 newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective,
8023 templateDirective = previousCompileContext.templateDirective,
8024 nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective,
8025 hasTranscludeDirective = false,
8026 hasTemplate = false,
8027 hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective,
8028 $compileNode = templateAttrs.$$element = jqLite(compileNode),
8032 replaceDirective = originalReplaceDirective,
8033 childTranscludeFn = transcludeFn,
8037 // executes all directives on the current element
8038 for (var i = 0, ii = directives.length; i < ii; i++) {
8039 directive = directives[i];
8040 var attrStart = directive.$$start;
8041 var attrEnd = directive.$$end;
8043 // collect multiblock sections
8045 $compileNode = groupScan(compileNode, attrStart, attrEnd);
8047 $template = undefined;
8049 if (terminalPriority > directive.priority) {
8050 break; // prevent further processing of directives
8053 if (directiveValue = directive.scope) {
8055 // skip the check for directives with async templates, we'll check the derived sync
8056 // directive when the template arrives
8057 if (!directive.templateUrl) {
8058 if (isObject(directiveValue)) {
8059 // This directive is trying to add an isolated scope.
8060 // Check that there is no scope of any kind already
8061 assertNoDuplicate('new/isolated scope', newIsolateScopeDirective || newScopeDirective,
8062 directive, $compileNode);
8063 newIsolateScopeDirective = directive;
8065 // This directive is trying to add a child scope.
8066 // Check that there is no isolated scope already
8067 assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive,
8072 newScopeDirective = newScopeDirective || directive;
8075 directiveName = directive.name;
8077 if (!directive.templateUrl && directive.controller) {
8078 directiveValue = directive.controller;
8079 controllerDirectives = controllerDirectives || createMap();
8080 assertNoDuplicate("'" + directiveName + "' controller",
8081 controllerDirectives[directiveName], directive, $compileNode);
8082 controllerDirectives[directiveName] = directive;
8085 if (directiveValue = directive.transclude) {
8086 hasTranscludeDirective = true;
8088 // Special case ngIf and ngRepeat so that we don't complain about duplicate transclusion.
8089 // This option should only be used by directives that know how to safely handle element transclusion,
8090 // where the transcluded nodes are added or replaced after linking.
8091 if (!directive.$$tlb) {
8092 assertNoDuplicate('transclusion', nonTlbTranscludeDirective, directive, $compileNode);
8093 nonTlbTranscludeDirective = directive;
8096 if (directiveValue == 'element') {
8097 hasElementTranscludeDirective = true;
8098 terminalPriority = directive.priority;
8099 $template = $compileNode;
8100 $compileNode = templateAttrs.$$element =
8101 jqLite(document.createComment(' ' + directiveName + ': ' +
8102 templateAttrs[directiveName] + ' '));
8103 compileNode = $compileNode[0];
8104 replaceWith(jqCollection, sliceArgs($template), compileNode);
8106 childTranscludeFn = compile($template, transcludeFn, terminalPriority,
8107 replaceDirective && replaceDirective.name, {
8109 // - controllerDirectives - otherwise we'll create duplicates controllers
8110 // - newIsolateScopeDirective or templateDirective - combining templates with
8111 // element transclusion doesn't make sense.
8113 // We need only nonTlbTranscludeDirective so that we prevent putting transclusion
8114 // on the same element more than once.
8115 nonTlbTranscludeDirective: nonTlbTranscludeDirective
8118 $template = jqLite(jqLiteClone(compileNode)).contents();
8119 $compileNode.empty(); // clear contents
8120 childTranscludeFn = compile($template, transcludeFn, undefined,
8121 undefined, { needsNewScope: directive.$$isolateScope || directive.$$newScope});
8125 if (directive.template) {
8127 assertNoDuplicate('template', templateDirective, directive, $compileNode);
8128 templateDirective = directive;
8130 directiveValue = (isFunction(directive.template))
8131 ? directive.template($compileNode, templateAttrs)
8132 : directive.template;
8134 directiveValue = denormalizeTemplate(directiveValue);
8136 if (directive.replace) {
8137 replaceDirective = directive;
8138 if (jqLiteIsTextNode(directiveValue)) {
8141 $template = removeComments(wrapTemplate(directive.templateNamespace, trim(directiveValue)));
8143 compileNode = $template[0];
8145 if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
8146 throw $compileMinErr('tplrt',
8147 "Template for directive '{0}' must have exactly one root element. {1}",
8151 replaceWith(jqCollection, $compileNode, compileNode);
8153 var newTemplateAttrs = {$attr: {}};
8155 // combine directives from the original node and from the template:
8156 // - take the array of directives for this element
8157 // - split it into two parts, those that already applied (processed) and those that weren't (unprocessed)
8158 // - collect directives from the template and sort them by priority
8159 // - combine directives as: processed + template + unprocessed
8160 var templateDirectives = collectDirectives(compileNode, [], newTemplateAttrs);
8161 var unprocessedDirectives = directives.splice(i + 1, directives.length - (i + 1));
8163 if (newIsolateScopeDirective || newScopeDirective) {
8164 // The original directive caused the current element to be replaced but this element
8165 // also needs to have a new scope, so we need to tell the template directives
8166 // that they would need to get their scope from further up, if they require transclusion
8167 markDirectiveScope(templateDirectives, newIsolateScopeDirective, newScopeDirective);
8169 directives = directives.concat(templateDirectives).concat(unprocessedDirectives);
8170 mergeTemplateAttributes(templateAttrs, newTemplateAttrs);
8172 ii = directives.length;
8174 $compileNode.html(directiveValue);
8178 if (directive.templateUrl) {
8180 assertNoDuplicate('template', templateDirective, directive, $compileNode);
8181 templateDirective = directive;
8183 if (directive.replace) {
8184 replaceDirective = directive;
8187 nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
8188 templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
8189 controllerDirectives: controllerDirectives,
8190 newScopeDirective: (newScopeDirective !== directive) && newScopeDirective,
8191 newIsolateScopeDirective: newIsolateScopeDirective,
8192 templateDirective: templateDirective,
8193 nonTlbTranscludeDirective: nonTlbTranscludeDirective
8195 ii = directives.length;
8196 } else if (directive.compile) {
8198 linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn);
8199 if (isFunction(linkFn)) {
8200 addLinkFns(null, linkFn, attrStart, attrEnd);
8201 } else if (linkFn) {
8202 addLinkFns(linkFn.pre, linkFn.post, attrStart, attrEnd);
8205 $exceptionHandler(e, startingTag($compileNode));
8209 if (directive.terminal) {
8210 nodeLinkFn.terminal = true;
8211 terminalPriority = Math.max(terminalPriority, directive.priority);
8216 nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true;
8217 nodeLinkFn.transcludeOnThisElement = hasTranscludeDirective;
8218 nodeLinkFn.templateOnThisElement = hasTemplate;
8219 nodeLinkFn.transclude = childTranscludeFn;
8221 previousCompileContext.hasElementTranscludeDirective = hasElementTranscludeDirective;
8223 // might be normal or delayed nodeLinkFn depending on if templateUrl is present
8226 ////////////////////
8228 function addLinkFns(pre, post, attrStart, attrEnd) {
8230 if (attrStart) pre = groupElementsLinkFnWrapper(pre, attrStart, attrEnd);
8231 pre.require = directive.require;
8232 pre.directiveName = directiveName;
8233 if (newIsolateScopeDirective === directive || directive.$$isolateScope) {
8234 pre = cloneAndAnnotateFn(pre, {isolateScope: true});
8236 preLinkFns.push(pre);
8239 if (attrStart) post = groupElementsLinkFnWrapper(post, attrStart, attrEnd);
8240 post.require = directive.require;
8241 post.directiveName = directiveName;
8242 if (newIsolateScopeDirective === directive || directive.$$isolateScope) {
8243 post = cloneAndAnnotateFn(post, {isolateScope: true});
8245 postLinkFns.push(post);
8250 function getControllers(directiveName, require, $element, elementControllers) {
8253 if (isString(require)) {
8254 var match = require.match(REQUIRE_PREFIX_REGEXP);
8255 var name = require.substring(match[0].length);
8256 var inheritType = match[1] || match[3];
8257 var optional = match[2] === '?';
8259 //If only parents then start at the parent element
8260 if (inheritType === '^^') {
8261 $element = $element.parent();
8262 //Otherwise attempt getting the controller from elementControllers in case
8263 //the element is transcluded (and has no data) and to avoid .data if possible
8265 value = elementControllers && elementControllers[name];
8266 value = value && value.instance;
8270 var dataName = '$' + name + 'Controller';
8271 value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
8274 if (!value && !optional) {
8275 throw $compileMinErr('ctreq',
8276 "Controller '{0}', required by directive '{1}', can't be found!",
8277 name, directiveName);
8279 } else if (isArray(require)) {
8281 for (var i = 0, ii = require.length; i < ii; i++) {
8282 value[i] = getControllers(directiveName, require[i], $element, elementControllers);
8286 return value || null;
8289 function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope) {
8290 var elementControllers = createMap();
8291 for (var controllerKey in controllerDirectives) {
8292 var directive = controllerDirectives[controllerKey];
8294 $scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
8297 $transclude: transcludeFn
8300 var controller = directive.controller;
8301 if (controller == '@') {
8302 controller = attrs[directive.name];
8305 var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
8307 // For directives with element transclusion the element is a comment,
8308 // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
8309 // clean up (http://bugs.jquery.com/ticket/8335).
8310 // Instead, we save the controllers for the element in a local hash and attach to .data
8311 // later, once we have the actual element.
8312 elementControllers[directive.name] = controllerInstance;
8313 if (!hasElementTranscludeDirective) {
8314 $element.data('$' + directive.name + 'Controller', controllerInstance.instance);
8317 return elementControllers;
8320 function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
8321 var linkFn, isolateScope, controllerScope, elementControllers, transcludeFn, $element,
8322 attrs, removeScopeBindingWatches, removeControllerBindingWatches;
8324 if (compileNode === linkNode) {
8325 attrs = templateAttrs;
8326 $element = templateAttrs.$$element;
8328 $element = jqLite(linkNode);
8329 attrs = new Attributes($element, templateAttrs);
8332 controllerScope = scope;
8333 if (newIsolateScopeDirective) {
8334 isolateScope = scope.$new(true);
8335 } else if (newScopeDirective) {
8336 controllerScope = scope.$parent;
8339 if (boundTranscludeFn) {
8340 // track `boundTranscludeFn` so it can be unwrapped if `transcludeFn`
8341 // is later passed as `parentBoundTranscludeFn` to `publicLinkFn`
8342 transcludeFn = controllersBoundTransclude;
8343 transcludeFn.$$boundTransclude = boundTranscludeFn;
8346 if (controllerDirectives) {
8347 elementControllers = setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope);
8350 if (newIsolateScopeDirective) {
8351 // Initialize isolate scope bindings for new isolate scope directive.
8352 compile.$$addScopeInfo($element, isolateScope, true, !(templateDirective && (templateDirective === newIsolateScopeDirective ||
8353 templateDirective === newIsolateScopeDirective.$$originalDirective)));
8354 compile.$$addScopeClass($element, true);
8355 isolateScope.$$isolateBindings =
8356 newIsolateScopeDirective.$$isolateBindings;
8357 removeScopeBindingWatches = initializeDirectiveBindings(scope, attrs, isolateScope,
8358 isolateScope.$$isolateBindings,
8359 newIsolateScopeDirective);
8360 if (removeScopeBindingWatches) {
8361 isolateScope.$on('$destroy', removeScopeBindingWatches);
8365 // Initialize bindToController bindings
8366 for (var name in elementControllers) {
8367 var controllerDirective = controllerDirectives[name];
8368 var controller = elementControllers[name];
8369 var bindings = controllerDirective.$$bindings.bindToController;
8371 if (controller.identifier && bindings) {
8372 removeControllerBindingWatches =
8373 initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
8376 var controllerResult = controller();
8377 if (controllerResult !== controller.instance) {
8378 // If the controller constructor has a return value, overwrite the instance
8379 // from setupControllers
8380 controller.instance = controllerResult;
8381 $element.data('$' + controllerDirective.name + 'Controller', controllerResult);
8382 removeControllerBindingWatches && removeControllerBindingWatches();
8383 removeControllerBindingWatches =
8384 initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
8389 for (i = 0, ii = preLinkFns.length; i < ii; i++) {
8390 linkFn = preLinkFns[i];
8391 invokeLinkFn(linkFn,
8392 linkFn.isolateScope ? isolateScope : scope,
8395 linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
8401 // We only pass the isolate scope, if the isolate directive has a template,
8402 // otherwise the child elements do not belong to the isolate directive.
8403 var scopeToChild = scope;
8404 if (newIsolateScopeDirective && (newIsolateScopeDirective.template || newIsolateScopeDirective.templateUrl === null)) {
8405 scopeToChild = isolateScope;
8407 childLinkFn && childLinkFn(scopeToChild, linkNode.childNodes, undefined, boundTranscludeFn);
8410 for (i = postLinkFns.length - 1; i >= 0; i--) {
8411 linkFn = postLinkFns[i];
8412 invokeLinkFn(linkFn,
8413 linkFn.isolateScope ? isolateScope : scope,
8416 linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
8421 // This is the function that is injected as `$transclude`.
8422 // Note: all arguments are optional!
8423 function controllersBoundTransclude(scope, cloneAttachFn, futureParentElement) {
8424 var transcludeControllers;
8426 // No scope passed in:
8427 if (!isScope(scope)) {
8428 futureParentElement = cloneAttachFn;
8429 cloneAttachFn = scope;
8433 if (hasElementTranscludeDirective) {
8434 transcludeControllers = elementControllers;
8436 if (!futureParentElement) {
8437 futureParentElement = hasElementTranscludeDirective ? $element.parent() : $element;
8439 return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);
8444 // Depending upon the context in which a directive finds itself it might need to have a new isolated
8445 // or child scope created. For instance:
8446 // * if the directive has been pulled into a template because another directive with a higher priority
8447 // asked for element transclusion
8448 // * if the directive itself asks for transclusion but it is at the root of a template and the original
8449 // element was replaced. See https://github.com/angular/angular.js/issues/12936
8450 function markDirectiveScope(directives, isolateScope, newScope) {
8451 for (var j = 0, jj = directives.length; j < jj; j++) {
8452 directives[j] = inherit(directives[j], {$$isolateScope: isolateScope, $$newScope: newScope});
8457 * looks up the directive and decorates it with exception handling and proper parameters. We
8458 * call this the boundDirective.
8460 * @param {string} name name of the directive to look up.
8461 * @param {string} location The directive must be found in specific format.
8462 * String containing any of theses characters:
8464 * * `E`: element name
8468 * @returns {boolean} true if directive was added.
8470 function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName,
8472 if (name === ignoreDirective) return null;
8474 if (hasDirectives.hasOwnProperty(name)) {
8475 for (var directive, directives = $injector.get(name + Suffix),
8476 i = 0, ii = directives.length; i < ii; i++) {
8478 directive = directives[i];
8479 if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
8480 directive.restrict.indexOf(location) != -1) {
8481 if (startAttrName) {
8482 directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
8484 tDirectives.push(directive);
8487 } catch (e) { $exceptionHandler(e); }
8495 * looks up the directive and returns true if it is a multi-element directive,
8496 * and therefore requires DOM nodes between -start and -end markers to be grouped
8499 * @param {string} name name of the directive to look up.
8500 * @returns true if directive was registered as multi-element.
8502 function directiveIsMultiElement(name) {
8503 if (hasDirectives.hasOwnProperty(name)) {
8504 for (var directive, directives = $injector.get(name + Suffix),
8505 i = 0, ii = directives.length; i < ii; i++) {
8506 directive = directives[i];
8507 if (directive.multiElement) {
8516 * When the element is replaced with HTML template then the new attributes
8517 * on the template need to be merged with the existing attributes in the DOM.
8518 * The desired effect is to have both of the attributes present.
8520 * @param {object} dst destination attributes (original DOM)
8521 * @param {object} src source attributes (from the directive template)
8523 function mergeTemplateAttributes(dst, src) {
8524 var srcAttr = src.$attr,
8525 dstAttr = dst.$attr,
8526 $element = dst.$$element;
8528 // reapply the old attributes to the new element
8529 forEach(dst, function(value, key) {
8530 if (key.charAt(0) != '$') {
8531 if (src[key] && src[key] !== value) {
8532 value += (key === 'style' ? ';' : ' ') + src[key];
8534 dst.$set(key, value, true, srcAttr[key]);
8538 // copy the new attributes on the old attrs object
8539 forEach(src, function(value, key) {
8540 if (key == 'class') {
8541 safeAddClass($element, value);
8542 dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
8543 } else if (key == 'style') {
8544 $element.attr('style', $element.attr('style') + ';' + value);
8545 dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value;
8546 // `dst` will never contain hasOwnProperty as DOM parser won't let it.
8547 // You will get an "InvalidCharacterError: DOM Exception 5" error if you
8548 // have an attribute like "has-own-property" or "data-has-own-property", etc.
8549 } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
8551 dstAttr[key] = srcAttr[key];
8557 function compileTemplateUrl(directives, $compileNode, tAttrs,
8558 $rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) {
8560 afterTemplateNodeLinkFn,
8561 afterTemplateChildLinkFn,
8562 beforeTemplateCompileNode = $compileNode[0],
8563 origAsyncDirective = directives.shift(),
8564 derivedSyncDirective = inherit(origAsyncDirective, {
8565 templateUrl: null, transclude: null, replace: null, $$originalDirective: origAsyncDirective
8567 templateUrl = (isFunction(origAsyncDirective.templateUrl))
8568 ? origAsyncDirective.templateUrl($compileNode, tAttrs)
8569 : origAsyncDirective.templateUrl,
8570 templateNamespace = origAsyncDirective.templateNamespace;
8572 $compileNode.empty();
8574 $templateRequest(templateUrl)
8575 .then(function(content) {
8576 var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn;
8578 content = denormalizeTemplate(content);
8580 if (origAsyncDirective.replace) {
8581 if (jqLiteIsTextNode(content)) {
8584 $template = removeComments(wrapTemplate(templateNamespace, trim(content)));
8586 compileNode = $template[0];
8588 if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
8589 throw $compileMinErr('tplrt',
8590 "Template for directive '{0}' must have exactly one root element. {1}",
8591 origAsyncDirective.name, templateUrl);
8594 tempTemplateAttrs = {$attr: {}};
8595 replaceWith($rootElement, $compileNode, compileNode);
8596 var templateDirectives = collectDirectives(compileNode, [], tempTemplateAttrs);
8598 if (isObject(origAsyncDirective.scope)) {
8599 // the original directive that caused the template to be loaded async required
8601 markDirectiveScope(templateDirectives, true);
8603 directives = templateDirectives.concat(directives);
8604 mergeTemplateAttributes(tAttrs, tempTemplateAttrs);
8606 compileNode = beforeTemplateCompileNode;
8607 $compileNode.html(content);
8610 directives.unshift(derivedSyncDirective);
8612 afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs,
8613 childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns,
8614 previousCompileContext);
8615 forEach($rootElement, function(node, i) {
8616 if (node == compileNode) {
8617 $rootElement[i] = $compileNode[0];
8620 afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);
8622 while (linkQueue.length) {
8623 var scope = linkQueue.shift(),
8624 beforeTemplateLinkNode = linkQueue.shift(),
8625 linkRootElement = linkQueue.shift(),
8626 boundTranscludeFn = linkQueue.shift(),
8627 linkNode = $compileNode[0];
8629 if (scope.$$destroyed) continue;
8631 if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {
8632 var oldClasses = beforeTemplateLinkNode.className;
8634 if (!(previousCompileContext.hasElementTranscludeDirective &&
8635 origAsyncDirective.replace)) {
8636 // it was cloned therefore we have to clone as well.
8637 linkNode = jqLiteClone(compileNode);
8639 replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
8641 // Copy in CSS classes from original node
8642 safeAddClass(jqLite(linkNode), oldClasses);
8644 if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
8645 childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
8647 childBoundTranscludeFn = boundTranscludeFn;
8649 afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,
8650 childBoundTranscludeFn);
8655 return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
8656 var childBoundTranscludeFn = boundTranscludeFn;
8657 if (scope.$$destroyed) return;
8659 linkQueue.push(scope,
8662 childBoundTranscludeFn);
8664 if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
8665 childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
8667 afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn);
8674 * Sorting function for bound directives.
8676 function byPriority(a, b) {
8677 var diff = b.priority - a.priority;
8678 if (diff !== 0) return diff;
8679 if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;
8680 return a.index - b.index;
8683 function assertNoDuplicate(what, previousDirective, directive, element) {
8685 function wrapModuleNameIfDefined(moduleName) {
8687 (' (module: ' + moduleName + ')') :
8691 if (previousDirective) {
8692 throw $compileMinErr('multidir', 'Multiple directives [{0}{1}, {2}{3}] asking for {4} on: {5}',
8693 previousDirective.name, wrapModuleNameIfDefined(previousDirective.$$moduleName),
8694 directive.name, wrapModuleNameIfDefined(directive.$$moduleName), what, startingTag(element));
8699 function addTextInterpolateDirective(directives, text) {
8700 var interpolateFn = $interpolate(text, true);
8701 if (interpolateFn) {
8704 compile: function textInterpolateCompileFn(templateNode) {
8705 var templateNodeParent = templateNode.parent(),
8706 hasCompileParent = !!templateNodeParent.length;
8708 // When transcluding a template that has bindings in the root
8709 // we don't have a parent and thus need to add the class during linking fn.
8710 if (hasCompileParent) compile.$$addBindingClass(templateNodeParent);
8712 return function textInterpolateLinkFn(scope, node) {
8713 var parent = node.parent();
8714 if (!hasCompileParent) compile.$$addBindingClass(parent);
8715 compile.$$addBindingInfo(parent, interpolateFn.expressions);
8716 scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
8717 node[0].nodeValue = value;
8726 function wrapTemplate(type, template) {
8727 type = lowercase(type || 'html');
8731 var wrapper = document.createElement('div');
8732 wrapper.innerHTML = '<' + type + '>' + template + '</' + type + '>';
8733 return wrapper.childNodes[0].childNodes;
8740 function getTrustedContext(node, attrNormalizedName) {
8741 if (attrNormalizedName == "srcdoc") {
8744 var tag = nodeName_(node);
8745 // maction[xlink:href] can source SVG. It's not limited to <maction>.
8746 if (attrNormalizedName == "xlinkHref" ||
8747 (tag == "form" && attrNormalizedName == "action") ||
8748 (tag != "img" && (attrNormalizedName == "src" ||
8749 attrNormalizedName == "ngSrc"))) {
8750 return $sce.RESOURCE_URL;
8755 function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) {
8756 var trustedContext = getTrustedContext(node, name);
8757 allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing;
8759 var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing);
8761 // no interpolation found -> ignore
8762 if (!interpolateFn) return;
8765 if (name === "multiple" && nodeName_(node) === "select") {
8766 throw $compileMinErr("selmulti",
8767 "Binding to the 'multiple' attribute is not supported. Element: {0}",
8773 compile: function() {
8775 pre: function attrInterpolatePreLinkFn(scope, element, attr) {
8776 var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
8778 if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
8779 throw $compileMinErr('nodomevents',
8780 "Interpolations for HTML DOM event attributes are disallowed. Please use the " +
8781 "ng- versions (such as ng-click instead of onclick) instead.");
8784 // If the attribute has changed since last $interpolate()ed
8785 var newValue = attr[name];
8786 if (newValue !== value) {
8787 // we need to interpolate again since the attribute value has been updated
8788 // (e.g. by another directive's compile function)
8789 // ensure unset/empty values make interpolateFn falsy
8790 interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
8794 // if attribute was updated so that there is no interpolation going on we don't want to
8795 // register any observers
8796 if (!interpolateFn) return;
8798 // initialize attr object so that it's ready in case we need the value for isolate
8799 // scope initialization, otherwise the value would not be available from isolate
8800 // directive's linking fn during linking phase
8801 attr[name] = interpolateFn(scope);
8803 ($$observers[name] || ($$observers[name] = [])).$$inter = true;
8804 (attr.$$observers && attr.$$observers[name].$$scope || scope).
8805 $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
8806 //special case for class attribute addition + removal
8807 //so that class changes can tap into the animation
8808 //hooks provided by the $animate service. Be sure to
8809 //skip animations when the first digest occurs (when
8810 //both the new and the old values are the same) since
8811 //the CSS classes are the non-interpolated values
8812 if (name === 'class' && newValue != oldValue) {
8813 attr.$updateClass(newValue, oldValue);
8815 attr.$set(name, newValue);
8826 * This is a special jqLite.replaceWith, which can replace items which
8827 * have no parents, provided that the containing jqLite collection is provided.
8829 * @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes
8830 * in the root of the tree.
8831 * @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep
8832 * the shell, but replace its DOM node reference.
8833 * @param {Node} newNode The new DOM node.
8835 function replaceWith($rootElement, elementsToRemove, newNode) {
8836 var firstElementToRemove = elementsToRemove[0],
8837 removeCount = elementsToRemove.length,
8838 parent = firstElementToRemove.parentNode,
8842 for (i = 0, ii = $rootElement.length; i < ii; i++) {
8843 if ($rootElement[i] == firstElementToRemove) {
8844 $rootElement[i++] = newNode;
8845 for (var j = i, j2 = j + removeCount - 1,
8846 jj = $rootElement.length;
8847 j < jj; j++, j2++) {
8849 $rootElement[j] = $rootElement[j2];
8851 delete $rootElement[j];
8854 $rootElement.length -= removeCount - 1;
8856 // If the replaced element is also the jQuery .context then replace it
8857 // .context is a deprecated jQuery api, so we should set it only when jQuery set it
8858 // http://api.jquery.com/context/
8859 if ($rootElement.context === firstElementToRemove) {
8860 $rootElement.context = newNode;
8868 parent.replaceChild(newNode, firstElementToRemove);
8871 // TODO(perf): what's this document fragment for? is it needed? can we at least reuse it?
8872 var fragment = document.createDocumentFragment();
8873 fragment.appendChild(firstElementToRemove);
8875 if (jqLite.hasData(firstElementToRemove)) {
8876 // Copy over user data (that includes Angular's $scope etc.). Don't copy private
8877 // data here because there's no public interface in jQuery to do that and copying over
8878 // event listeners (which is the main use of private data) wouldn't work anyway.
8879 jqLite.data(newNode, jqLite.data(firstElementToRemove));
8881 // Remove data of the replaced element. We cannot just call .remove()
8882 // on the element it since that would deallocate scope that is needed
8883 // for the new node. Instead, remove the data "manually".
8885 delete jqLite.cache[firstElementToRemove[jqLite.expando]];
8887 // jQuery 2.x doesn't expose the data storage. Use jQuery.cleanData to clean up after
8888 // the replaced element. The cleanData version monkey-patched by Angular would cause
8889 // the scope to be trashed and we do need the very same scope to work with the new
8890 // element. However, we cannot just cache the non-patched version and use it here as
8891 // that would break if another library patches the method after Angular does (one
8892 // example is jQuery UI). Instead, set a flag indicating scope destroying should be
8893 // skipped this one time.
8894 skipDestroyOnNextJQueryCleanData = true;
8895 jQuery.cleanData([firstElementToRemove]);
8899 for (var k = 1, kk = elementsToRemove.length; k < kk; k++) {
8900 var element = elementsToRemove[k];
8901 jqLite(element).remove(); // must do this way to clean up expando
8902 fragment.appendChild(element);
8903 delete elementsToRemove[k];
8906 elementsToRemove[0] = newNode;
8907 elementsToRemove.length = 1;
8911 function cloneAndAnnotateFn(fn, annotation) {
8912 return extend(function() { return fn.apply(null, arguments); }, fn, annotation);
8916 function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) {
8918 linkFn(scope, $element, attrs, controllers, transcludeFn);
8920 $exceptionHandler(e, startingTag($element));
8925 // Set up $watches for isolate scope and controller bindings. This process
8926 // only occurs for isolate scopes and new scopes with controllerAs.
8927 function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
8928 var removeWatchCollection = [];
8929 forEach(bindings, function(definition, scopeName) {
8930 var attrName = definition.attrName,
8931 optional = definition.optional,
8932 mode = definition.mode, // @, =, or &
8934 parentGet, parentSet, compare;
8939 if (!optional && !hasOwnProperty.call(attrs, attrName)) {
8940 destination[scopeName] = attrs[attrName] = void 0;
8942 attrs.$observe(attrName, function(value) {
8943 if (isString(value)) {
8944 destination[scopeName] = value;
8947 attrs.$$observers[attrName].$$scope = scope;
8948 if (isString(attrs[attrName])) {
8949 // If the attribute has been provided then we trigger an interpolation to ensure
8950 // the value is there for use in the link fn
8951 destination[scopeName] = $interpolate(attrs[attrName])(scope);
8956 if (!hasOwnProperty.call(attrs, attrName)) {
8957 if (optional) break;
8958 attrs[attrName] = void 0;
8960 if (optional && !attrs[attrName]) break;
8962 parentGet = $parse(attrs[attrName]);
8963 if (parentGet.literal) {
8966 compare = function(a, b) { return a === b || (a !== a && b !== b); };
8968 parentSet = parentGet.assign || function() {
8969 // reset the change, or we will throw this exception on every $digest
8970 lastValue = destination[scopeName] = parentGet(scope);
8971 throw $compileMinErr('nonassign',
8972 "Expression '{0}' used with directive '{1}' is non-assignable!",
8973 attrs[attrName], directive.name);
8975 lastValue = destination[scopeName] = parentGet(scope);
8976 var parentValueWatch = function parentValueWatch(parentValue) {
8977 if (!compare(parentValue, destination[scopeName])) {
8978 // we are out of sync and need to copy
8979 if (!compare(parentValue, lastValue)) {
8980 // parent changed and it has precedence
8981 destination[scopeName] = parentValue;
8983 // if the parent can be assigned then do so
8984 parentSet(scope, parentValue = destination[scopeName]);
8987 return lastValue = parentValue;
8989 parentValueWatch.$stateful = true;
8991 if (definition.collection) {
8992 removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
8994 removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
8996 removeWatchCollection.push(removeWatch);
9000 // Don't assign Object.prototype method to scope
9001 parentGet = attrs.hasOwnProperty(attrName) ? $parse(attrs[attrName]) : noop;
9003 // Don't assign noop to destination if expression is not valid
9004 if (parentGet === noop && optional) break;
9006 destination[scopeName] = function(locals) {
9007 return parentGet(scope, locals);
9013 return removeWatchCollection.length && function removeWatches() {
9014 for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {
9015 removeWatchCollection[i]();
9022 var PREFIX_REGEXP = /^((?:x|data)[\:\-_])/i;
9024 * Converts all accepted directives format into proper directive name.
9025 * @param name Name to normalize
9027 function directiveNormalize(name) {
9028 return camelCase(name.replace(PREFIX_REGEXP, ''));
9033 * @name $compile.directive.Attributes
9036 * A shared object between directive compile / linking functions which contains normalized DOM
9037 * element attributes. The values reflect current binding state `{{ }}`. The normalization is
9038 * needed since all of these are treated as equivalent in Angular:
9041 * <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">
9047 * @name $compile.directive.Attributes#$attr
9050 * A map of DOM element attribute names to the normalized name. This is
9051 * needed to do reverse lookup from normalized name back to actual name.
9057 * @name $compile.directive.Attributes#$set
9061 * Set DOM element attribute value.
9064 * @param {string} name Normalized element attribute name of the property to modify. The name is
9065 * reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
9066 * property to the original name.
9067 * @param {string} value Value to set the attribute to. The value can be an interpolated string.
9073 * Closure compiler type information
9076 function nodesetLinkingFn(
9077 /* angular.Scope */ scope,
9078 /* NodeList */ nodeList,
9079 /* Element */ rootElement,
9080 /* function(Function) */ boundTranscludeFn
9083 function directiveLinkingFn(
9084 /* nodesetLinkingFn */ nodesetLinkingFn,
9085 /* angular.Scope */ scope,
9087 /* Element */ rootElement,
9088 /* function(Function) */ boundTranscludeFn
9091 function tokenDifference(str1, str2) {
9093 tokens1 = str1.split(/\s+/),
9094 tokens2 = str2.split(/\s+/);
9097 for (var i = 0; i < tokens1.length; i++) {
9098 var token = tokens1[i];
9099 for (var j = 0; j < tokens2.length; j++) {
9100 if (token == tokens2[j]) continue outer;
9102 values += (values.length > 0 ? ' ' : '') + token;
9107 function removeComments(jqNodes) {
9108 jqNodes = jqLite(jqNodes);
9109 var i = jqNodes.length;
9116 var node = jqNodes[i];
9117 if (node.nodeType === NODE_TYPE_COMMENT) {
9118 splice.call(jqNodes, i, 1);
9124 var $controllerMinErr = minErr('$controller');
9127 var CNTRL_REG = /^(\S+)(\s+as\s+(\w+))?$/;
9128 function identifierForController(controller, ident) {
9129 if (ident && isString(ident)) return ident;
9130 if (isString(controller)) {
9131 var match = CNTRL_REG.exec(controller);
9132 if (match) return match[3];
9139 * @name $controllerProvider
9141 * The {@link ng.$controller $controller service} is used by Angular to create new
9144 * This provider allows controller registration via the
9145 * {@link ng.$controllerProvider#register register} method.
9147 function $ControllerProvider() {
9148 var controllers = {},
9153 * @name $controllerProvider#register
9154 * @param {string|Object} name Controller name, or an object map of controllers where the keys are
9155 * the names and the values are the constructors.
9156 * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI
9157 * annotations in the array notation).
9159 this.register = function(name, constructor) {
9160 assertNotHasOwnProperty(name, 'controller');
9161 if (isObject(name)) {
9162 extend(controllers, name);
9164 controllers[name] = constructor;
9170 * @name $controllerProvider#allowGlobals
9171 * @description If called, allows `$controller` to find controller constructors on `window`
9173 this.allowGlobals = function() {
9178 this.$get = ['$injector', '$window', function($injector, $window) {
9183 * @requires $injector
9185 * @param {Function|string} constructor If called with a function then it's considered to be the
9186 * controller constructor function. Otherwise it's considered to be a string which is used
9187 * to retrieve the controller constructor using the following steps:
9189 * * check if a controller with given name is registered via `$controllerProvider`
9190 * * check if evaluating the string on the current scope returns a constructor
9191 * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global
9192 * `window` object (not recommended)
9194 * The string can use the `controller as property` syntax, where the controller instance is published
9195 * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
9196 * to work correctly.
9198 * @param {Object} locals Injection locals for Controller.
9199 * @return {Object} Instance of given controller.
9202 * `$controller` service is responsible for instantiating controllers.
9204 * It's just a simple call to {@link auto.$injector $injector}, but extracted into
9205 * a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
9207 return function(expression, locals, later, ident) {
9209 // param `later` --- indicates that the controller's constructor is invoked at a later time.
9210 // If true, $controller will allocate the object with the correct
9211 // prototype chain, but will not invoke the controller until a returned
9212 // callback is invoked.
9213 // param `ident` --- An optional label which overrides the label parsed from the controller
9214 // expression, if any.
9215 var instance, match, constructor, identifier;
9216 later = later === true;
9217 if (ident && isString(ident)) {
9221 if (isString(expression)) {
9222 match = expression.match(CNTRL_REG);
9224 throw $controllerMinErr('ctrlfmt',
9225 "Badly formed controller string '{0}'. " +
9226 "Must match `__name__ as __id__` or `__name__`.", expression);
9228 constructor = match[1],
9229 identifier = identifier || match[3];
9230 expression = controllers.hasOwnProperty(constructor)
9231 ? controllers[constructor]
9232 : getter(locals.$scope, constructor, true) ||
9233 (globals ? getter($window, constructor, true) : undefined);
9235 assertArgFn(expression, constructor, true);
9239 // Instantiate controller later:
9240 // This machinery is used to create an instance of the object before calling the
9241 // controller's constructor itself.
9243 // This allows properties to be added to the controller before the constructor is
9244 // invoked. Primarily, this is used for isolate scope bindings in $compile.
9246 // This feature is not intended for use by applications, and is thus not documented
9248 // Object creation: http://jsperf.com/create-constructor/2
9249 var controllerPrototype = (isArray(expression) ?
9250 expression[expression.length - 1] : expression).prototype;
9251 instance = Object.create(controllerPrototype || null);
9254 addIdentifier(locals, identifier, instance, constructor || expression.name);
9258 return instantiate = extend(function() {
9259 var result = $injector.invoke(expression, instance, locals, constructor);
9260 if (result !== instance && (isObject(result) || isFunction(result))) {
9263 // If result changed, re-assign controllerAs value to scope.
9264 addIdentifier(locals, identifier, instance, constructor || expression.name);
9270 identifier: identifier
9274 instance = $injector.instantiate(expression, locals, constructor);
9277 addIdentifier(locals, identifier, instance, constructor || expression.name);
9283 function addIdentifier(locals, identifier, instance, name) {
9284 if (!(locals && isObject(locals.$scope))) {
9285 throw minErr('$controller')('noscp',
9286 "Cannot export controller '{0}' as '{1}'! No $scope object provided via `locals`.",
9290 locals.$scope[identifier] = instance;
9301 * A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object.
9304 <example module="documentExample">
9305 <file name="index.html">
9306 <div ng-controller="ExampleController">
9307 <p>$document title: <b ng-bind="title"></b></p>
9308 <p>window.document title: <b ng-bind="windowTitle"></b></p>
9311 <file name="script.js">
9312 angular.module('documentExample', [])
9313 .controller('ExampleController', ['$scope', '$document', function($scope, $document) {
9314 $scope.title = $document[0].title;
9315 $scope.windowTitle = angular.element(window.document)[0].title;
9320 function $DocumentProvider() {
9321 this.$get = ['$window', function(window) {
9322 return jqLite(window.document);
9328 * @name $exceptionHandler
9332 * Any uncaught exception in angular expressions is delegated to this service.
9333 * The default implementation simply delegates to `$log.error` which logs it into
9334 * the browser console.
9336 * In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
9337 * {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing.
9342 * angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
9343 * return function(exception, cause) {
9344 * exception.message += ' (caused by "' + cause + '")';
9350 * This example will override the normal action of `$exceptionHandler`, to make angular
9351 * exceptions fail hard when they happen, instead of just logging to the console.
9354 * Note, that code executed in event-listeners (even those registered using jqLite's `on`/`bind`
9355 * methods) does not delegate exceptions to the {@link ng.$exceptionHandler $exceptionHandler}
9356 * (unless executed during a digest).
9358 * If you wish, you can manually delegate exceptions, e.g.
9359 * `try { ... } catch(e) { $exceptionHandler(e); }`
9361 * @param {Error} exception Exception associated with the error.
9362 * @param {string=} cause optional information about the context in which
9363 * the error was thrown.
9366 function $ExceptionHandlerProvider() {
9367 this.$get = ['$log', function($log) {
9368 return function(exception, cause) {
9369 $log.error.apply($log, arguments);
9374 var $$ForceReflowProvider = function() {
9375 this.$get = ['$document', function($document) {
9376 return function(domNode) {
9377 //the line below will force the browser to perform a repaint so
9378 //that all the animated elements within the animation frame will
9379 //be properly updated and drawn on screen. This is required to
9380 //ensure that the preparation animation is properly flushed so that
9381 //the active state picks up from there. DO NOT REMOVE THIS LINE.
9382 //DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH
9383 //WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND
9384 //WILL TAKE YEARS AWAY FROM YOUR LIFE.
9386 if (!domNode.nodeType && domNode instanceof jqLite) {
9387 domNode = domNode[0];
9390 domNode = $document[0].body;
9392 return domNode.offsetWidth + 1;
9397 var APPLICATION_JSON = 'application/json';
9398 var CONTENT_TYPE_APPLICATION_JSON = {'Content-Type': APPLICATION_JSON + ';charset=utf-8'};
9399 var JSON_START = /^\[|^\{(?!\{)/;
9404 var JSON_PROTECTION_PREFIX = /^\)\]\}',?\n/;
9405 var $httpMinErr = minErr('$http');
9406 var $httpMinErrLegacyFn = function(method) {
9408 throw $httpMinErr('legacy', 'The method `{0}` on the promise returned from `$http` has been disabled.', method);
9412 function serializeValue(v) {
9414 return isDate(v) ? v.toISOString() : toJson(v);
9420 function $HttpParamSerializerProvider() {
9423 * @name $httpParamSerializer
9426 * Default {@link $http `$http`} params serializer that converts objects to strings
9427 * according to the following rules:
9429 * * `{'foo': 'bar'}` results in `foo=bar`
9430 * * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
9431 * * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
9432 * * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D"` (stringified and encoded representation of an object)
9434 * Note that serializer will sort the request parameters alphabetically.
9437 this.$get = function() {
9438 return function ngParamSerializer(params) {
9439 if (!params) return '';
9441 forEachSorted(params, function(value, key) {
9442 if (value === null || isUndefined(value)) return;
9443 if (isArray(value)) {
9444 forEach(value, function(v, k) {
9445 parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(v)));
9448 parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(value)));
9452 return parts.join('&');
9457 function $HttpParamSerializerJQLikeProvider() {
9460 * @name $httpParamSerializerJQLike
9463 * Alternative {@link $http `$http`} params serializer that follows
9464 * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
9465 * The serializer will also sort the params alphabetically.
9467 * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
9474 * paramSerializer: '$httpParamSerializerJQLike'
9478 * It is also possible to set it as the default `paramSerializer` in the
9479 * {@link $httpProvider#defaults `$httpProvider`}.
9481 * Additionally, you can inject the serializer and use it explicitly, for example to serialize
9482 * form data for submission:
9485 * .controller(function($http, $httpParamSerializerJQLike) {
9491 * data: $httpParamSerializerJQLike(myData),
9493 * 'Content-Type': 'application/x-www-form-urlencoded'
9501 this.$get = function() {
9502 return function jQueryLikeParamSerializer(params) {
9503 if (!params) return '';
9505 serialize(params, '', true);
9506 return parts.join('&');
9508 function serialize(toSerialize, prefix, topLevel) {
9509 if (toSerialize === null || isUndefined(toSerialize)) return;
9510 if (isArray(toSerialize)) {
9511 forEach(toSerialize, function(value, index) {
9512 serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
9514 } else if (isObject(toSerialize) && !isDate(toSerialize)) {
9515 forEachSorted(toSerialize, function(value, key) {
9516 serialize(value, prefix +
9517 (topLevel ? '' : '[') +
9519 (topLevel ? '' : ']'));
9522 parts.push(encodeUriQuery(prefix) + '=' + encodeUriQuery(serializeValue(toSerialize)));
9529 function defaultHttpResponseTransform(data, headers) {
9530 if (isString(data)) {
9531 // Strip json vulnerability protection prefix and trim whitespace
9532 var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();
9535 var contentType = headers('Content-Type');
9536 if ((contentType && (contentType.indexOf(APPLICATION_JSON) === 0)) || isJsonLike(tempData)) {
9537 data = fromJson(tempData);
9545 function isJsonLike(str) {
9546 var jsonStart = str.match(JSON_START);
9547 return jsonStart && JSON_ENDS[jsonStart[0]].test(str);
9551 * Parse headers into key value object
9553 * @param {string} headers Raw headers as a string
9554 * @returns {Object} Parsed headers as key value object
9556 function parseHeaders(headers) {
9557 var parsed = createMap(), i;
9559 function fillInParsed(key, val) {
9561 parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
9565 if (isString(headers)) {
9566 forEach(headers.split('\n'), function(line) {
9567 i = line.indexOf(':');
9568 fillInParsed(lowercase(trim(line.substr(0, i))), trim(line.substr(i + 1)));
9570 } else if (isObject(headers)) {
9571 forEach(headers, function(headerVal, headerKey) {
9572 fillInParsed(lowercase(headerKey), trim(headerVal));
9581 * Returns a function that provides access to parsed headers.
9583 * Headers are lazy parsed when first requested.
9586 * @param {(string|Object)} headers Headers to provide access to.
9587 * @returns {function(string=)} Returns a getter function which if called with:
9589 * - if called with single an argument returns a single header value or null
9590 * - if called with no arguments returns an object containing all headers.
9592 function headersGetter(headers) {
9595 return function(name) {
9596 if (!headersObj) headersObj = parseHeaders(headers);
9599 var value = headersObj[lowercase(name)];
9600 if (value === void 0) {
9612 * Chain all given functions
9614 * This function is used for both request and response transforming
9616 * @param {*} data Data to transform.
9617 * @param {function(string=)} headers HTTP headers getter fn.
9618 * @param {number} status HTTP status code of the response.
9619 * @param {(Function|Array.<Function>)} fns Function or an array of functions.
9620 * @returns {*} Transformed data.
9622 function transformData(data, headers, status, fns) {
9623 if (isFunction(fns)) {
9624 return fns(data, headers, status);
9627 forEach(fns, function(fn) {
9628 data = fn(data, headers, status);
9635 function isSuccess(status) {
9636 return 200 <= status && status < 300;
9642 * @name $httpProvider
9644 * Use `$httpProvider` to change the default behavior of the {@link ng.$http $http} service.
9646 function $HttpProvider() {
9649 * @name $httpProvider#defaults
9652 * Object containing default values for all {@link ng.$http $http} requests.
9654 * - **`defaults.cache`** - {Object} - an object built with {@link ng.$cacheFactory `$cacheFactory`}
9655 * that will provide the cache for all requests who set their `cache` property to `true`.
9656 * If you set the `defaults.cache = false` then only requests that specify their own custom
9657 * cache object will be cached. See {@link $http#caching $http Caching} for more information.
9659 * - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token.
9660 * Defaults value is `'XSRF-TOKEN'`.
9662 * - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the
9663 * XSRF token. Defaults value is `'X-XSRF-TOKEN'`.
9665 * - **`defaults.headers`** - {Object} - Default headers for all $http requests.
9666 * Refer to {@link ng.$http#setting-http-headers $http} for documentation on
9667 * setting default headers.
9668 * - **`defaults.headers.common`**
9669 * - **`defaults.headers.post`**
9670 * - **`defaults.headers.put`**
9671 * - **`defaults.headers.patch`**
9674 * - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function
9675 * used to the prepare string representation of request parameters (specified as an object).
9676 * If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
9677 * Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
9680 var defaults = this.defaults = {
9681 // transform incoming response data
9682 transformResponse: [defaultHttpResponseTransform],
9684 // transform outgoing request data
9685 transformRequest: [function(d) {
9686 return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
9692 'Accept': 'application/json, text/plain, */*'
9694 post: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
9695 put: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
9696 patch: shallowCopy(CONTENT_TYPE_APPLICATION_JSON)
9699 xsrfCookieName: 'XSRF-TOKEN',
9700 xsrfHeaderName: 'X-XSRF-TOKEN',
9702 paramSerializer: '$httpParamSerializer'
9705 var useApplyAsync = false;
9708 * @name $httpProvider#useApplyAsync
9711 * Configure $http service to combine processing of multiple http responses received at around
9712 * the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in
9713 * significant performance improvement for bigger applications that make many HTTP requests
9714 * concurrently (common during application bootstrap).
9716 * Defaults to false. If no value is specified, returns the current configured value.
9718 * @param {boolean=} value If true, when requests are loaded, they will schedule a deferred
9719 * "apply" on the next tick, giving time for subsequent requests in a roughly ~10ms window
9720 * to load and share the same digest cycle.
9722 * @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining.
9723 * otherwise, returns the current configured value.
9725 this.useApplyAsync = function(value) {
9726 if (isDefined(value)) {
9727 useApplyAsync = !!value;
9730 return useApplyAsync;
9733 var useLegacyPromise = true;
9736 * @name $httpProvider#useLegacyPromiseExtensions
9739 * Configure `$http` service to return promises without the shorthand methods `success` and `error`.
9740 * This should be used to make sure that applications work without these methods.
9742 * Defaults to true. If no value is specified, returns the current configured value.
9744 * @param {boolean=} value If true, `$http` will return a promise with the deprecated legacy `success` and `error` methods.
9746 * @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining.
9747 * otherwise, returns the current configured value.
9749 this.useLegacyPromiseExtensions = function(value) {
9750 if (isDefined(value)) {
9751 useLegacyPromise = !!value;
9754 return useLegacyPromise;
9759 * @name $httpProvider#interceptors
9762 * Array containing service factories for all synchronous or asynchronous {@link ng.$http $http}
9763 * pre-processing of request or postprocessing of responses.
9765 * These service factories are ordered by request, i.e. they are applied in the same order as the
9766 * array, on request, but reverse order, on response.
9768 * {@link ng.$http#interceptors Interceptors detailed info}
9770 var interceptorFactories = this.interceptors = [];
9772 this.$get = ['$httpBackend', '$$cookieReader', '$cacheFactory', '$rootScope', '$q', '$injector',
9773 function($httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector) {
9775 var defaultCache = $cacheFactory('$http');
9778 * Make sure that default param serializer is exposed as a function
9780 defaults.paramSerializer = isString(defaults.paramSerializer) ?
9781 $injector.get(defaults.paramSerializer) : defaults.paramSerializer;
9784 * Interceptors stored in reverse order. Inner interceptors before outer interceptors.
9785 * The reversal is needed so that we can build up the interception chain around the
9788 var reversedInterceptors = [];
9790 forEach(interceptorFactories, function(interceptorFactory) {
9791 reversedInterceptors.unshift(isString(interceptorFactory)
9792 ? $injector.get(interceptorFactory) : $injector.invoke(interceptorFactory));
9799 * @requires ng.$httpBackend
9800 * @requires $cacheFactory
9801 * @requires $rootScope
9803 * @requires $injector
9806 * The `$http` service is a core Angular service that facilitates communication with the remote
9807 * HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
9808 * object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
9810 * For unit testing applications that use `$http` service, see
9811 * {@link ngMock.$httpBackend $httpBackend mock}.
9813 * For a higher level of abstraction, please check out the {@link ngResource.$resource
9814 * $resource} service.
9816 * The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by
9817 * the $q service. While for simple usage patterns this doesn't matter much, for advanced usage
9818 * it is important to familiarize yourself with these APIs and the guarantees they provide.
9822 * The `$http` service is a function which takes a single argument — a {@link $http#usage configuration object} —
9823 * that is used to generate an HTTP request and returns a {@link ng.$q promise}.
9826 * // Simple GET request example:
9830 * }).then(function successCallback(response) {
9831 * // this callback will be called asynchronously
9832 * // when the response is available
9833 * }, function errorCallback(response) {
9834 * // called asynchronously if an error occurs
9835 * // or server returns response with an error status.
9839 * The response object has these properties:
9841 * - **data** – `{string|Object}` – The response body transformed with the transform
9843 * - **status** – `{number}` – HTTP status code of the response.
9844 * - **headers** – `{function([headerName])}` – Header getter function.
9845 * - **config** – `{Object}` – The configuration object that was used to generate the request.
9846 * - **statusText** – `{string}` – HTTP status text of the response.
9848 * A response status code between 200 and 299 is considered a success status and
9849 * will result in the success callback being called. Note that if the response is a redirect,
9850 * XMLHttpRequest will transparently follow it, meaning that the error callback will not be
9851 * called for such responses.
9854 * ## Shortcut methods
9856 * Shortcut methods are also available. All shortcut methods require passing in the URL, and
9857 * request data must be passed in for POST/PUT requests. An optional config can be passed as the
9861 * $http.get('/someUrl', config).then(successCallback, errorCallback);
9862 * $http.post('/someUrl', data, config).then(successCallback, errorCallback);
9865 * Complete list of shortcut methods:
9867 * - {@link ng.$http#get $http.get}
9868 * - {@link ng.$http#head $http.head}
9869 * - {@link ng.$http#post $http.post}
9870 * - {@link ng.$http#put $http.put}
9871 * - {@link ng.$http#delete $http.delete}
9872 * - {@link ng.$http#jsonp $http.jsonp}
9873 * - {@link ng.$http#patch $http.patch}
9876 * ## Writing Unit Tests that use $http
9877 * When unit testing (using {@link ngMock ngMock}), it is necessary to call
9878 * {@link ngMock.$httpBackend#flush $httpBackend.flush()} to flush each pending
9879 * request using trained responses.
9882 * $httpBackend.expectGET(...);
9884 * $httpBackend.flush();
9887 * ## Deprecation Notice
9888 * <div class="alert alert-danger">
9889 * The `$http` legacy promise methods `success` and `error` have been deprecated.
9890 * Use the standard `then` method instead.
9891 * If {@link $httpProvider#useLegacyPromiseExtensions `$httpProvider.useLegacyPromiseExtensions`} is set to
9892 * `false` then these methods will throw {@link $http:legacy `$http/legacy`} error.
9895 * ## Setting HTTP Headers
9897 * The $http service will automatically add certain HTTP headers to all requests. These defaults
9898 * can be fully configured by accessing the `$httpProvider.defaults.headers` configuration
9899 * object, which currently contains this default configuration:
9901 * - `$httpProvider.defaults.headers.common` (headers that are common for all requests):
9902 * - `Accept: application/json, text/plain, * / *`
9903 * - `$httpProvider.defaults.headers.post`: (header defaults for POST requests)
9904 * - `Content-Type: application/json`
9905 * - `$httpProvider.defaults.headers.put` (header defaults for PUT requests)
9906 * - `Content-Type: application/json`
9908 * To add or overwrite these defaults, simply add or remove a property from these configuration
9909 * objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
9910 * with the lowercased HTTP method name as the key, e.g.
9911 * `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
9913 * The defaults can also be set at runtime via the `$http.defaults` object in the same
9914 * fashion. For example:
9917 * module.run(function($http) {
9918 * $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'
9922 * In addition, you can supply a `headers` property in the config object passed when
9923 * calling `$http(config)`, which overrides the defaults without changing them globally.
9925 * To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
9926 * Use the `headers` property, setting the desired header to `undefined`. For example:
9931 * url: 'http://example.com',
9933 * 'Content-Type': undefined
9935 * data: { test: 'test' }
9938 * $http(req).then(function(){...}, function(){...});
9941 * ## Transforming Requests and Responses
9943 * Both requests and responses can be transformed using transformation functions: `transformRequest`
9944 * and `transformResponse`. These properties can be a single function that returns
9945 * the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
9946 * which allows you to `push` or `unshift` a new transformation function into the transformation chain.
9948 * ### Default Transformations
9950 * The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
9951 * `defaults.transformResponse` properties. If a request does not provide its own transformations
9952 * then these will be applied.
9954 * You can augment or replace the default transformations by modifying these properties by adding to or
9955 * replacing the array.
9957 * Angular provides the following default transformations:
9959 * Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`):
9961 * - If the `data` property of the request configuration object contains an object, serialize it
9964 * Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`):
9966 * - If XSRF prefix is detected, strip it (see Security Considerations section below).
9967 * - If JSON response is detected, deserialize it using a JSON parser.
9970 * ### Overriding the Default Transformations Per Request
9972 * If you wish override the request/response transformations only for a single request then provide
9973 * `transformRequest` and/or `transformResponse` properties on the configuration object passed
9976 * Note that if you provide these properties on the config object the default transformations will be
9977 * overwritten. If you wish to augment the default transformations then you must include them in your
9978 * local transformation array.
9980 * The following code demonstrates adding a new response transformation to be run after the default response
9981 * transformations have been run.
9984 * function appendTransform(defaults, transform) {
9986 * // We can't guarantee that the default transformation is an array
9987 * defaults = angular.isArray(defaults) ? defaults : [defaults];
9989 * // Append the new transformation to the defaults
9990 * return defaults.concat(transform);
9996 * transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
9997 * return doTransform(value);
10005 * To enable caching, set the request configuration `cache` property to `true` (to use default
10006 * cache) or to a custom cache object (built with {@link ng.$cacheFactory `$cacheFactory`}).
10007 * When the cache is enabled, `$http` stores the response from the server in the specified
10008 * cache. The next time the same request is made, the response is served from the cache without
10009 * sending a request to the server.
10011 * Note that even if the response is served from cache, delivery of the data is asynchronous in
10012 * the same way that real requests are.
10014 * If there are multiple GET requests for the same URL that should be cached using the same
10015 * cache, but the cache is not populated yet, only one request to the server will be made and
10016 * the remaining requests will be fulfilled using the response from the first request.
10018 * You can change the default cache to a new object (built with
10019 * {@link ng.$cacheFactory `$cacheFactory`}) by updating the
10020 * {@link ng.$http#defaults `$http.defaults.cache`} property. All requests who set
10021 * their `cache` property to `true` will now use this cache object.
10023 * If you set the default cache to `false` then only requests that specify their own custom
10024 * cache object will be cached.
10028 * Before you start creating interceptors, be sure to understand the
10029 * {@link ng.$q $q and deferred/promise APIs}.
10031 * For purposes of global error handling, authentication, or any kind of synchronous or
10032 * asynchronous pre-processing of request or postprocessing of responses, it is desirable to be
10033 * able to intercept requests before they are handed to the server and
10034 * responses before they are handed over to the application code that
10035 * initiated these requests. The interceptors leverage the {@link ng.$q
10036 * promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
10038 * The interceptors are service factories that are registered with the `$httpProvider` by
10039 * adding them to the `$httpProvider.interceptors` array. The factory is called and
10040 * injected with dependencies (if specified) and returns the interceptor.
10042 * There are two kinds of interceptors (and two kinds of rejection interceptors):
10044 * * `request`: interceptors get called with a http {@link $http#usage config} object. The function is free to
10045 * modify the `config` object or create a new one. The function needs to return the `config`
10046 * object directly, or a promise containing the `config` or a new `config` object.
10047 * * `requestError`: interceptor gets called when a previous interceptor threw an error or
10048 * resolved with a rejection.
10049 * * `response`: interceptors get called with http `response` object. The function is free to
10050 * modify the `response` object or create a new one. The function needs to return the `response`
10051 * object directly, or as a promise containing the `response` or a new `response` object.
10052 * * `responseError`: interceptor gets called when a previous interceptor threw an error or
10053 * resolved with a rejection.
10057 * // register the interceptor as a service
10058 * $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
10060 * // optional method
10061 * 'request': function(config) {
10062 * // do something on success
10066 * // optional method
10067 * 'requestError': function(rejection) {
10068 * // do something on error
10069 * if (canRecover(rejection)) {
10070 * return responseOrNewPromise
10072 * return $q.reject(rejection);
10077 * // optional method
10078 * 'response': function(response) {
10079 * // do something on success
10083 * // optional method
10084 * 'responseError': function(rejection) {
10085 * // do something on error
10086 * if (canRecover(rejection)) {
10087 * return responseOrNewPromise
10089 * return $q.reject(rejection);
10094 * $httpProvider.interceptors.push('myHttpInterceptor');
10097 * // alternatively, register the interceptor via an anonymous factory
10098 * $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
10100 * 'request': function(config) {
10104 * 'response': function(response) {
10111 * ## Security Considerations
10113 * When designing web applications, consider security threats from:
10115 * - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
10116 * - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
10118 * Both server and the client must cooperate in order to eliminate these threats. Angular comes
10119 * pre-configured with strategies that address these issues, but for this to work backend server
10120 * cooperation is required.
10122 * ### JSON Vulnerability Protection
10124 * A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
10125 * allows third party website to turn your JSON resource URL into
10126 * [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
10127 * counter this your server can prefix all JSON requests with following string `")]}',\n"`.
10128 * Angular will automatically strip the prefix before processing it as JSON.
10130 * For example if your server needs to return:
10135 * which is vulnerable to attack, your server can return:
10141 * Angular will strip the prefix, before processing the JSON.
10144 * ### Cross Site Request Forgery (XSRF) Protection
10146 * [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is a technique by which
10147 * an unauthorized site can gain your user's private data. Angular provides a mechanism
10148 * to counter XSRF. When performing XHR requests, the $http service reads a token from a cookie
10149 * (by default, `XSRF-TOKEN`) and sets it as an HTTP header (`X-XSRF-TOKEN`). Since only
10150 * JavaScript that runs on your domain could read the cookie, your server can be assured that
10151 * the XHR came from JavaScript running on your domain. The header will not be set for
10152 * cross-domain requests.
10154 * To take advantage of this, your server needs to set a token in a JavaScript readable session
10155 * cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
10156 * server can verify that the cookie matches `X-XSRF-TOKEN` HTTP header, and therefore be sure
10157 * that only JavaScript running on your domain could have sent the request. The token must be
10158 * unique for each user and must be verifiable by the server (to prevent the JavaScript from
10159 * making up its own tokens). We recommend that the token is a digest of your site's
10160 * authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography))
10161 * for added security.
10163 * The name of the headers can be specified using the xsrfHeaderName and xsrfCookieName
10164 * properties of either $httpProvider.defaults at config-time, $http.defaults at run-time,
10165 * or the per-request config object.
10167 * In order to prevent collisions in environments where multiple Angular apps share the
10168 * same domain or subdomain, we recommend that each application uses unique cookie name.
10170 * @param {object} config Object describing the request to be made and how it should be
10171 * processed. The object has following properties:
10173 * - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
10174 * - **url** – `{string}` – Absolute or relative URL of the resource that is being requested.
10175 * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
10176 * with the `paramSerializer` and appended as GET parameters.
10177 * - **data** – `{string|Object}` – Data to be sent as the request message data.
10178 * - **headers** – `{Object}` – Map of strings or functions which return strings representing
10179 * HTTP headers to send to the server. If the return value of a function is null, the
10180 * header will not be sent. Functions accept a config object as an argument.
10181 * - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
10182 * - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
10183 * - **transformRequest** –
10184 * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
10185 * transform function or an array of such functions. The transform function takes the http
10186 * request body and headers and returns its transformed (typically serialized) version.
10187 * See {@link ng.$http#overriding-the-default-transformations-per-request
10188 * Overriding the Default Transformations}
10189 * - **transformResponse** –
10190 * `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` –
10191 * transform function or an array of such functions. The transform function takes the http
10192 * response body, headers and status and returns its transformed (typically deserialized) version.
10193 * See {@link ng.$http#overriding-the-default-transformations-per-request
10194 * Overriding the Default TransformationjqLiks}
10195 * - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
10196 * prepare the string representation of request parameters (specified as an object).
10197 * If specified as string, it is interpreted as function registered with the
10198 * {@link $injector $injector}, which means you can create your own serializer
10199 * by registering it as a {@link auto.$provide#service service}.
10200 * The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
10201 * alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike}
10202 * - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
10203 * GET request, otherwise if a cache instance built with
10204 * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
10206 * - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
10207 * that should abort the request when resolved.
10208 * - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
10209 * XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
10210 * for more information.
10211 * - **responseType** - `{string}` - see
10212 * [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
10214 * @returns {HttpPromise} Returns a {@link ng.$q `Promise}` that will be resolved to a response object
10215 * when the request succeeds or fails.
10218 * @property {Array.<Object>} pendingRequests Array of config objects for currently pending
10219 * requests. This is primarily meant to be used for debugging purposes.
10223 <example module="httpExample">
10224 <file name="index.html">
10225 <div ng-controller="FetchController">
10226 <select ng-model="method" aria-label="Request method">
10227 <option>GET</option>
10228 <option>JSONP</option>
10230 <input type="text" ng-model="url" size="80" aria-label="URL" />
10231 <button id="fetchbtn" ng-click="fetch()">fetch</button><br>
10232 <button id="samplegetbtn" ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button>
10233 <button id="samplejsonpbtn"
10234 ng-click="updateModel('JSONP',
10235 'https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">
10238 <button id="invalidjsonpbtn"
10239 ng-click="updateModel('JSONP', 'https://angularjs.org/doesntexist&callback=JSON_CALLBACK')">
10242 <pre>http status code: {{status}}</pre>
10243 <pre>http response data: {{data}}</pre>
10246 <file name="script.js">
10247 angular.module('httpExample', [])
10248 .controller('FetchController', ['$scope', '$http', '$templateCache',
10249 function($scope, $http, $templateCache) {
10250 $scope.method = 'GET';
10251 $scope.url = 'http-hello.html';
10253 $scope.fetch = function() {
10254 $scope.code = null;
10255 $scope.response = null;
10257 $http({method: $scope.method, url: $scope.url, cache: $templateCache}).
10258 then(function(response) {
10259 $scope.status = response.status;
10260 $scope.data = response.data;
10261 }, function(response) {
10262 $scope.data = response.data || "Request failed";
10263 $scope.status = response.status;
10267 $scope.updateModel = function(method, url) {
10268 $scope.method = method;
10273 <file name="http-hello.html">
10276 <file name="protractor.js" type="protractor">
10277 var status = element(by.binding('status'));
10278 var data = element(by.binding('data'));
10279 var fetchBtn = element(by.id('fetchbtn'));
10280 var sampleGetBtn = element(by.id('samplegetbtn'));
10281 var sampleJsonpBtn = element(by.id('samplejsonpbtn'));
10282 var invalidJsonpBtn = element(by.id('invalidjsonpbtn'));
10284 it('should make an xhr GET request', function() {
10285 sampleGetBtn.click();
10287 expect(status.getText()).toMatch('200');
10288 expect(data.getText()).toMatch(/Hello, \$http!/);
10291 // Commented out due to flakes. See https://github.com/angular/angular.js/issues/9185
10292 // it('should make a JSONP request to angularjs.org', function() {
10293 // sampleJsonpBtn.click();
10294 // fetchBtn.click();
10295 // expect(status.getText()).toMatch('200');
10296 // expect(data.getText()).toMatch(/Super Hero!/);
10299 it('should make JSONP request to invalid URL and invoke the error handler',
10301 invalidJsonpBtn.click();
10303 expect(status.getText()).toMatch('0');
10304 expect(data.getText()).toMatch('Request failed');
10309 function $http(requestConfig) {
10311 if (!angular.isObject(requestConfig)) {
10312 throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
10315 var config = extend({
10317 transformRequest: defaults.transformRequest,
10318 transformResponse: defaults.transformResponse,
10319 paramSerializer: defaults.paramSerializer
10322 config.headers = mergeHeaders(requestConfig);
10323 config.method = uppercase(config.method);
10324 config.paramSerializer = isString(config.paramSerializer) ?
10325 $injector.get(config.paramSerializer) : config.paramSerializer;
10327 var serverRequest = function(config) {
10328 var headers = config.headers;
10329 var reqData = transformData(config.data, headersGetter(headers), undefined, config.transformRequest);
10331 // strip content-type if data is undefined
10332 if (isUndefined(reqData)) {
10333 forEach(headers, function(value, header) {
10334 if (lowercase(header) === 'content-type') {
10335 delete headers[header];
10340 if (isUndefined(config.withCredentials) && !isUndefined(defaults.withCredentials)) {
10341 config.withCredentials = defaults.withCredentials;
10345 return sendReq(config, reqData).then(transformResponse, transformResponse);
10348 var chain = [serverRequest, undefined];
10349 var promise = $q.when(config);
10351 // apply interceptors
10352 forEach(reversedInterceptors, function(interceptor) {
10353 if (interceptor.request || interceptor.requestError) {
10354 chain.unshift(interceptor.request, interceptor.requestError);
10356 if (interceptor.response || interceptor.responseError) {
10357 chain.push(interceptor.response, interceptor.responseError);
10361 while (chain.length) {
10362 var thenFn = chain.shift();
10363 var rejectFn = chain.shift();
10365 promise = promise.then(thenFn, rejectFn);
10368 if (useLegacyPromise) {
10369 promise.success = function(fn) {
10370 assertArgFn(fn, 'fn');
10372 promise.then(function(response) {
10373 fn(response.data, response.status, response.headers, config);
10378 promise.error = function(fn) {
10379 assertArgFn(fn, 'fn');
10381 promise.then(null, function(response) {
10382 fn(response.data, response.status, response.headers, config);
10387 promise.success = $httpMinErrLegacyFn('success');
10388 promise.error = $httpMinErrLegacyFn('error');
10393 function transformResponse(response) {
10394 // make a copy since the response must be cacheable
10395 var resp = extend({}, response);
10396 resp.data = transformData(response.data, response.headers, response.status,
10397 config.transformResponse);
10398 return (isSuccess(response.status))
10403 function executeHeaderFns(headers, config) {
10404 var headerContent, processedHeaders = {};
10406 forEach(headers, function(headerFn, header) {
10407 if (isFunction(headerFn)) {
10408 headerContent = headerFn(config);
10409 if (headerContent != null) {
10410 processedHeaders[header] = headerContent;
10413 processedHeaders[header] = headerFn;
10417 return processedHeaders;
10420 function mergeHeaders(config) {
10421 var defHeaders = defaults.headers,
10422 reqHeaders = extend({}, config.headers),
10423 defHeaderName, lowercaseDefHeaderName, reqHeaderName;
10425 defHeaders = extend({}, defHeaders.common, defHeaders[lowercase(config.method)]);
10427 // using for-in instead of forEach to avoid unecessary iteration after header has been found
10428 defaultHeadersIteration:
10429 for (defHeaderName in defHeaders) {
10430 lowercaseDefHeaderName = lowercase(defHeaderName);
10432 for (reqHeaderName in reqHeaders) {
10433 if (lowercase(reqHeaderName) === lowercaseDefHeaderName) {
10434 continue defaultHeadersIteration;
10438 reqHeaders[defHeaderName] = defHeaders[defHeaderName];
10441 // execute if header value is a function for merged headers
10442 return executeHeaderFns(reqHeaders, shallowCopy(config));
10446 $http.pendingRequests = [];
10453 * Shortcut method to perform `GET` request.
10455 * @param {string} url Relative or absolute URL specifying the destination of the request
10456 * @param {Object=} config Optional configuration object
10457 * @returns {HttpPromise} Future object
10462 * @name $http#delete
10465 * Shortcut method to perform `DELETE` request.
10467 * @param {string} url Relative or absolute URL specifying the destination of the request
10468 * @param {Object=} config Optional configuration object
10469 * @returns {HttpPromise} Future object
10477 * Shortcut method to perform `HEAD` request.
10479 * @param {string} url Relative or absolute URL specifying the destination of the request
10480 * @param {Object=} config Optional configuration object
10481 * @returns {HttpPromise} Future object
10486 * @name $http#jsonp
10489 * Shortcut method to perform `JSONP` request.
10491 * @param {string} url Relative or absolute URL specifying the destination of the request.
10492 * The name of the callback should be the string `JSON_CALLBACK`.
10493 * @param {Object=} config Optional configuration object
10494 * @returns {HttpPromise} Future object
10496 createShortMethods('get', 'delete', 'head', 'jsonp');
10503 * Shortcut method to perform `POST` request.
10505 * @param {string} url Relative or absolute URL specifying the destination of the request
10506 * @param {*} data Request content
10507 * @param {Object=} config Optional configuration object
10508 * @returns {HttpPromise} Future object
10516 * Shortcut method to perform `PUT` request.
10518 * @param {string} url Relative or absolute URL specifying the destination of the request
10519 * @param {*} data Request content
10520 * @param {Object=} config Optional configuration object
10521 * @returns {HttpPromise} Future object
10526 * @name $http#patch
10529 * Shortcut method to perform `PATCH` request.
10531 * @param {string} url Relative or absolute URL specifying the destination of the request
10532 * @param {*} data Request content
10533 * @param {Object=} config Optional configuration object
10534 * @returns {HttpPromise} Future object
10536 createShortMethodsWithData('post', 'put', 'patch');
10540 * @name $http#defaults
10543 * Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of
10544 * default headers, withCredentials as well as request and response transformations.
10546 * See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above.
10548 $http.defaults = defaults;
10554 function createShortMethods(names) {
10555 forEach(arguments, function(name) {
10556 $http[name] = function(url, config) {
10557 return $http(extend({}, config || {}, {
10566 function createShortMethodsWithData(name) {
10567 forEach(arguments, function(name) {
10568 $http[name] = function(url, data, config) {
10569 return $http(extend({}, config || {}, {
10580 * Makes the request.
10582 * !!! ACCESSES CLOSURE VARS:
10583 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
10585 function sendReq(config, reqData) {
10586 var deferred = $q.defer(),
10587 promise = deferred.promise,
10590 reqHeaders = config.headers,
10591 url = buildUrl(config.url, config.paramSerializer(config.params));
10593 $http.pendingRequests.push(config);
10594 promise.then(removePendingReq, removePendingReq);
10597 if ((config.cache || defaults.cache) && config.cache !== false &&
10598 (config.method === 'GET' || config.method === 'JSONP')) {
10599 cache = isObject(config.cache) ? config.cache
10600 : isObject(defaults.cache) ? defaults.cache
10605 cachedResp = cache.get(url);
10606 if (isDefined(cachedResp)) {
10607 if (isPromiseLike(cachedResp)) {
10608 // cached request has already been sent, but there is no response yet
10609 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
10611 // serving from cache
10612 if (isArray(cachedResp)) {
10613 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]);
10615 resolvePromise(cachedResp, 200, {}, 'OK');
10619 // put the promise for the non-transformed response into cache as a placeholder
10620 cache.put(url, promise);
10625 // if we won't have the response in cache, set the xsrf headers and
10626 // send the request to the backend
10627 if (isUndefined(cachedResp)) {
10628 var xsrfValue = urlIsSameOrigin(config.url)
10629 ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName]
10632 reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
10635 $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
10636 config.withCredentials, config.responseType);
10643 * Callback registered to $httpBackend():
10644 * - caches the response if desired
10645 * - resolves the raw $http promise
10648 function done(status, response, headersString, statusText) {
10650 if (isSuccess(status)) {
10651 cache.put(url, [status, response, parseHeaders(headersString), statusText]);
10653 // remove promise from the cache
10658 function resolveHttpPromise() {
10659 resolvePromise(response, status, headersString, statusText);
10662 if (useApplyAsync) {
10663 $rootScope.$applyAsync(resolveHttpPromise);
10665 resolveHttpPromise();
10666 if (!$rootScope.$$phase) $rootScope.$apply();
10672 * Resolves the raw $http promise.
10674 function resolvePromise(response, status, headers, statusText) {
10675 //status: HTTP response status code, 0, -1 (aborted by timeout / promise)
10676 status = status >= -1 ? status : 0;
10678 (isSuccess(status) ? deferred.resolve : deferred.reject)({
10681 headers: headersGetter(headers),
10683 statusText: statusText
10687 function resolvePromiseWithResult(result) {
10688 resolvePromise(result.data, result.status, shallowCopy(result.headers()), result.statusText);
10691 function removePendingReq() {
10692 var idx = $http.pendingRequests.indexOf(config);
10693 if (idx !== -1) $http.pendingRequests.splice(idx, 1);
10698 function buildUrl(url, serializedParams) {
10699 if (serializedParams.length > 0) {
10700 url += ((url.indexOf('?') == -1) ? '?' : '&') + serializedParams;
10709 * @name $xhrFactory
10712 * Factory function used to create XMLHttpRequest objects.
10714 * Replace or decorate this service to create your own custom XMLHttpRequest objects.
10717 * angular.module('myApp', [])
10718 * .factory('$xhrFactory', function() {
10719 * return function createXhr(method, url) {
10720 * return new window.XMLHttpRequest({mozSystem: true});
10725 * @param {string} method HTTP method of the request (GET, POST, PUT, ..)
10726 * @param {string} url URL of the request.
10728 function $xhrFactoryProvider() {
10729 this.$get = function() {
10730 return function createXhr() {
10731 return new window.XMLHttpRequest();
10738 * @name $httpBackend
10739 * @requires $window
10740 * @requires $document
10741 * @requires $xhrFactory
10744 * HTTP backend used by the {@link ng.$http service} that delegates to
10745 * XMLHttpRequest object or JSONP and deals with browser incompatibilities.
10747 * You should never need to use this service directly, instead use the higher-level abstractions:
10748 * {@link ng.$http $http} or {@link ngResource.$resource $resource}.
10750 * During testing this implementation is swapped with {@link ngMock.$httpBackend mock
10751 * $httpBackend} which can be trained with responses.
10753 function $HttpBackendProvider() {
10754 this.$get = ['$browser', '$window', '$document', '$xhrFactory', function($browser, $window, $document, $xhrFactory) {
10755 return createHttpBackend($browser, $xhrFactory, $browser.defer, $window.angular.callbacks, $document[0]);
10759 function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
10760 // TODO(vojta): fix the signature
10761 return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
10762 $browser.$$incOutstandingRequestCount();
10763 url = url || $browser.url();
10765 if (lowercase(method) == 'jsonp') {
10766 var callbackId = '_' + (callbacks.counter++).toString(36);
10767 callbacks[callbackId] = function(data) {
10768 callbacks[callbackId].data = data;
10769 callbacks[callbackId].called = true;
10772 var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId),
10773 callbackId, function(status, text) {
10774 completeRequest(callback, status, callbacks[callbackId].data, "", text);
10775 callbacks[callbackId] = noop;
10779 var xhr = createXhr(method, url);
10781 xhr.open(method, url, true);
10782 forEach(headers, function(value, key) {
10783 if (isDefined(value)) {
10784 xhr.setRequestHeader(key, value);
10788 xhr.onload = function requestLoaded() {
10789 var statusText = xhr.statusText || '';
10791 // responseText is the old-school way of retrieving response (supported by IE9)
10792 // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
10793 var response = ('response' in xhr) ? xhr.response : xhr.responseText;
10795 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
10796 var status = xhr.status === 1223 ? 204 : xhr.status;
10798 // fix status code when it is 0 (0 status is undocumented).
10799 // Occurs when accessing file resources or on Android 4.1 stock browser
10800 // while retrieving files from application cache.
10801 if (status === 0) {
10802 status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
10805 completeRequest(callback,
10808 xhr.getAllResponseHeaders(),
10812 var requestError = function() {
10813 // The response is always empty
10814 // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
10815 completeRequest(callback, -1, null, null, '');
10818 xhr.onerror = requestError;
10819 xhr.onabort = requestError;
10821 if (withCredentials) {
10822 xhr.withCredentials = true;
10825 if (responseType) {
10827 xhr.responseType = responseType;
10829 // WebKit added support for the json responseType value on 09/03/2013
10830 // https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are
10831 // known to throw when setting the value "json" as the response type. Other older
10832 // browsers implementing the responseType
10834 // The json response type can be ignored if not supported, because JSON payloads are
10835 // parsed on the client-side regardless.
10836 if (responseType !== 'json') {
10842 xhr.send(isUndefined(post) ? null : post);
10846 var timeoutId = $browserDefer(timeoutRequest, timeout);
10847 } else if (isPromiseLike(timeout)) {
10848 timeout.then(timeoutRequest);
10852 function timeoutRequest() {
10853 jsonpDone && jsonpDone();
10854 xhr && xhr.abort();
10857 function completeRequest(callback, status, response, headersString, statusText) {
10858 // cancel timeout and subsequent timeout promise resolution
10859 if (isDefined(timeoutId)) {
10860 $browserDefer.cancel(timeoutId);
10862 jsonpDone = xhr = null;
10864 callback(status, response, headersString, statusText);
10865 $browser.$$completeOutstandingRequest(noop);
10869 function jsonpReq(url, callbackId, done) {
10870 // we can't use jQuery/jqLite here because jQuery does crazy stuff with script elements, e.g.:
10871 // - fetches local scripts via XHR and evals them
10872 // - adds and immediately removes script elements from the document
10873 var script = rawDocument.createElement('script'), callback = null;
10874 script.type = "text/javascript";
10876 script.async = true;
10878 callback = function(event) {
10879 removeEventListenerFn(script, "load", callback);
10880 removeEventListenerFn(script, "error", callback);
10881 rawDocument.body.removeChild(script);
10884 var text = "unknown";
10887 if (event.type === "load" && !callbacks[callbackId].called) {
10888 event = { type: "error" };
10891 status = event.type === "error" ? 404 : 200;
10895 done(status, text);
10899 addEventListenerFn(script, "load", callback);
10900 addEventListenerFn(script, "error", callback);
10901 rawDocument.body.appendChild(script);
10906 var $interpolateMinErr = angular.$interpolateMinErr = minErr('$interpolate');
10907 $interpolateMinErr.throwNoconcat = function(text) {
10908 throw $interpolateMinErr('noconcat',
10909 "Error while interpolating: {0}\nStrict Contextual Escaping disallows " +
10910 "interpolations that concatenate multiple expressions when a trusted value is " +
10911 "required. See http://docs.angularjs.org/api/ng.$sce", text);
10914 $interpolateMinErr.interr = function(text, err) {
10915 return $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text, err.toString());
10920 * @name $interpolateProvider
10924 * Used for configuring the interpolation markup. Defaults to `{{` and `}}`.
10927 <example module="customInterpolationApp">
10928 <file name="index.html">
10930 var customInterpolationApp = angular.module('customInterpolationApp', []);
10932 customInterpolationApp.config(function($interpolateProvider) {
10933 $interpolateProvider.startSymbol('//');
10934 $interpolateProvider.endSymbol('//');
10938 customInterpolationApp.controller('DemoController', function() {
10939 this.label = "This binding is brought you by // interpolation symbols.";
10942 <div ng-app="App" ng-controller="DemoController as demo">
10946 <file name="protractor.js" type="protractor">
10947 it('should interpolate binding with custom symbols', function() {
10948 expect(element(by.binding('demo.label')).getText()).toBe('This binding is brought you by // interpolation symbols.');
10953 function $InterpolateProvider() {
10954 var startSymbol = '{{';
10955 var endSymbol = '}}';
10959 * @name $interpolateProvider#startSymbol
10961 * Symbol to denote start of expression in the interpolated string. Defaults to `{{`.
10963 * @param {string=} value new value to set the starting symbol to.
10964 * @returns {string|self} Returns the symbol when used as getter and self if used as setter.
10966 this.startSymbol = function(value) {
10968 startSymbol = value;
10971 return startSymbol;
10977 * @name $interpolateProvider#endSymbol
10979 * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`.
10981 * @param {string=} value new value to set the ending symbol to.
10982 * @returns {string|self} Returns the symbol when used as getter and self if used as setter.
10984 this.endSymbol = function(value) {
10994 this.$get = ['$parse', '$exceptionHandler', '$sce', function($parse, $exceptionHandler, $sce) {
10995 var startSymbolLength = startSymbol.length,
10996 endSymbolLength = endSymbol.length,
10997 escapedStartRegexp = new RegExp(startSymbol.replace(/./g, escape), 'g'),
10998 escapedEndRegexp = new RegExp(endSymbol.replace(/./g, escape), 'g');
11000 function escape(ch) {
11001 return '\\\\\\' + ch;
11004 function unescapeText(text) {
11005 return text.replace(escapedStartRegexp, startSymbol).
11006 replace(escapedEndRegexp, endSymbol);
11009 function stringify(value) {
11010 if (value == null) { // null || undefined
11013 switch (typeof value) {
11017 value = '' + value;
11020 value = toJson(value);
11028 * @name $interpolate
11036 * Compiles a string with markup into an interpolation function. This service is used by the
11037 * HTML {@link ng.$compile $compile} service for data binding. See
11038 * {@link ng.$interpolateProvider $interpolateProvider} for configuring the
11039 * interpolation markup.
11043 * var $interpolate = ...; // injected
11044 * var exp = $interpolate('Hello {{name | uppercase}}!');
11045 * expect(exp({name:'Angular'})).toEqual('Hello ANGULAR!');
11048 * `$interpolate` takes an optional fourth argument, `allOrNothing`. If `allOrNothing` is
11049 * `true`, the interpolation function will return `undefined` unless all embedded expressions
11050 * evaluate to a value other than `undefined`.
11053 * var $interpolate = ...; // injected
11054 * var context = {greeting: 'Hello', name: undefined };
11056 * // default "forgiving" mode
11057 * var exp = $interpolate('{{greeting}} {{name}}!');
11058 * expect(exp(context)).toEqual('Hello !');
11060 * // "allOrNothing" mode
11061 * exp = $interpolate('{{greeting}} {{name}}!', false, null, true);
11062 * expect(exp(context)).toBeUndefined();
11063 * context.name = 'Angular';
11064 * expect(exp(context)).toEqual('Hello Angular!');
11067 * `allOrNothing` is useful for interpolating URLs. `ngSrc` and `ngSrcset` use this behavior.
11069 * ####Escaped Interpolation
11070 * $interpolate provides a mechanism for escaping interpolation markers. Start and end markers
11071 * can be escaped by preceding each of their characters with a REVERSE SOLIDUS U+005C (backslash).
11072 * It will be rendered as a regular start/end marker, and will not be interpreted as an expression
11075 * This enables web-servers to prevent script injection attacks and defacing attacks, to some
11076 * degree, while also enabling code examples to work without relying on the
11077 * {@link ng.directive:ngNonBindable ngNonBindable} directive.
11079 * **For security purposes, it is strongly encouraged that web servers escape user-supplied data,
11080 * replacing angle brackets (<, >) with &lt; and &gt; respectively, and replacing all
11081 * interpolation start/end markers with their escaped counterparts.**
11083 * Escaped interpolation markers are only replaced with the actual interpolation markers in rendered
11084 * output when the $interpolate service processes the text. So, for HTML elements interpolated
11085 * by {@link ng.$compile $compile}, or otherwise interpolated with the `mustHaveExpression` parameter
11086 * set to `true`, the interpolated text must contain an unescaped interpolation expression. As such,
11087 * this is typically useful only when user-data is used in rendering a template from the server, or
11088 * when otherwise untrusted data is used by a directive.
11091 * <file name="index.html">
11092 * <div ng-init="username='A user'">
11093 * <p ng-init="apptitle='Escaping demo'">{{apptitle}}: \{\{ username = "defaced value"; \}\}
11095 * <p><strong>{{username}}</strong> attempts to inject code which will deface the
11096 * application, but fails to accomplish their task, because the server has correctly
11097 * escaped the interpolation start/end markers with REVERSE SOLIDUS U+005C (backslash)
11099 * <p>Instead, the result of the attempted script injection is visible, and can be removed
11100 * from the database by an administrator.</p>
11105 * @param {string} text The text with markup to interpolate.
11106 * @param {boolean=} mustHaveExpression if set to true then the interpolation string must have
11107 * embedded expression in order to return an interpolation function. Strings with no
11108 * embedded expression will return null for the interpolation function.
11109 * @param {string=} trustedContext when provided, the returned function passes the interpolated
11110 * result through {@link ng.$sce#getTrusted $sce.getTrusted(interpolatedResult,
11111 * trustedContext)} before returning it. Refer to the {@link ng.$sce $sce} service that
11112 * provides Strict Contextual Escaping for details.
11113 * @param {boolean=} allOrNothing if `true`, then the returned function returns undefined
11114 * unless all embedded expressions evaluate to a value other than `undefined`.
11115 * @returns {function(context)} an interpolation function which is used to compute the
11116 * interpolated string. The function has these parameters:
11118 * - `context`: evaluation context for all expressions embedded in the interpolated text
11120 function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
11121 allOrNothing = !!allOrNothing;
11127 textLength = text.length,
11130 expressionPositions = [];
11132 while (index < textLength) {
11133 if (((startIndex = text.indexOf(startSymbol, index)) != -1) &&
11134 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1)) {
11135 if (index !== startIndex) {
11136 concat.push(unescapeText(text.substring(index, startIndex)));
11138 exp = text.substring(startIndex + startSymbolLength, endIndex);
11139 expressions.push(exp);
11140 parseFns.push($parse(exp, parseStringifyInterceptor));
11141 index = endIndex + endSymbolLength;
11142 expressionPositions.push(concat.length);
11145 // we did not find an interpolation, so we have to add the remainder to the separators array
11146 if (index !== textLength) {
11147 concat.push(unescapeText(text.substring(index)));
11153 // Concatenating expressions makes it hard to reason about whether some combination of
11154 // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a
11155 // single expression be used for iframe[src], object[src], etc., we ensure that the value
11156 // that's used is assigned or constructed by some JS code somewhere that is more testable or
11157 // make it obvious that you bound the value to some user controlled value. This helps reduce
11158 // the load when auditing for XSS issues.
11159 if (trustedContext && concat.length > 1) {
11160 $interpolateMinErr.throwNoconcat(text);
11163 if (!mustHaveExpression || expressions.length) {
11164 var compute = function(values) {
11165 for (var i = 0, ii = expressions.length; i < ii; i++) {
11166 if (allOrNothing && isUndefined(values[i])) return;
11167 concat[expressionPositions[i]] = values[i];
11169 return concat.join('');
11172 var getValue = function(value) {
11173 return trustedContext ?
11174 $sce.getTrusted(trustedContext, value) :
11175 $sce.valueOf(value);
11178 return extend(function interpolationFn(context) {
11180 var ii = expressions.length;
11181 var values = new Array(ii);
11184 for (; i < ii; i++) {
11185 values[i] = parseFns[i](context);
11188 return compute(values);
11190 $exceptionHandler($interpolateMinErr.interr(text, err));
11194 // all of these properties are undocumented for now
11195 exp: text, //just for compatibility with regular watchers created via $watch
11196 expressions: expressions,
11197 $$watchDelegate: function(scope, listener) {
11199 return scope.$watchGroup(parseFns, function interpolateFnWatcher(values, oldValues) {
11200 var currValue = compute(values);
11201 if (isFunction(listener)) {
11202 listener.call(this, currValue, values !== oldValues ? lastValue : currValue, scope);
11204 lastValue = currValue;
11210 function parseStringifyInterceptor(value) {
11212 value = getValue(value);
11213 return allOrNothing && !isDefined(value) ? value : stringify(value);
11215 $exceptionHandler($interpolateMinErr.interr(text, err));
11223 * @name $interpolate#startSymbol
11225 * Symbol to denote the start of expression in the interpolated string. Defaults to `{{`.
11227 * Use {@link ng.$interpolateProvider#startSymbol `$interpolateProvider.startSymbol`} to change
11230 * @returns {string} start symbol.
11232 $interpolate.startSymbol = function() {
11233 return startSymbol;
11239 * @name $interpolate#endSymbol
11241 * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`.
11243 * Use {@link ng.$interpolateProvider#endSymbol `$interpolateProvider.endSymbol`} to change
11246 * @returns {string} end symbol.
11248 $interpolate.endSymbol = function() {
11252 return $interpolate;
11256 function $IntervalProvider() {
11257 this.$get = ['$rootScope', '$window', '$q', '$$q',
11258 function($rootScope, $window, $q, $$q) {
11259 var intervals = {};
11267 * Angular's wrapper for `window.setInterval`. The `fn` function is executed every `delay`
11270 * The return value of registering an interval function is a promise. This promise will be
11271 * notified upon each tick of the interval, and will be resolved after `count` iterations, or
11272 * run indefinitely if `count` is not defined. The value of the notification will be the
11273 * number of iterations that have run.
11274 * To cancel an interval, call `$interval.cancel(promise)`.
11276 * In tests you can use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
11277 * move forward by `millis` milliseconds and trigger any functions scheduled to run in that
11280 * <div class="alert alert-warning">
11281 * **Note**: Intervals created by this service must be explicitly destroyed when you are finished
11282 * with them. In particular they are not automatically destroyed when a controller's scope or a
11283 * directive's element are destroyed.
11284 * You should take this into consideration and make sure to always cancel the interval at the
11285 * appropriate moment. See the example below for more details on how and when to do this.
11288 * @param {function()} fn A function that should be called repeatedly.
11289 * @param {number} delay Number of milliseconds between each function call.
11290 * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
11292 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
11293 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
11294 * @param {...*=} Pass additional parameters to the executed function.
11295 * @returns {promise} A promise which will be notified on each iteration.
11298 * <example module="intervalExample">
11299 * <file name="index.html">
11301 * angular.module('intervalExample', [])
11302 * .controller('ExampleController', ['$scope', '$interval',
11303 * function($scope, $interval) {
11304 * $scope.format = 'M/d/yy h:mm:ss a';
11305 * $scope.blood_1 = 100;
11306 * $scope.blood_2 = 120;
11309 * $scope.fight = function() {
11310 * // Don't start a new fight if we are already fighting
11311 * if ( angular.isDefined(stop) ) return;
11313 * stop = $interval(function() {
11314 * if ($scope.blood_1 > 0 && $scope.blood_2 > 0) {
11315 * $scope.blood_1 = $scope.blood_1 - 3;
11316 * $scope.blood_2 = $scope.blood_2 - 4;
11318 * $scope.stopFight();
11323 * $scope.stopFight = function() {
11324 * if (angular.isDefined(stop)) {
11325 * $interval.cancel(stop);
11326 * stop = undefined;
11330 * $scope.resetFight = function() {
11331 * $scope.blood_1 = 100;
11332 * $scope.blood_2 = 120;
11335 * $scope.$on('$destroy', function() {
11336 * // Make sure that the interval is destroyed too
11337 * $scope.stopFight();
11340 * // Register the 'myCurrentTime' directive factory method.
11341 * // We inject $interval and dateFilter service since the factory method is DI.
11342 * .directive('myCurrentTime', ['$interval', 'dateFilter',
11343 * function($interval, dateFilter) {
11344 * // return the directive link function. (compile function not needed)
11345 * return function(scope, element, attrs) {
11346 * var format, // date format
11347 * stopTime; // so that we can cancel the time updates
11349 * // used to update the UI
11350 * function updateTime() {
11351 * element.text(dateFilter(new Date(), format));
11354 * // watch the expression, and update the UI on change.
11355 * scope.$watch(attrs.myCurrentTime, function(value) {
11360 * stopTime = $interval(updateTime, 1000);
11362 * // listen on DOM destroy (removal) event, and cancel the next UI update
11363 * // to prevent updating time after the DOM element was removed.
11364 * element.on('$destroy', function() {
11365 * $interval.cancel(stopTime);
11372 * <div ng-controller="ExampleController">
11373 * <label>Date format: <input ng-model="format"></label> <hr/>
11374 * Current time is: <span my-current-time="format"></span>
11376 * Blood 1 : <font color='red'>{{blood_1}}</font>
11377 * Blood 2 : <font color='red'>{{blood_2}}</font>
11378 * <button type="button" data-ng-click="fight()">Fight</button>
11379 * <button type="button" data-ng-click="stopFight()">StopFight</button>
11380 * <button type="button" data-ng-click="resetFight()">resetFight</button>
11387 function interval(fn, delay, count, invokeApply) {
11388 var hasParams = arguments.length > 4,
11389 args = hasParams ? sliceArgs(arguments, 4) : [],
11390 setInterval = $window.setInterval,
11391 clearInterval = $window.clearInterval,
11393 skipApply = (isDefined(invokeApply) && !invokeApply),
11394 deferred = (skipApply ? $$q : $q).defer(),
11395 promise = deferred.promise;
11397 count = isDefined(count) ? count : 0;
11399 promise.then(null, null, (!hasParams) ? fn : function() {
11400 fn.apply(null, args);
11403 promise.$$intervalId = setInterval(function tick() {
11404 deferred.notify(iteration++);
11406 if (count > 0 && iteration >= count) {
11407 deferred.resolve(iteration);
11408 clearInterval(promise.$$intervalId);
11409 delete intervals[promise.$$intervalId];
11412 if (!skipApply) $rootScope.$apply();
11416 intervals[promise.$$intervalId] = deferred;
11424 * @name $interval#cancel
11427 * Cancels a task associated with the `promise`.
11429 * @param {Promise=} promise returned by the `$interval` function.
11430 * @returns {boolean} Returns `true` if the task was successfully canceled.
11432 interval.cancel = function(promise) {
11433 if (promise && promise.$$intervalId in intervals) {
11434 intervals[promise.$$intervalId].reject('canceled');
11435 $window.clearInterval(promise.$$intervalId);
11436 delete intervals[promise.$$intervalId];
11451 * $locale service provides localization rules for various Angular components. As of right now the
11452 * only public api is:
11454 * * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`)
11457 var PATH_MATCH = /^([^\?#]*)(\?([^#]*))?(#(.*))?$/,
11458 DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21};
11459 var $locationMinErr = minErr('$location');
11463 * Encode path using encodeUriSegment, ignoring forward slashes
11465 * @param {string} path Path to encode
11466 * @returns {string}
11468 function encodePath(path) {
11469 var segments = path.split('/'),
11470 i = segments.length;
11473 segments[i] = encodeUriSegment(segments[i]);
11476 return segments.join('/');
11479 function parseAbsoluteUrl(absoluteUrl, locationObj) {
11480 var parsedUrl = urlResolve(absoluteUrl);
11482 locationObj.$$protocol = parsedUrl.protocol;
11483 locationObj.$$host = parsedUrl.hostname;
11484 locationObj.$$port = toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
11488 function parseAppUrl(relativeUrl, locationObj) {
11489 var prefixed = (relativeUrl.charAt(0) !== '/');
11491 relativeUrl = '/' + relativeUrl;
11493 var match = urlResolve(relativeUrl);
11494 locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ?
11495 match.pathname.substring(1) : match.pathname);
11496 locationObj.$$search = parseKeyValue(match.search);
11497 locationObj.$$hash = decodeURIComponent(match.hash);
11499 // make sure path starts with '/';
11500 if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') {
11501 locationObj.$$path = '/' + locationObj.$$path;
11508 * @param {string} begin
11509 * @param {string} whole
11510 * @returns {string} returns text from whole after begin or undefined if it does not begin with
11513 function beginsWith(begin, whole) {
11514 if (whole.indexOf(begin) === 0) {
11515 return whole.substr(begin.length);
11520 function stripHash(url) {
11521 var index = url.indexOf('#');
11522 return index == -1 ? url : url.substr(0, index);
11525 function trimEmptyHash(url) {
11526 return url.replace(/(#.+)|#$/, '$1');
11530 function stripFile(url) {
11531 return url.substr(0, stripHash(url).lastIndexOf('/') + 1);
11534 /* return the server only (scheme://host:port) */
11535 function serverBase(url) {
11536 return url.substring(0, url.indexOf('/', url.indexOf('//') + 2));
11541 * LocationHtml5Url represents an url
11542 * This object is exposed as $location service when HTML5 mode is enabled and supported
11545 * @param {string} appBase application base URL
11546 * @param {string} appBaseNoFile application base URL stripped of any filename
11547 * @param {string} basePrefix url path prefix
11549 function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
11550 this.$$html5 = true;
11551 basePrefix = basePrefix || '';
11552 parseAbsoluteUrl(appBase, this);
11556 * Parse given html5 (regular) url string into properties
11557 * @param {string} url HTML5 url
11560 this.$$parse = function(url) {
11561 var pathUrl = beginsWith(appBaseNoFile, url);
11562 if (!isString(pathUrl)) {
11563 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
11567 parseAppUrl(pathUrl, this);
11569 if (!this.$$path) {
11577 * Compose url and update `absUrl` property
11580 this.$$compose = function() {
11581 var search = toKeyValue(this.$$search),
11582 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
11584 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
11585 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
11588 this.$$parseLinkUrl = function(url, relHref) {
11589 if (relHref && relHref[0] === '#') {
11590 // special case for links to hash fragments:
11591 // keep the old url and only replace the hash fragment
11592 this.hash(relHref.slice(1));
11595 var appUrl, prevAppUrl;
11598 if (isDefined(appUrl = beginsWith(appBase, url))) {
11599 prevAppUrl = appUrl;
11600 if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) {
11601 rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
11603 rewrittenUrl = appBase + prevAppUrl;
11605 } else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) {
11606 rewrittenUrl = appBaseNoFile + appUrl;
11607 } else if (appBaseNoFile == url + '/') {
11608 rewrittenUrl = appBaseNoFile;
11610 if (rewrittenUrl) {
11611 this.$$parse(rewrittenUrl);
11613 return !!rewrittenUrl;
11619 * LocationHashbangUrl represents url
11620 * This object is exposed as $location service when developer doesn't opt into html5 mode.
11621 * It also serves as the base class for html5 mode fallback on legacy browsers.
11624 * @param {string} appBase application base URL
11625 * @param {string} appBaseNoFile application base URL stripped of any filename
11626 * @param {string} hashPrefix hashbang prefix
11628 function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
11630 parseAbsoluteUrl(appBase, this);
11634 * Parse given hashbang url into properties
11635 * @param {string} url Hashbang url
11638 this.$$parse = function(url) {
11639 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
11640 var withoutHashUrl;
11642 if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {
11644 // The rest of the url starts with a hash so we have
11645 // got either a hashbang path or a plain hash fragment
11646 withoutHashUrl = beginsWith(hashPrefix, withoutBaseUrl);
11647 if (isUndefined(withoutHashUrl)) {
11648 // There was no hashbang prefix so we just have a hash fragment
11649 withoutHashUrl = withoutBaseUrl;
11653 // There was no hashbang path nor hash fragment:
11654 // If we are in HTML5 mode we use what is left as the path;
11655 // Otherwise we ignore what is left
11656 if (this.$$html5) {
11657 withoutHashUrl = withoutBaseUrl;
11659 withoutHashUrl = '';
11660 if (isUndefined(withoutBaseUrl)) {
11667 parseAppUrl(withoutHashUrl, this);
11669 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
11674 * In Windows, on an anchor node on documents loaded from
11675 * the filesystem, the browser will return a pathname
11676 * prefixed with the drive name ('/C:/path') when a
11677 * pathname without a drive is set:
11678 * * a.setAttribute('href', '/foo')
11679 * * a.pathname === '/C:/foo' //true
11681 * Inside of Angular, we're always using pathnames that
11682 * do not include drive names for routing.
11684 function removeWindowsDriveName(path, url, base) {
11686 Matches paths for file protocol on windows,
11687 such as /C:/foo/bar, and captures only /foo/bar.
11689 var windowsFilePathExp = /^\/[A-Z]:(\/.*)/;
11691 var firstPathSegmentMatch;
11693 //Get the relative path from the input URL.
11694 if (url.indexOf(base) === 0) {
11695 url = url.replace(base, '');
11698 // The input URL intentionally contains a first path segment that ends with a colon.
11699 if (windowsFilePathExp.exec(url)) {
11703 firstPathSegmentMatch = windowsFilePathExp.exec(path);
11704 return firstPathSegmentMatch ? firstPathSegmentMatch[1] : path;
11709 * Compose hashbang url and update `absUrl` property
11712 this.$$compose = function() {
11713 var search = toKeyValue(this.$$search),
11714 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
11716 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
11717 this.$$absUrl = appBase + (this.$$url ? hashPrefix + this.$$url : '');
11720 this.$$parseLinkUrl = function(url, relHref) {
11721 if (stripHash(appBase) == stripHash(url)) {
11731 * LocationHashbangUrl represents url
11732 * This object is exposed as $location service when html5 history api is enabled but the browser
11733 * does not support it.
11736 * @param {string} appBase application base URL
11737 * @param {string} appBaseNoFile application base URL stripped of any filename
11738 * @param {string} hashPrefix hashbang prefix
11740 function LocationHashbangInHtml5Url(appBase, appBaseNoFile, hashPrefix) {
11741 this.$$html5 = true;
11742 LocationHashbangUrl.apply(this, arguments);
11744 this.$$parseLinkUrl = function(url, relHref) {
11745 if (relHref && relHref[0] === '#') {
11746 // special case for links to hash fragments:
11747 // keep the old url and only replace the hash fragment
11748 this.hash(relHref.slice(1));
11755 if (appBase == stripHash(url)) {
11756 rewrittenUrl = url;
11757 } else if ((appUrl = beginsWith(appBaseNoFile, url))) {
11758 rewrittenUrl = appBase + hashPrefix + appUrl;
11759 } else if (appBaseNoFile === url + '/') {
11760 rewrittenUrl = appBaseNoFile;
11762 if (rewrittenUrl) {
11763 this.$$parse(rewrittenUrl);
11765 return !!rewrittenUrl;
11768 this.$$compose = function() {
11769 var search = toKeyValue(this.$$search),
11770 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
11772 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
11773 // include hashPrefix in $$absUrl when $$url is empty so IE9 does not reload page because of removal of '#'
11774 this.$$absUrl = appBase + hashPrefix + this.$$url;
11780 var locationPrototype = {
11783 * Are we in html5 mode?
11789 * Has any change been replacing?
11796 * @name $location#absUrl
11799 * This method is getter only.
11801 * Return full url representation with all segments encoded according to rules specified in
11802 * [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
11806 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11807 * var absUrl = $location.absUrl();
11808 * // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
11811 * @return {string} full url
11813 absUrl: locationGetter('$$absUrl'),
11817 * @name $location#url
11820 * This method is getter / setter.
11822 * Return url (e.g. `/path?a=b#hash`) when called without any parameter.
11824 * Change path, search and hash, when called with parameter and return `$location`.
11828 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11829 * var url = $location.url();
11830 * // => "/some/path?foo=bar&baz=xoxo"
11833 * @param {string=} url New url without base prefix (e.g. `/path?a=b#hash`)
11834 * @return {string} url
11836 url: function(url) {
11837 if (isUndefined(url)) {
11841 var match = PATH_MATCH.exec(url);
11842 if (match[1] || url === '') this.path(decodeURIComponent(match[1]));
11843 if (match[2] || match[1] || url === '') this.search(match[3] || '');
11844 this.hash(match[5] || '');
11851 * @name $location#protocol
11854 * This method is getter only.
11856 * Return protocol of current url.
11860 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11861 * var protocol = $location.protocol();
11865 * @return {string} protocol of current url
11867 protocol: locationGetter('$$protocol'),
11871 * @name $location#host
11874 * This method is getter only.
11876 * Return host of current url.
11878 * Note: compared to the non-angular version `location.host` which returns `hostname:port`, this returns the `hostname` portion only.
11882 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11883 * var host = $location.host();
11884 * // => "example.com"
11886 * // given url http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
11887 * host = $location.host();
11888 * // => "example.com"
11889 * host = location.host;
11890 * // => "example.com:8080"
11893 * @return {string} host of current url.
11895 host: locationGetter('$$host'),
11899 * @name $location#port
11902 * This method is getter only.
11904 * Return port of current url.
11908 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11909 * var port = $location.port();
11913 * @return {Number} port
11915 port: locationGetter('$$port'),
11919 * @name $location#path
11922 * This method is getter / setter.
11924 * Return path of current url when called without any parameter.
11926 * Change path when called with parameter and return `$location`.
11928 * Note: Path should always begin with forward slash (/), this method will add the forward slash
11929 * if it is missing.
11933 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11934 * var path = $location.path();
11935 * // => "/some/path"
11938 * @param {(string|number)=} path New path
11939 * @return {string} path
11941 path: locationGetterSetter('$$path', function(path) {
11942 path = path !== null ? path.toString() : '';
11943 return path.charAt(0) == '/' ? path : '/' + path;
11948 * @name $location#search
11951 * This method is getter / setter.
11953 * Return search part (as object) of current url when called without any parameter.
11955 * Change search part when called with parameter and return `$location`.
11959 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
11960 * var searchObject = $location.search();
11961 * // => {foo: 'bar', baz: 'xoxo'}
11963 * // set foo to 'yipee'
11964 * $location.search('foo', 'yipee');
11965 * // $location.search() => {foo: 'yipee', baz: 'xoxo'}
11968 * @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or
11971 * When called with a single argument the method acts as a setter, setting the `search` component
11972 * of `$location` to the specified value.
11974 * If the argument is a hash object containing an array of values, these values will be encoded
11975 * as duplicate search parameters in the url.
11977 * @param {(string|Number|Array<string>|boolean)=} paramValue If `search` is a string or number, then `paramValue`
11978 * will override only a single search property.
11980 * If `paramValue` is an array, it will override the property of the `search` component of
11981 * `$location` specified via the first argument.
11983 * If `paramValue` is `null`, the property specified via the first argument will be deleted.
11985 * If `paramValue` is `true`, the property specified via the first argument will be added with no
11986 * value nor trailing equal sign.
11988 * @return {Object} If called with no arguments returns the parsed `search` object. If called with
11989 * one or more arguments returns `$location` object itself.
11991 search: function(search, paramValue) {
11992 switch (arguments.length) {
11994 return this.$$search;
11996 if (isString(search) || isNumber(search)) {
11997 search = search.toString();
11998 this.$$search = parseKeyValue(search);
11999 } else if (isObject(search)) {
12000 search = copy(search, {});
12001 // remove object undefined or null properties
12002 forEach(search, function(value, key) {
12003 if (value == null) delete search[key];
12006 this.$$search = search;
12008 throw $locationMinErr('isrcharg',
12009 'The first argument of the `$location#search()` call must be a string or an object.');
12013 if (isUndefined(paramValue) || paramValue === null) {
12014 delete this.$$search[search];
12016 this.$$search[search] = paramValue;
12026 * @name $location#hash
12029 * This method is getter / setter.
12031 * Returns the hash fragment when called without any parameters.
12033 * Changes the hash fragment when called with a parameter and returns `$location`.
12037 * // given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
12038 * var hash = $location.hash();
12039 * // => "hashValue"
12042 * @param {(string|number)=} hash New hash fragment
12043 * @return {string} hash
12045 hash: locationGetterSetter('$$hash', function(hash) {
12046 return hash !== null ? hash.toString() : '';
12051 * @name $location#replace
12054 * If called, all changes to $location during the current `$digest` will replace the current history
12055 * record, instead of adding a new one.
12057 replace: function() {
12058 this.$$replace = true;
12063 forEach([LocationHashbangInHtml5Url, LocationHashbangUrl, LocationHtml5Url], function(Location) {
12064 Location.prototype = Object.create(locationPrototype);
12068 * @name $location#state
12071 * This method is getter / setter.
12073 * Return the history state object when called without any parameter.
12075 * Change the history state object when called with one parameter and return `$location`.
12076 * The state object is later passed to `pushState` or `replaceState`.
12078 * NOTE: This method is supported only in HTML5 mode and only in browsers supporting
12079 * the HTML5 History API (i.e. methods `pushState` and `replaceState`). If you need to support
12080 * older browsers (like IE9 or Android < 4.0), don't use this method.
12082 * @param {object=} state State object for pushState or replaceState
12083 * @return {object} state
12085 Location.prototype.state = function(state) {
12086 if (!arguments.length) {
12087 return this.$$state;
12090 if (Location !== LocationHtml5Url || !this.$$html5) {
12091 throw $locationMinErr('nostate', 'History API state support is available only ' +
12092 'in HTML5 mode and only in browsers supporting HTML5 History API');
12094 // The user might modify `stateObject` after invoking `$location.state(stateObject)`
12095 // but we're changing the $$state reference to $browser.state() during the $digest
12096 // so the modification window is narrow.
12097 this.$$state = isUndefined(state) ? null : state;
12104 function locationGetter(property) {
12105 return function() {
12106 return this[property];
12111 function locationGetterSetter(property, preprocess) {
12112 return function(value) {
12113 if (isUndefined(value)) {
12114 return this[property];
12117 this[property] = preprocess(value);
12129 * @requires $rootElement
12132 * The $location service parses the URL in the browser address bar (based on the
12133 * [window.location](https://developer.mozilla.org/en/window.location)) and makes the URL
12134 * available to your application. Changes to the URL in the address bar are reflected into
12135 * $location service and changes to $location are reflected into the browser address bar.
12137 * **The $location service:**
12139 * - Exposes the current URL in the browser address bar, so you can
12140 * - Watch and observe the URL.
12141 * - Change the URL.
12142 * - Synchronizes the URL with the browser when the user
12143 * - Changes the address bar.
12144 * - Clicks the back or forward button (or clicks a History link).
12145 * - Clicks on a link.
12146 * - Represents the URL object as a set of methods (protocol, host, port, path, search, hash).
12148 * For more information see {@link guide/$location Developer Guide: Using $location}
12153 * @name $locationProvider
12155 * Use the `$locationProvider` to configure how the application deep linking paths are stored.
12157 function $LocationProvider() {
12158 var hashPrefix = '',
12167 * @name $locationProvider#hashPrefix
12169 * @param {string=} prefix Prefix for hash part (containing path and search)
12170 * @returns {*} current value if used as getter or itself (chaining) if used as setter
12172 this.hashPrefix = function(prefix) {
12173 if (isDefined(prefix)) {
12174 hashPrefix = prefix;
12183 * @name $locationProvider#html5Mode
12185 * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value.
12186 * If object, sets `enabled`, `requireBase` and `rewriteLinks` to respective values. Supported
12188 * - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to
12189 * change urls where supported. Will fall back to hash-prefixed paths in browsers that do not
12190 * support `pushState`.
12191 * - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies
12192 * whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
12193 * true, and a base tag is not present, an error will be thrown when `$location` is injected.
12194 * See the {@link guide/$location $location guide for more information}
12195 * - **rewriteLinks** - `{boolean}` - (default: `true`) When html5Mode is enabled,
12196 * enables/disables url rewriting for relative links.
12198 * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
12200 this.html5Mode = function(mode) {
12201 if (isBoolean(mode)) {
12202 html5Mode.enabled = mode;
12204 } else if (isObject(mode)) {
12206 if (isBoolean(mode.enabled)) {
12207 html5Mode.enabled = mode.enabled;
12210 if (isBoolean(mode.requireBase)) {
12211 html5Mode.requireBase = mode.requireBase;
12214 if (isBoolean(mode.rewriteLinks)) {
12215 html5Mode.rewriteLinks = mode.rewriteLinks;
12226 * @name $location#$locationChangeStart
12227 * @eventType broadcast on root scope
12229 * Broadcasted before a URL will change.
12231 * This change can be prevented by calling
12232 * `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on} for more
12233 * details about event object. Upon successful change
12234 * {@link ng.$location#$locationChangeSuccess $locationChangeSuccess} is fired.
12236 * The `newState` and `oldState` parameters may be defined only in HTML5 mode and when
12237 * the browser supports the HTML5 History API.
12239 * @param {Object} angularEvent Synthetic event object.
12240 * @param {string} newUrl New URL
12241 * @param {string=} oldUrl URL that was before it was changed.
12242 * @param {string=} newState New history state object
12243 * @param {string=} oldState History state object that was before it was changed.
12248 * @name $location#$locationChangeSuccess
12249 * @eventType broadcast on root scope
12251 * Broadcasted after a URL was changed.
12253 * The `newState` and `oldState` parameters may be defined only in HTML5 mode and when
12254 * the browser supports the HTML5 History API.
12256 * @param {Object} angularEvent Synthetic event object.
12257 * @param {string} newUrl New URL
12258 * @param {string=} oldUrl URL that was before it was changed.
12259 * @param {string=} newState New history state object
12260 * @param {string=} oldState History state object that was before it was changed.
12263 this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement', '$window',
12264 function($rootScope, $browser, $sniffer, $rootElement, $window) {
12267 baseHref = $browser.baseHref(), // if base[href] is undefined, it defaults to ''
12268 initialUrl = $browser.url(),
12271 if (html5Mode.enabled) {
12272 if (!baseHref && html5Mode.requireBase) {
12273 throw $locationMinErr('nobase',
12274 "$location in HTML5 mode requires a <base> tag to be present!");
12276 appBase = serverBase(initialUrl) + (baseHref || '/');
12277 LocationMode = $sniffer.history ? LocationHtml5Url : LocationHashbangInHtml5Url;
12279 appBase = stripHash(initialUrl);
12280 LocationMode = LocationHashbangUrl;
12282 var appBaseNoFile = stripFile(appBase);
12284 $location = new LocationMode(appBase, appBaseNoFile, '#' + hashPrefix);
12285 $location.$$parseLinkUrl(initialUrl, initialUrl);
12287 $location.$$state = $browser.state();
12289 var IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i;
12291 function setBrowserUrlWithFallback(url, replace, state) {
12292 var oldUrl = $location.url();
12293 var oldState = $location.$$state;
12295 $browser.url(url, replace, state);
12297 // Make sure $location.state() returns referentially identical (not just deeply equal)
12298 // state object; this makes possible quick checking if the state changed in the digest
12299 // loop. Checking deep equality would be too expensive.
12300 $location.$$state = $browser.state();
12302 // Restore old values if pushState fails
12303 $location.url(oldUrl);
12304 $location.$$state = oldState;
12310 $rootElement.on('click', function(event) {
12311 // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
12312 // currently we open nice url link and redirect then
12314 if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.shiftKey || event.which == 2 || event.button == 2) return;
12316 var elm = jqLite(event.target);
12318 // traverse the DOM up to find first A tag
12319 while (nodeName_(elm[0]) !== 'a') {
12320 // ignore rewriting if no A tag (reached root element, or no parent - removed from document)
12321 if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
12324 var absHref = elm.prop('href');
12325 // get the actual href attribute - see
12326 // http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
12327 var relHref = elm.attr('href') || elm.attr('xlink:href');
12329 if (isObject(absHref) && absHref.toString() === '[object SVGAnimatedString]') {
12330 // SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during
12332 absHref = urlResolve(absHref.animVal).href;
12335 // Ignore when url is started with javascript: or mailto:
12336 if (IGNORE_URI_REGEXP.test(absHref)) return;
12338 if (absHref && !elm.attr('target') && !event.isDefaultPrevented()) {
12339 if ($location.$$parseLinkUrl(absHref, relHref)) {
12340 // We do a preventDefault for all urls that are part of the angular application,
12341 // in html5mode and also without, so that we are able to abort navigation without
12342 // getting double entries in the location history.
12343 event.preventDefault();
12344 // update location manually
12345 if ($location.absUrl() != $browser.url()) {
12346 $rootScope.$apply();
12347 // hack to work around FF6 bug 684208 when scenario runner clicks on links
12348 $window.angular['ff-684208-preventDefault'] = true;
12355 // rewrite hashbang url <> html5 url
12356 if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) {
12357 $browser.url($location.absUrl(), true);
12360 var initializing = true;
12362 // update $location when $browser url changes
12363 $browser.onUrlChange(function(newUrl, newState) {
12365 if (isUndefined(beginsWith(appBaseNoFile, newUrl))) {
12366 // If we are navigating outside of the app then force a reload
12367 $window.location.href = newUrl;
12371 $rootScope.$evalAsync(function() {
12372 var oldUrl = $location.absUrl();
12373 var oldState = $location.$$state;
12374 var defaultPrevented;
12375 newUrl = trimEmptyHash(newUrl);
12376 $location.$$parse(newUrl);
12377 $location.$$state = newState;
12379 defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl,
12380 newState, oldState).defaultPrevented;
12382 // if the location was changed by a `$locationChangeStart` handler then stop
12383 // processing this location change
12384 if ($location.absUrl() !== newUrl) return;
12386 if (defaultPrevented) {
12387 $location.$$parse(oldUrl);
12388 $location.$$state = oldState;
12389 setBrowserUrlWithFallback(oldUrl, false, oldState);
12391 initializing = false;
12392 afterLocationChange(oldUrl, oldState);
12395 if (!$rootScope.$$phase) $rootScope.$digest();
12399 $rootScope.$watch(function $locationWatch() {
12400 var oldUrl = trimEmptyHash($browser.url());
12401 var newUrl = trimEmptyHash($location.absUrl());
12402 var oldState = $browser.state();
12403 var currentReplace = $location.$$replace;
12404 var urlOrStateChanged = oldUrl !== newUrl ||
12405 ($location.$$html5 && $sniffer.history && oldState !== $location.$$state);
12407 if (initializing || urlOrStateChanged) {
12408 initializing = false;
12410 $rootScope.$evalAsync(function() {
12411 var newUrl = $location.absUrl();
12412 var defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl,
12413 $location.$$state, oldState).defaultPrevented;
12415 // if the location was changed by a `$locationChangeStart` handler then stop
12416 // processing this location change
12417 if ($location.absUrl() !== newUrl) return;
12419 if (defaultPrevented) {
12420 $location.$$parse(oldUrl);
12421 $location.$$state = oldState;
12423 if (urlOrStateChanged) {
12424 setBrowserUrlWithFallback(newUrl, currentReplace,
12425 oldState === $location.$$state ? null : $location.$$state);
12427 afterLocationChange(oldUrl, oldState);
12432 $location.$$replace = false;
12434 // we don't need to return anything because $evalAsync will make the digest loop dirty when
12435 // there is a change
12440 function afterLocationChange(oldUrl, oldState) {
12441 $rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), oldUrl,
12442 $location.$$state, oldState);
12450 * @requires $window
12453 * Simple service for logging. Default implementation safely writes the message
12454 * into the browser's console (if present).
12456 * The main purpose of this service is to simplify debugging and troubleshooting.
12458 * The default is to log `debug` messages. You can use
12459 * {@link ng.$logProvider ng.$logProvider#debugEnabled} to change this.
12462 <example module="logExample">
12463 <file name="script.js">
12464 angular.module('logExample', [])
12465 .controller('LogController', ['$scope', '$log', function($scope, $log) {
12466 $scope.$log = $log;
12467 $scope.message = 'Hello World!';
12470 <file name="index.html">
12471 <div ng-controller="LogController">
12472 <p>Reload this page with open console, enter text and hit the log button...</p>
12474 <input type="text" ng-model="message" /></label>
12475 <button ng-click="$log.log(message)">log</button>
12476 <button ng-click="$log.warn(message)">warn</button>
12477 <button ng-click="$log.info(message)">info</button>
12478 <button ng-click="$log.error(message)">error</button>
12479 <button ng-click="$log.debug(message)">debug</button>
12487 * @name $logProvider
12489 * Use the `$logProvider` to configure how the application logs messages
12491 function $LogProvider() {
12497 * @name $logProvider#debugEnabled
12499 * @param {boolean=} flag enable or disable debug level messages
12500 * @returns {*} current value if used as getter or itself (chaining) if used as setter
12502 this.debugEnabled = function(flag) {
12503 if (isDefined(flag)) {
12511 this.$get = ['$window', function($window) {
12518 * Write a log message
12520 log: consoleLog('log'),
12527 * Write an information message
12529 info: consoleLog('info'),
12536 * Write a warning message
12538 warn: consoleLog('warn'),
12545 * Write an error message
12547 error: consoleLog('error'),
12554 * Write a debug message
12556 debug: (function() {
12557 var fn = consoleLog('debug');
12559 return function() {
12561 fn.apply(self, arguments);
12567 function formatError(arg) {
12568 if (arg instanceof Error) {
12570 arg = (arg.message && arg.stack.indexOf(arg.message) === -1)
12571 ? 'Error: ' + arg.message + '\n' + arg.stack
12573 } else if (arg.sourceURL) {
12574 arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line;
12580 function consoleLog(type) {
12581 var console = $window.console || {},
12582 logFn = console[type] || console.log || noop,
12585 // Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
12586 // The reason behind this is that console.log has type "object" in IE8...
12588 hasApply = !!logFn.apply;
12592 return function() {
12594 forEach(arguments, function(arg) {
12595 args.push(formatError(arg));
12597 return logFn.apply(console, args);
12601 // we are IE which either doesn't have window.console => this is noop and we do nothing,
12602 // or we are IE where console.log doesn't have apply so we log at least first 2 args
12603 return function(arg1, arg2) {
12604 logFn(arg1, arg2 == null ? '' : arg2);
12610 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
12611 * Any commits to this file should be reviewed with security in mind. *
12612 * Changes to this file can potentially create security vulnerabilities. *
12613 * An approval from 2 Core members with history of modifying *
12614 * this file is required. *
12616 * Does the change somehow allow for arbitrary javascript to be executed? *
12617 * Or allows for someone to change the prototype of built-in objects? *
12618 * Or gives undesired access to variables likes document or window? *
12619 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12621 var $parseMinErr = minErr('$parse');
12623 // Sandboxing Angular Expressions
12624 // ------------------------------
12625 // Angular expressions are generally considered safe because these expressions only have direct
12626 // access to `$scope` and locals. However, one can obtain the ability to execute arbitrary JS code by
12627 // obtaining a reference to native JS functions such as the Function constructor.
12629 // As an example, consider the following Angular expression:
12631 // {}.toString.constructor('alert("evil JS code")')
12633 // This sandboxing technique is not perfect and doesn't aim to be. The goal is to prevent exploits
12634 // against the expression language, but not to prevent exploits that were enabled by exposing
12635 // sensitive JavaScript or browser APIs on Scope. Exposing such objects on a Scope is never a good
12636 // practice and therefore we are not even trying to protect against interaction with an object
12637 // explicitly exposed in this way.
12639 // In general, it is not possible to access a Window object from an angular expression unless a
12640 // window or some DOM object that has a reference to window is published onto a Scope.
12641 // Similarly we prevent invocations of function known to be dangerous, as well as assignments to
12644 // See https://docs.angularjs.org/guide/security
12647 function ensureSafeMemberName(name, fullExpression) {
12648 if (name === "__defineGetter__" || name === "__defineSetter__"
12649 || name === "__lookupGetter__" || name === "__lookupSetter__"
12650 || name === "__proto__") {
12651 throw $parseMinErr('isecfld',
12652 'Attempting to access a disallowed field in Angular expressions! '
12653 + 'Expression: {0}', fullExpression);
12658 function getStringValue(name, fullExpression) {
12659 // From the JavaScript docs:
12660 // Property names must be strings. This means that non-string objects cannot be used
12661 // as keys in an object. Any non-string object, including a number, is typecasted
12662 // into a string via the toString method.
12664 // So, to ensure that we are checking the same `name` that JavaScript would use,
12665 // we cast it to a string, if possible.
12666 // Doing `name + ''` can cause a repl error if the result to `toString` is not a string,
12667 // this is, this will handle objects that misbehave.
12669 if (!isString(name)) {
12670 throw $parseMinErr('iseccst',
12671 'Cannot convert object to primitive value! '
12672 + 'Expression: {0}', fullExpression);
12677 function ensureSafeObject(obj, fullExpression) {
12678 // nifty check if obj is Function that is fast and works across iframes and other contexts
12680 if (obj.constructor === obj) {
12681 throw $parseMinErr('isecfn',
12682 'Referencing Function in Angular expressions is disallowed! Expression: {0}',
12684 } else if (// isWindow(obj)
12685 obj.window === obj) {
12686 throw $parseMinErr('isecwindow',
12687 'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
12689 } else if (// isElement(obj)
12690 obj.children && (obj.nodeName || (obj.prop && obj.attr && obj.find))) {
12691 throw $parseMinErr('isecdom',
12692 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
12694 } else if (// block Object so that we can't get hold of dangerous Object.* methods
12696 throw $parseMinErr('isecobj',
12697 'Referencing Object in Angular expressions is disallowed! Expression: {0}',
12704 var CALL = Function.prototype.call;
12705 var APPLY = Function.prototype.apply;
12706 var BIND = Function.prototype.bind;
12708 function ensureSafeFunction(obj, fullExpression) {
12710 if (obj.constructor === obj) {
12711 throw $parseMinErr('isecfn',
12712 'Referencing Function in Angular expressions is disallowed! Expression: {0}',
12714 } else if (obj === CALL || obj === APPLY || obj === BIND) {
12715 throw $parseMinErr('isecff',
12716 'Referencing call, apply or bind in Angular expressions is disallowed! Expression: {0}',
12722 function ensureSafeAssignContext(obj, fullExpression) {
12724 if (obj === (0).constructor || obj === (false).constructor || obj === ''.constructor ||
12725 obj === {}.constructor || obj === [].constructor || obj === Function.constructor) {
12726 throw $parseMinErr('isecaf',
12727 'Assigning to a constructor is disallowed! Expression: {0}', fullExpression);
12732 var OPERATORS = createMap();
12733 forEach('+ - * / % === !== == != < > <= >= && || ! = |'.split(' '), function(operator) { OPERATORS[operator] = true; });
12734 var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};
12737 /////////////////////////////////////////
12743 var Lexer = function(options) {
12744 this.options = options;
12747 Lexer.prototype = {
12748 constructor: Lexer,
12750 lex: function(text) {
12755 while (this.index < this.text.length) {
12756 var ch = this.text.charAt(this.index);
12757 if (ch === '"' || ch === "'") {
12758 this.readString(ch);
12759 } else if (this.isNumber(ch) || ch === '.' && this.isNumber(this.peek())) {
12761 } else if (this.isIdent(ch)) {
12763 } else if (this.is(ch, '(){}[].,;:?')) {
12764 this.tokens.push({index: this.index, text: ch});
12766 } else if (this.isWhitespace(ch)) {
12769 var ch2 = ch + this.peek();
12770 var ch3 = ch2 + this.peek(2);
12771 var op1 = OPERATORS[ch];
12772 var op2 = OPERATORS[ch2];
12773 var op3 = OPERATORS[ch3];
12774 if (op1 || op2 || op3) {
12775 var token = op3 ? ch3 : (op2 ? ch2 : ch);
12776 this.tokens.push({index: this.index, text: token, operator: true});
12777 this.index += token.length;
12779 this.throwError('Unexpected next character ', this.index, this.index + 1);
12783 return this.tokens;
12786 is: function(ch, chars) {
12787 return chars.indexOf(ch) !== -1;
12790 peek: function(i) {
12792 return (this.index + num < this.text.length) ? this.text.charAt(this.index + num) : false;
12795 isNumber: function(ch) {
12796 return ('0' <= ch && ch <= '9') && typeof ch === "string";
12799 isWhitespace: function(ch) {
12800 // IE treats non-breaking space as \u00A0
12801 return (ch === ' ' || ch === '\r' || ch === '\t' ||
12802 ch === '\n' || ch === '\v' || ch === '\u00A0');
12805 isIdent: function(ch) {
12806 return ('a' <= ch && ch <= 'z' ||
12807 'A' <= ch && ch <= 'Z' ||
12808 '_' === ch || ch === '$');
12811 isExpOperator: function(ch) {
12812 return (ch === '-' || ch === '+' || this.isNumber(ch));
12815 throwError: function(error, start, end) {
12816 end = end || this.index;
12817 var colStr = (isDefined(start)
12818 ? 's ' + start + '-' + this.index + ' [' + this.text.substring(start, end) + ']'
12820 throw $parseMinErr('lexerr', 'Lexer Error: {0} at column{1} in expression [{2}].',
12821 error, colStr, this.text);
12824 readNumber: function() {
12826 var start = this.index;
12827 while (this.index < this.text.length) {
12828 var ch = lowercase(this.text.charAt(this.index));
12829 if (ch == '.' || this.isNumber(ch)) {
12832 var peekCh = this.peek();
12833 if (ch == 'e' && this.isExpOperator(peekCh)) {
12835 } else if (this.isExpOperator(ch) &&
12836 peekCh && this.isNumber(peekCh) &&
12837 number.charAt(number.length - 1) == 'e') {
12839 } else if (this.isExpOperator(ch) &&
12840 (!peekCh || !this.isNumber(peekCh)) &&
12841 number.charAt(number.length - 1) == 'e') {
12842 this.throwError('Invalid exponent');
12853 value: Number(number)
12857 readIdent: function() {
12858 var start = this.index;
12859 while (this.index < this.text.length) {
12860 var ch = this.text.charAt(this.index);
12861 if (!(this.isIdent(ch) || this.isNumber(ch))) {
12868 text: this.text.slice(start, this.index),
12873 readString: function(quote) {
12874 var start = this.index;
12877 var rawString = quote;
12878 var escape = false;
12879 while (this.index < this.text.length) {
12880 var ch = this.text.charAt(this.index);
12884 var hex = this.text.substring(this.index + 1, this.index + 5);
12885 if (!hex.match(/[\da-f]{4}/i)) {
12886 this.throwError('Invalid unicode escape [\\u' + hex + ']');
12889 string += String.fromCharCode(parseInt(hex, 16));
12891 var rep = ESCAPE[ch];
12892 string = string + (rep || ch);
12895 } else if (ch === '\\') {
12897 } else if (ch === quote) {
12911 this.throwError('Unterminated quote', start);
12915 var AST = function(lexer, options) {
12916 this.lexer = lexer;
12917 this.options = options;
12920 AST.Program = 'Program';
12921 AST.ExpressionStatement = 'ExpressionStatement';
12922 AST.AssignmentExpression = 'AssignmentExpression';
12923 AST.ConditionalExpression = 'ConditionalExpression';
12924 AST.LogicalExpression = 'LogicalExpression';
12925 AST.BinaryExpression = 'BinaryExpression';
12926 AST.UnaryExpression = 'UnaryExpression';
12927 AST.CallExpression = 'CallExpression';
12928 AST.MemberExpression = 'MemberExpression';
12929 AST.Identifier = 'Identifier';
12930 AST.Literal = 'Literal';
12931 AST.ArrayExpression = 'ArrayExpression';
12932 AST.Property = 'Property';
12933 AST.ObjectExpression = 'ObjectExpression';
12934 AST.ThisExpression = 'ThisExpression';
12936 // Internal use only
12937 AST.NGValueParameter = 'NGValueParameter';
12940 ast: function(text) {
12942 this.tokens = this.lexer.lex(text);
12944 var value = this.program();
12946 if (this.tokens.length !== 0) {
12947 this.throwError('is an unexpected token', this.tokens[0]);
12953 program: function() {
12956 if (this.tokens.length > 0 && !this.peek('}', ')', ';', ']'))
12957 body.push(this.expressionStatement());
12958 if (!this.expect(';')) {
12959 return { type: AST.Program, body: body};
12964 expressionStatement: function() {
12965 return { type: AST.ExpressionStatement, expression: this.filterChain() };
12968 filterChain: function() {
12969 var left = this.expression();
12971 while ((token = this.expect('|'))) {
12972 left = this.filter(left);
12977 expression: function() {
12978 return this.assignment();
12981 assignment: function() {
12982 var result = this.ternary();
12983 if (this.expect('=')) {
12984 result = { type: AST.AssignmentExpression, left: result, right: this.assignment(), operator: '='};
12989 ternary: function() {
12990 var test = this.logicalOR();
12993 if (this.expect('?')) {
12994 alternate = this.expression();
12995 if (this.consume(':')) {
12996 consequent = this.expression();
12997 return { type: AST.ConditionalExpression, test: test, alternate: alternate, consequent: consequent};
13003 logicalOR: function() {
13004 var left = this.logicalAND();
13005 while (this.expect('||')) {
13006 left = { type: AST.LogicalExpression, operator: '||', left: left, right: this.logicalAND() };
13011 logicalAND: function() {
13012 var left = this.equality();
13013 while (this.expect('&&')) {
13014 left = { type: AST.LogicalExpression, operator: '&&', left: left, right: this.equality()};
13019 equality: function() {
13020 var left = this.relational();
13022 while ((token = this.expect('==','!=','===','!=='))) {
13023 left = { type: AST.BinaryExpression, operator: token.text, left: left, right: this.relational() };
13028 relational: function() {
13029 var left = this.additive();
13031 while ((token = this.expect('<', '>', '<=', '>='))) {
13032 left = { type: AST.BinaryExpression, operator: token.text, left: left, right: this.additive() };
13037 additive: function() {
13038 var left = this.multiplicative();
13040 while ((token = this.expect('+','-'))) {
13041 left = { type: AST.BinaryExpression, operator: token.text, left: left, right: this.multiplicative() };
13046 multiplicative: function() {
13047 var left = this.unary();
13049 while ((token = this.expect('*','/','%'))) {
13050 left = { type: AST.BinaryExpression, operator: token.text, left: left, right: this.unary() };
13055 unary: function() {
13057 if ((token = this.expect('+', '-', '!'))) {
13058 return { type: AST.UnaryExpression, operator: token.text, prefix: true, argument: this.unary() };
13060 return this.primary();
13064 primary: function() {
13066 if (this.expect('(')) {
13067 primary = this.filterChain();
13069 } else if (this.expect('[')) {
13070 primary = this.arrayDeclaration();
13071 } else if (this.expect('{')) {
13072 primary = this.object();
13073 } else if (this.constants.hasOwnProperty(this.peek().text)) {
13074 primary = copy(this.constants[this.consume().text]);
13075 } else if (this.peek().identifier) {
13076 primary = this.identifier();
13077 } else if (this.peek().constant) {
13078 primary = this.constant();
13080 this.throwError('not a primary expression', this.peek());
13084 while ((next = this.expect('(', '[', '.'))) {
13085 if (next.text === '(') {
13086 primary = {type: AST.CallExpression, callee: primary, arguments: this.parseArguments() };
13088 } else if (next.text === '[') {
13089 primary = { type: AST.MemberExpression, object: primary, property: this.expression(), computed: true };
13091 } else if (next.text === '.') {
13092 primary = { type: AST.MemberExpression, object: primary, property: this.identifier(), computed: false };
13094 this.throwError('IMPOSSIBLE');
13100 filter: function(baseExpression) {
13101 var args = [baseExpression];
13102 var result = {type: AST.CallExpression, callee: this.identifier(), arguments: args, filter: true};
13104 while (this.expect(':')) {
13105 args.push(this.expression());
13111 parseArguments: function() {
13113 if (this.peekToken().text !== ')') {
13115 args.push(this.expression());
13116 } while (this.expect(','));
13121 identifier: function() {
13122 var token = this.consume();
13123 if (!token.identifier) {
13124 this.throwError('is not a valid identifier', token);
13126 return { type: AST.Identifier, name: token.text };
13129 constant: function() {
13130 // TODO check that it is a constant
13131 return { type: AST.Literal, value: this.consume().value };
13134 arrayDeclaration: function() {
13136 if (this.peekToken().text !== ']') {
13138 if (this.peek(']')) {
13139 // Support trailing commas per ES5.1.
13142 elements.push(this.expression());
13143 } while (this.expect(','));
13147 return { type: AST.ArrayExpression, elements: elements };
13150 object: function() {
13151 var properties = [], property;
13152 if (this.peekToken().text !== '}') {
13154 if (this.peek('}')) {
13155 // Support trailing commas per ES5.1.
13158 property = {type: AST.Property, kind: 'init'};
13159 if (this.peek().constant) {
13160 property.key = this.constant();
13161 } else if (this.peek().identifier) {
13162 property.key = this.identifier();
13164 this.throwError("invalid key", this.peek());
13167 property.value = this.expression();
13168 properties.push(property);
13169 } while (this.expect(','));
13173 return {type: AST.ObjectExpression, properties: properties };
13176 throwError: function(msg, token) {
13177 throw $parseMinErr('syntax',
13178 'Syntax Error: Token \'{0}\' {1} at column {2} of the expression [{3}] starting at [{4}].',
13179 token.text, msg, (token.index + 1), this.text, this.text.substring(token.index));
13182 consume: function(e1) {
13183 if (this.tokens.length === 0) {
13184 throw $parseMinErr('ueoe', 'Unexpected end of expression: {0}', this.text);
13187 var token = this.expect(e1);
13189 this.throwError('is unexpected, expecting [' + e1 + ']', this.peek());
13194 peekToken: function() {
13195 if (this.tokens.length === 0) {
13196 throw $parseMinErr('ueoe', 'Unexpected end of expression: {0}', this.text);
13198 return this.tokens[0];
13201 peek: function(e1, e2, e3, e4) {
13202 return this.peekAhead(0, e1, e2, e3, e4);
13205 peekAhead: function(i, e1, e2, e3, e4) {
13206 if (this.tokens.length > i) {
13207 var token = this.tokens[i];
13208 var t = token.text;
13209 if (t === e1 || t === e2 || t === e3 || t === e4 ||
13210 (!e1 && !e2 && !e3 && !e4)) {
13217 expect: function(e1, e2, e3, e4) {
13218 var token = this.peek(e1, e2, e3, e4);
13220 this.tokens.shift();
13227 /* `undefined` is not a constant, it is an identifier,
13228 * but using it as an identifier is not supported
13231 'true': { type: AST.Literal, value: true },
13232 'false': { type: AST.Literal, value: false },
13233 'null': { type: AST.Literal, value: null },
13234 'undefined': {type: AST.Literal, value: undefined },
13235 'this': {type: AST.ThisExpression }
13239 function ifDefined(v, d) {
13240 return typeof v !== 'undefined' ? v : d;
13243 function plusFn(l, r) {
13244 if (typeof l === 'undefined') return r;
13245 if (typeof r === 'undefined') return l;
13249 function isStateless($filter, filterName) {
13250 var fn = $filter(filterName);
13251 return !fn.$stateful;
13254 function findConstantAndWatchExpressions(ast, $filter) {
13257 switch (ast.type) {
13259 allConstants = true;
13260 forEach(ast.body, function(expr) {
13261 findConstantAndWatchExpressions(expr.expression, $filter);
13262 allConstants = allConstants && expr.expression.constant;
13264 ast.constant = allConstants;
13267 ast.constant = true;
13270 case AST.UnaryExpression:
13271 findConstantAndWatchExpressions(ast.argument, $filter);
13272 ast.constant = ast.argument.constant;
13273 ast.toWatch = ast.argument.toWatch;
13275 case AST.BinaryExpression:
13276 findConstantAndWatchExpressions(ast.left, $filter);
13277 findConstantAndWatchExpressions(ast.right, $filter);
13278 ast.constant = ast.left.constant && ast.right.constant;
13279 ast.toWatch = ast.left.toWatch.concat(ast.right.toWatch);
13281 case AST.LogicalExpression:
13282 findConstantAndWatchExpressions(ast.left, $filter);
13283 findConstantAndWatchExpressions(ast.right, $filter);
13284 ast.constant = ast.left.constant && ast.right.constant;
13285 ast.toWatch = ast.constant ? [] : [ast];
13287 case AST.ConditionalExpression:
13288 findConstantAndWatchExpressions(ast.test, $filter);
13289 findConstantAndWatchExpressions(ast.alternate, $filter);
13290 findConstantAndWatchExpressions(ast.consequent, $filter);
13291 ast.constant = ast.test.constant && ast.alternate.constant && ast.consequent.constant;
13292 ast.toWatch = ast.constant ? [] : [ast];
13294 case AST.Identifier:
13295 ast.constant = false;
13296 ast.toWatch = [ast];
13298 case AST.MemberExpression:
13299 findConstantAndWatchExpressions(ast.object, $filter);
13300 if (ast.computed) {
13301 findConstantAndWatchExpressions(ast.property, $filter);
13303 ast.constant = ast.object.constant && (!ast.computed || ast.property.constant);
13304 ast.toWatch = [ast];
13306 case AST.CallExpression:
13307 allConstants = ast.filter ? isStateless($filter, ast.callee.name) : false;
13309 forEach(ast.arguments, function(expr) {
13310 findConstantAndWatchExpressions(expr, $filter);
13311 allConstants = allConstants && expr.constant;
13312 if (!expr.constant) {
13313 argsToWatch.push.apply(argsToWatch, expr.toWatch);
13316 ast.constant = allConstants;
13317 ast.toWatch = ast.filter && isStateless($filter, ast.callee.name) ? argsToWatch : [ast];
13319 case AST.AssignmentExpression:
13320 findConstantAndWatchExpressions(ast.left, $filter);
13321 findConstantAndWatchExpressions(ast.right, $filter);
13322 ast.constant = ast.left.constant && ast.right.constant;
13323 ast.toWatch = [ast];
13325 case AST.ArrayExpression:
13326 allConstants = true;
13328 forEach(ast.elements, function(expr) {
13329 findConstantAndWatchExpressions(expr, $filter);
13330 allConstants = allConstants && expr.constant;
13331 if (!expr.constant) {
13332 argsToWatch.push.apply(argsToWatch, expr.toWatch);
13335 ast.constant = allConstants;
13336 ast.toWatch = argsToWatch;
13338 case AST.ObjectExpression:
13339 allConstants = true;
13341 forEach(ast.properties, function(property) {
13342 findConstantAndWatchExpressions(property.value, $filter);
13343 allConstants = allConstants && property.value.constant;
13344 if (!property.value.constant) {
13345 argsToWatch.push.apply(argsToWatch, property.value.toWatch);
13348 ast.constant = allConstants;
13349 ast.toWatch = argsToWatch;
13351 case AST.ThisExpression:
13352 ast.constant = false;
13358 function getInputs(body) {
13359 if (body.length != 1) return;
13360 var lastExpression = body[0].expression;
13361 var candidate = lastExpression.toWatch;
13362 if (candidate.length !== 1) return candidate;
13363 return candidate[0] !== lastExpression ? candidate : undefined;
13366 function isAssignable(ast) {
13367 return ast.type === AST.Identifier || ast.type === AST.MemberExpression;
13370 function assignableAST(ast) {
13371 if (ast.body.length === 1 && isAssignable(ast.body[0].expression)) {
13372 return {type: AST.AssignmentExpression, left: ast.body[0].expression, right: {type: AST.NGValueParameter}, operator: '='};
13376 function isLiteral(ast) {
13377 return ast.body.length === 0 ||
13378 ast.body.length === 1 && (
13379 ast.body[0].expression.type === AST.Literal ||
13380 ast.body[0].expression.type === AST.ArrayExpression ||
13381 ast.body[0].expression.type === AST.ObjectExpression);
13384 function isConstant(ast) {
13385 return ast.constant;
13388 function ASTCompiler(astBuilder, $filter) {
13389 this.astBuilder = astBuilder;
13390 this.$filter = $filter;
13393 ASTCompiler.prototype = {
13394 compile: function(expression, expensiveChecks) {
13396 var ast = this.astBuilder.ast(expression);
13400 expensiveChecks: expensiveChecks,
13401 fn: {vars: [], body: [], own: {}},
13402 assign: {vars: [], body: [], own: {}},
13405 findConstantAndWatchExpressions(ast, self.$filter);
13408 this.stage = 'assign';
13409 if ((assignable = assignableAST(ast))) {
13410 this.state.computing = 'assign';
13411 var result = this.nextId();
13412 this.recurse(assignable, result);
13413 this.return_(result);
13414 extra = 'fn.assign=' + this.generateFunction('assign', 's,v,l');
13416 var toWatch = getInputs(ast.body);
13417 self.stage = 'inputs';
13418 forEach(toWatch, function(watch, key) {
13419 var fnKey = 'fn' + key;
13420 self.state[fnKey] = {vars: [], body: [], own: {}};
13421 self.state.computing = fnKey;
13422 var intoId = self.nextId();
13423 self.recurse(watch, intoId);
13424 self.return_(intoId);
13425 self.state.inputs.push(fnKey);
13426 watch.watchId = key;
13428 this.state.computing = 'fn';
13429 this.stage = 'main';
13432 // The build and minification steps remove the string "use strict" from the code, but this is done using a regex.
13433 // This is a workaround for this until we do a better job at only removing the prefix only when we should.
13434 '"' + this.USE + ' ' + this.STRICT + '";\n' +
13435 this.filterPrefix() +
13436 'var fn=' + this.generateFunction('fn', 's,l,a,i') +
13442 var fn = (new Function('$filter',
13443 'ensureSafeMemberName',
13444 'ensureSafeObject',
13445 'ensureSafeFunction',
13447 'ensureSafeAssignContext',
13453 ensureSafeMemberName,
13455 ensureSafeFunction,
13457 ensureSafeAssignContext,
13462 this.state = this.stage = undefined;
13463 fn.literal = isLiteral(ast);
13464 fn.constant = isConstant(ast);
13472 watchFns: function() {
13474 var fns = this.state.inputs;
13476 forEach(fns, function(name) {
13477 result.push('var ' + name + '=' + self.generateFunction(name, 's'));
13480 result.push('fn.inputs=[' + fns.join(',') + '];');
13482 return result.join('');
13485 generateFunction: function(name, params) {
13486 return 'function(' + params + '){' +
13487 this.varsPrefix(name) +
13492 filterPrefix: function() {
13495 forEach(this.state.filters, function(id, filter) {
13496 parts.push(id + '=$filter(' + self.escape(filter) + ')');
13498 if (parts.length) return 'var ' + parts.join(',') + ';';
13502 varsPrefix: function(section) {
13503 return this.state[section].vars.length ? 'var ' + this.state[section].vars.join(',') + ';' : '';
13506 body: function(section) {
13507 return this.state[section].body.join('');
13510 recurse: function(ast, intoId, nameId, recursionFn, create, skipWatchIdCheck) {
13511 var left, right, self = this, args, expression;
13512 recursionFn = recursionFn || noop;
13513 if (!skipWatchIdCheck && isDefined(ast.watchId)) {
13514 intoId = intoId || this.nextId();
13516 this.lazyAssign(intoId, this.computedMember('i', ast.watchId)),
13517 this.lazyRecurse(ast, intoId, nameId, recursionFn, create, true)
13521 switch (ast.type) {
13523 forEach(ast.body, function(expression, pos) {
13524 self.recurse(expression.expression, undefined, undefined, function(expr) { right = expr; });
13525 if (pos !== ast.body.length - 1) {
13526 self.current().body.push(right, ';');
13528 self.return_(right);
13533 expression = this.escape(ast.value);
13534 this.assign(intoId, expression);
13535 recursionFn(expression);
13537 case AST.UnaryExpression:
13538 this.recurse(ast.argument, undefined, undefined, function(expr) { right = expr; });
13539 expression = ast.operator + '(' + this.ifDefined(right, 0) + ')';
13540 this.assign(intoId, expression);
13541 recursionFn(expression);
13543 case AST.BinaryExpression:
13544 this.recurse(ast.left, undefined, undefined, function(expr) { left = expr; });
13545 this.recurse(ast.right, undefined, undefined, function(expr) { right = expr; });
13546 if (ast.operator === '+') {
13547 expression = this.plus(left, right);
13548 } else if (ast.operator === '-') {
13549 expression = this.ifDefined(left, 0) + ast.operator + this.ifDefined(right, 0);
13551 expression = '(' + left + ')' + ast.operator + '(' + right + ')';
13553 this.assign(intoId, expression);
13554 recursionFn(expression);
13556 case AST.LogicalExpression:
13557 intoId = intoId || this.nextId();
13558 self.recurse(ast.left, intoId);
13559 self.if_(ast.operator === '&&' ? intoId : self.not(intoId), self.lazyRecurse(ast.right, intoId));
13560 recursionFn(intoId);
13562 case AST.ConditionalExpression:
13563 intoId = intoId || this.nextId();
13564 self.recurse(ast.test, intoId);
13565 self.if_(intoId, self.lazyRecurse(ast.alternate, intoId), self.lazyRecurse(ast.consequent, intoId));
13566 recursionFn(intoId);
13568 case AST.Identifier:
13569 intoId = intoId || this.nextId();
13571 nameId.context = self.stage === 'inputs' ? 's' : this.assign(this.nextId(), this.getHasOwnProperty('l', ast.name) + '?l:s');
13572 nameId.computed = false;
13573 nameId.name = ast.name;
13575 ensureSafeMemberName(ast.name);
13576 self.if_(self.stage === 'inputs' || self.not(self.getHasOwnProperty('l', ast.name)),
13578 self.if_(self.stage === 'inputs' || 's', function() {
13579 if (create && create !== 1) {
13581 self.not(self.nonComputedMember('s', ast.name)),
13582 self.lazyAssign(self.nonComputedMember('s', ast.name), '{}'));
13584 self.assign(intoId, self.nonComputedMember('s', ast.name));
13586 }, intoId && self.lazyAssign(intoId, self.nonComputedMember('l', ast.name))
13588 if (self.state.expensiveChecks || isPossiblyDangerousMemberName(ast.name)) {
13589 self.addEnsureSafeObject(intoId);
13591 recursionFn(intoId);
13593 case AST.MemberExpression:
13594 left = nameId && (nameId.context = this.nextId()) || this.nextId();
13595 intoId = intoId || this.nextId();
13596 self.recurse(ast.object, left, undefined, function() {
13597 self.if_(self.notNull(left), function() {
13598 if (ast.computed) {
13599 right = self.nextId();
13600 self.recurse(ast.property, right);
13601 self.getStringValue(right);
13602 self.addEnsureSafeMemberName(right);
13603 if (create && create !== 1) {
13604 self.if_(self.not(self.computedMember(left, right)), self.lazyAssign(self.computedMember(left, right), '{}'));
13606 expression = self.ensureSafeObject(self.computedMember(left, right));
13607 self.assign(intoId, expression);
13609 nameId.computed = true;
13610 nameId.name = right;
13613 ensureSafeMemberName(ast.property.name);
13614 if (create && create !== 1) {
13615 self.if_(self.not(self.nonComputedMember(left, ast.property.name)), self.lazyAssign(self.nonComputedMember(left, ast.property.name), '{}'));
13617 expression = self.nonComputedMember(left, ast.property.name);
13618 if (self.state.expensiveChecks || isPossiblyDangerousMemberName(ast.property.name)) {
13619 expression = self.ensureSafeObject(expression);
13621 self.assign(intoId, expression);
13623 nameId.computed = false;
13624 nameId.name = ast.property.name;
13628 self.assign(intoId, 'undefined');
13630 recursionFn(intoId);
13633 case AST.CallExpression:
13634 intoId = intoId || this.nextId();
13636 right = self.filter(ast.callee.name);
13638 forEach(ast.arguments, function(expr) {
13639 var argument = self.nextId();
13640 self.recurse(expr, argument);
13641 args.push(argument);
13643 expression = right + '(' + args.join(',') + ')';
13644 self.assign(intoId, expression);
13645 recursionFn(intoId);
13647 right = self.nextId();
13650 self.recurse(ast.callee, right, left, function() {
13651 self.if_(self.notNull(right), function() {
13652 self.addEnsureSafeFunction(right);
13653 forEach(ast.arguments, function(expr) {
13654 self.recurse(expr, self.nextId(), undefined, function(argument) {
13655 args.push(self.ensureSafeObject(argument));
13659 if (!self.state.expensiveChecks) {
13660 self.addEnsureSafeObject(left.context);
13662 expression = self.member(left.context, left.name, left.computed) + '(' + args.join(',') + ')';
13664 expression = right + '(' + args.join(',') + ')';
13666 expression = self.ensureSafeObject(expression);
13667 self.assign(intoId, expression);
13669 self.assign(intoId, 'undefined');
13671 recursionFn(intoId);
13675 case AST.AssignmentExpression:
13676 right = this.nextId();
13678 if (!isAssignable(ast.left)) {
13679 throw $parseMinErr('lval', 'Trying to assing a value to a non l-value');
13681 this.recurse(ast.left, undefined, left, function() {
13682 self.if_(self.notNull(left.context), function() {
13683 self.recurse(ast.right, right);
13684 self.addEnsureSafeObject(self.member(left.context, left.name, left.computed));
13685 self.addEnsureSafeAssignContext(left.context);
13686 expression = self.member(left.context, left.name, left.computed) + ast.operator + right;
13687 self.assign(intoId, expression);
13688 recursionFn(intoId || expression);
13692 case AST.ArrayExpression:
13694 forEach(ast.elements, function(expr) {
13695 self.recurse(expr, self.nextId(), undefined, function(argument) {
13696 args.push(argument);
13699 expression = '[' + args.join(',') + ']';
13700 this.assign(intoId, expression);
13701 recursionFn(expression);
13703 case AST.ObjectExpression:
13705 forEach(ast.properties, function(property) {
13706 self.recurse(property.value, self.nextId(), undefined, function(expr) {
13707 args.push(self.escape(
13708 property.key.type === AST.Identifier ? property.key.name :
13709 ('' + property.key.value)) +
13713 expression = '{' + args.join(',') + '}';
13714 this.assign(intoId, expression);
13715 recursionFn(expression);
13717 case AST.ThisExpression:
13718 this.assign(intoId, 's');
13721 case AST.NGValueParameter:
13722 this.assign(intoId, 'v');
13728 getHasOwnProperty: function(element, property) {
13729 var key = element + '.' + property;
13730 var own = this.current().own;
13731 if (!own.hasOwnProperty(key)) {
13732 own[key] = this.nextId(false, element + '&&(' + this.escape(property) + ' in ' + element + ')');
13737 assign: function(id, value) {
13739 this.current().body.push(id, '=', value, ';');
13743 filter: function(filterName) {
13744 if (!this.state.filters.hasOwnProperty(filterName)) {
13745 this.state.filters[filterName] = this.nextId(true);
13747 return this.state.filters[filterName];
13750 ifDefined: function(id, defaultValue) {
13751 return 'ifDefined(' + id + ',' + this.escape(defaultValue) + ')';
13754 plus: function(left, right) {
13755 return 'plus(' + left + ',' + right + ')';
13758 return_: function(id) {
13759 this.current().body.push('return ', id, ';');
13762 if_: function(test, alternate, consequent) {
13763 if (test === true) {
13766 var body = this.current().body;
13767 body.push('if(', test, '){');
13771 body.push('else{');
13778 not: function(expression) {
13779 return '!(' + expression + ')';
13782 notNull: function(expression) {
13783 return expression + '!=null';
13786 nonComputedMember: function(left, right) {
13787 return left + '.' + right;
13790 computedMember: function(left, right) {
13791 return left + '[' + right + ']';
13794 member: function(left, right, computed) {
13795 if (computed) return this.computedMember(left, right);
13796 return this.nonComputedMember(left, right);
13799 addEnsureSafeObject: function(item) {
13800 this.current().body.push(this.ensureSafeObject(item), ';');
13803 addEnsureSafeMemberName: function(item) {
13804 this.current().body.push(this.ensureSafeMemberName(item), ';');
13807 addEnsureSafeFunction: function(item) {
13808 this.current().body.push(this.ensureSafeFunction(item), ';');
13811 addEnsureSafeAssignContext: function(item) {
13812 this.current().body.push(this.ensureSafeAssignContext(item), ';');
13815 ensureSafeObject: function(item) {
13816 return 'ensureSafeObject(' + item + ',text)';
13819 ensureSafeMemberName: function(item) {
13820 return 'ensureSafeMemberName(' + item + ',text)';
13823 ensureSafeFunction: function(item) {
13824 return 'ensureSafeFunction(' + item + ',text)';
13827 getStringValue: function(item) {
13828 this.assign(item, 'getStringValue(' + item + ',text)');
13831 ensureSafeAssignContext: function(item) {
13832 return 'ensureSafeAssignContext(' + item + ',text)';
13835 lazyRecurse: function(ast, intoId, nameId, recursionFn, create, skipWatchIdCheck) {
13837 return function() {
13838 self.recurse(ast, intoId, nameId, recursionFn, create, skipWatchIdCheck);
13842 lazyAssign: function(id, value) {
13844 return function() {
13845 self.assign(id, value);
13849 stringEscapeRegex: /[^ a-zA-Z0-9]/g,
13851 stringEscapeFn: function(c) {
13852 return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
13855 escape: function(value) {
13856 if (isString(value)) return "'" + value.replace(this.stringEscapeRegex, this.stringEscapeFn) + "'";
13857 if (isNumber(value)) return value.toString();
13858 if (value === true) return 'true';
13859 if (value === false) return 'false';
13860 if (value === null) return 'null';
13861 if (typeof value === 'undefined') return 'undefined';
13863 throw $parseMinErr('esc', 'IMPOSSIBLE');
13866 nextId: function(skip, init) {
13867 var id = 'v' + (this.state.nextId++);
13869 this.current().vars.push(id + (init ? '=' + init : ''));
13874 current: function() {
13875 return this.state[this.state.computing];
13880 function ASTInterpreter(astBuilder, $filter) {
13881 this.astBuilder = astBuilder;
13882 this.$filter = $filter;
13885 ASTInterpreter.prototype = {
13886 compile: function(expression, expensiveChecks) {
13888 var ast = this.astBuilder.ast(expression);
13889 this.expression = expression;
13890 this.expensiveChecks = expensiveChecks;
13891 findConstantAndWatchExpressions(ast, self.$filter);
13894 if ((assignable = assignableAST(ast))) {
13895 assign = this.recurse(assignable);
13897 var toWatch = getInputs(ast.body);
13901 forEach(toWatch, function(watch, key) {
13902 var input = self.recurse(watch);
13903 watch.input = input;
13904 inputs.push(input);
13905 watch.watchId = key;
13908 var expressions = [];
13909 forEach(ast.body, function(expression) {
13910 expressions.push(self.recurse(expression.expression));
13912 var fn = ast.body.length === 0 ? function() {} :
13913 ast.body.length === 1 ? expressions[0] :
13914 function(scope, locals) {
13916 forEach(expressions, function(exp) {
13917 lastValue = exp(scope, locals);
13922 fn.assign = function(scope, value, locals) {
13923 return assign(scope, locals, value);
13927 fn.inputs = inputs;
13929 fn.literal = isLiteral(ast);
13930 fn.constant = isConstant(ast);
13934 recurse: function(ast, context, create) {
13935 var left, right, self = this, args, expression;
13937 return this.inputs(ast.input, ast.watchId);
13939 switch (ast.type) {
13941 return this.value(ast.value, context);
13942 case AST.UnaryExpression:
13943 right = this.recurse(ast.argument);
13944 return this['unary' + ast.operator](right, context);
13945 case AST.BinaryExpression:
13946 left = this.recurse(ast.left);
13947 right = this.recurse(ast.right);
13948 return this['binary' + ast.operator](left, right, context);
13949 case AST.LogicalExpression:
13950 left = this.recurse(ast.left);
13951 right = this.recurse(ast.right);
13952 return this['binary' + ast.operator](left, right, context);
13953 case AST.ConditionalExpression:
13954 return this['ternary?:'](
13955 this.recurse(ast.test),
13956 this.recurse(ast.alternate),
13957 this.recurse(ast.consequent),
13960 case AST.Identifier:
13961 ensureSafeMemberName(ast.name, self.expression);
13962 return self.identifier(ast.name,
13963 self.expensiveChecks || isPossiblyDangerousMemberName(ast.name),
13964 context, create, self.expression);
13965 case AST.MemberExpression:
13966 left = this.recurse(ast.object, false, !!create);
13967 if (!ast.computed) {
13968 ensureSafeMemberName(ast.property.name, self.expression);
13969 right = ast.property.name;
13971 if (ast.computed) right = this.recurse(ast.property);
13972 return ast.computed ?
13973 this.computedMember(left, right, context, create, self.expression) :
13974 this.nonComputedMember(left, right, self.expensiveChecks, context, create, self.expression);
13975 case AST.CallExpression:
13977 forEach(ast.arguments, function(expr) {
13978 args.push(self.recurse(expr));
13980 if (ast.filter) right = this.$filter(ast.callee.name);
13981 if (!ast.filter) right = this.recurse(ast.callee, true);
13982 return ast.filter ?
13983 function(scope, locals, assign, inputs) {
13985 for (var i = 0; i < args.length; ++i) {
13986 values.push(args[i](scope, locals, assign, inputs));
13988 var value = right.apply(undefined, values, inputs);
13989 return context ? {context: undefined, name: undefined, value: value} : value;
13991 function(scope, locals, assign, inputs) {
13992 var rhs = right(scope, locals, assign, inputs);
13994 if (rhs.value != null) {
13995 ensureSafeObject(rhs.context, self.expression);
13996 ensureSafeFunction(rhs.value, self.expression);
13998 for (var i = 0; i < args.length; ++i) {
13999 values.push(ensureSafeObject(args[i](scope, locals, assign, inputs), self.expression));
14001 value = ensureSafeObject(rhs.value.apply(rhs.context, values), self.expression);
14003 return context ? {value: value} : value;
14005 case AST.AssignmentExpression:
14006 left = this.recurse(ast.left, true, 1);
14007 right = this.recurse(ast.right);
14008 return function(scope, locals, assign, inputs) {
14009 var lhs = left(scope, locals, assign, inputs);
14010 var rhs = right(scope, locals, assign, inputs);
14011 ensureSafeObject(lhs.value, self.expression);
14012 ensureSafeAssignContext(lhs.context);
14013 lhs.context[lhs.name] = rhs;
14014 return context ? {value: rhs} : rhs;
14016 case AST.ArrayExpression:
14018 forEach(ast.elements, function(expr) {
14019 args.push(self.recurse(expr));
14021 return function(scope, locals, assign, inputs) {
14023 for (var i = 0; i < args.length; ++i) {
14024 value.push(args[i](scope, locals, assign, inputs));
14026 return context ? {value: value} : value;
14028 case AST.ObjectExpression:
14030 forEach(ast.properties, function(property) {
14031 args.push({key: property.key.type === AST.Identifier ?
14032 property.key.name :
14033 ('' + property.key.value),
14034 value: self.recurse(property.value)
14037 return function(scope, locals, assign, inputs) {
14039 for (var i = 0; i < args.length; ++i) {
14040 value[args[i].key] = args[i].value(scope, locals, assign, inputs);
14042 return context ? {value: value} : value;
14044 case AST.ThisExpression:
14045 return function(scope) {
14046 return context ? {value: scope} : scope;
14048 case AST.NGValueParameter:
14049 return function(scope, locals, assign, inputs) {
14050 return context ? {value: assign} : assign;
14055 'unary+': function(argument, context) {
14056 return function(scope, locals, assign, inputs) {
14057 var arg = argument(scope, locals, assign, inputs);
14058 if (isDefined(arg)) {
14063 return context ? {value: arg} : arg;
14066 'unary-': function(argument, context) {
14067 return function(scope, locals, assign, inputs) {
14068 var arg = argument(scope, locals, assign, inputs);
14069 if (isDefined(arg)) {
14074 return context ? {value: arg} : arg;
14077 'unary!': function(argument, context) {
14078 return function(scope, locals, assign, inputs) {
14079 var arg = !argument(scope, locals, assign, inputs);
14080 return context ? {value: arg} : arg;
14083 'binary+': function(left, right, context) {
14084 return function(scope, locals, assign, inputs) {
14085 var lhs = left(scope, locals, assign, inputs);
14086 var rhs = right(scope, locals, assign, inputs);
14087 var arg = plusFn(lhs, rhs);
14088 return context ? {value: arg} : arg;
14091 'binary-': function(left, right, context) {
14092 return function(scope, locals, assign, inputs) {
14093 var lhs = left(scope, locals, assign, inputs);
14094 var rhs = right(scope, locals, assign, inputs);
14095 var arg = (isDefined(lhs) ? lhs : 0) - (isDefined(rhs) ? rhs : 0);
14096 return context ? {value: arg} : arg;
14099 'binary*': function(left, right, context) {
14100 return function(scope, locals, assign, inputs) {
14101 var arg = left(scope, locals, assign, inputs) * right(scope, locals, assign, inputs);
14102 return context ? {value: arg} : arg;
14105 'binary/': function(left, right, context) {
14106 return function(scope, locals, assign, inputs) {
14107 var arg = left(scope, locals, assign, inputs) / right(scope, locals, assign, inputs);
14108 return context ? {value: arg} : arg;
14111 'binary%': function(left, right, context) {
14112 return function(scope, locals, assign, inputs) {
14113 var arg = left(scope, locals, assign, inputs) % right(scope, locals, assign, inputs);
14114 return context ? {value: arg} : arg;
14117 'binary===': function(left, right, context) {
14118 return function(scope, locals, assign, inputs) {
14119 var arg = left(scope, locals, assign, inputs) === right(scope, locals, assign, inputs);
14120 return context ? {value: arg} : arg;
14123 'binary!==': function(left, right, context) {
14124 return function(scope, locals, assign, inputs) {
14125 var arg = left(scope, locals, assign, inputs) !== right(scope, locals, assign, inputs);
14126 return context ? {value: arg} : arg;
14129 'binary==': function(left, right, context) {
14130 return function(scope, locals, assign, inputs) {
14131 var arg = left(scope, locals, assign, inputs) == right(scope, locals, assign, inputs);
14132 return context ? {value: arg} : arg;
14135 'binary!=': function(left, right, context) {
14136 return function(scope, locals, assign, inputs) {
14137 var arg = left(scope, locals, assign, inputs) != right(scope, locals, assign, inputs);
14138 return context ? {value: arg} : arg;
14141 'binary<': function(left, right, context) {
14142 return function(scope, locals, assign, inputs) {
14143 var arg = left(scope, locals, assign, inputs) < right(scope, locals, assign, inputs);
14144 return context ? {value: arg} : arg;
14147 'binary>': function(left, right, context) {
14148 return function(scope, locals, assign, inputs) {
14149 var arg = left(scope, locals, assign, inputs) > right(scope, locals, assign, inputs);
14150 return context ? {value: arg} : arg;
14153 'binary<=': function(left, right, context) {
14154 return function(scope, locals, assign, inputs) {
14155 var arg = left(scope, locals, assign, inputs) <= right(scope, locals, assign, inputs);
14156 return context ? {value: arg} : arg;
14159 'binary>=': function(left, right, context) {
14160 return function(scope, locals, assign, inputs) {
14161 var arg = left(scope, locals, assign, inputs) >= right(scope, locals, assign, inputs);
14162 return context ? {value: arg} : arg;
14165 'binary&&': function(left, right, context) {
14166 return function(scope, locals, assign, inputs) {
14167 var arg = left(scope, locals, assign, inputs) && right(scope, locals, assign, inputs);
14168 return context ? {value: arg} : arg;
14171 'binary||': function(left, right, context) {
14172 return function(scope, locals, assign, inputs) {
14173 var arg = left(scope, locals, assign, inputs) || right(scope, locals, assign, inputs);
14174 return context ? {value: arg} : arg;
14177 'ternary?:': function(test, alternate, consequent, context) {
14178 return function(scope, locals, assign, inputs) {
14179 var arg = test(scope, locals, assign, inputs) ? alternate(scope, locals, assign, inputs) : consequent(scope, locals, assign, inputs);
14180 return context ? {value: arg} : arg;
14183 value: function(value, context) {
14184 return function() { return context ? {context: undefined, name: undefined, value: value} : value; };
14186 identifier: function(name, expensiveChecks, context, create, expression) {
14187 return function(scope, locals, assign, inputs) {
14188 var base = locals && (name in locals) ? locals : scope;
14189 if (create && create !== 1 && base && !(base[name])) {
14192 var value = base ? base[name] : undefined;
14193 if (expensiveChecks) {
14194 ensureSafeObject(value, expression);
14197 return {context: base, name: name, value: value};
14203 computedMember: function(left, right, context, create, expression) {
14204 return function(scope, locals, assign, inputs) {
14205 var lhs = left(scope, locals, assign, inputs);
14209 rhs = right(scope, locals, assign, inputs);
14210 rhs = getStringValue(rhs);
14211 ensureSafeMemberName(rhs, expression);
14212 if (create && create !== 1 && lhs && !(lhs[rhs])) {
14216 ensureSafeObject(value, expression);
14219 return {context: lhs, name: rhs, value: value};
14225 nonComputedMember: function(left, right, expensiveChecks, context, create, expression) {
14226 return function(scope, locals, assign, inputs) {
14227 var lhs = left(scope, locals, assign, inputs);
14228 if (create && create !== 1 && lhs && !(lhs[right])) {
14231 var value = lhs != null ? lhs[right] : undefined;
14232 if (expensiveChecks || isPossiblyDangerousMemberName(right)) {
14233 ensureSafeObject(value, expression);
14236 return {context: lhs, name: right, value: value};
14242 inputs: function(input, watchId) {
14243 return function(scope, value, locals, inputs) {
14244 if (inputs) return inputs[watchId];
14245 return input(scope, value, locals);
14253 var Parser = function(lexer, $filter, options) {
14254 this.lexer = lexer;
14255 this.$filter = $filter;
14256 this.options = options;
14257 this.ast = new AST(this.lexer);
14258 this.astCompiler = options.csp ? new ASTInterpreter(this.ast, $filter) :
14259 new ASTCompiler(this.ast, $filter);
14262 Parser.prototype = {
14263 constructor: Parser,
14265 parse: function(text) {
14266 return this.astCompiler.compile(text, this.options.expensiveChecks);
14270 var getterFnCacheDefault = createMap();
14271 var getterFnCacheExpensive = createMap();
14273 function isPossiblyDangerousMemberName(name) {
14274 return name == 'constructor';
14277 var objectValueOf = Object.prototype.valueOf;
14279 function getValueOf(value) {
14280 return isFunction(value.valueOf) ? value.valueOf() : objectValueOf.call(value);
14283 ///////////////////////////////////
14292 * Converts Angular {@link guide/expression expression} into a function.
14295 * var getter = $parse('user.name');
14296 * var setter = getter.assign;
14297 * var context = {user:{name:'angular'}};
14298 * var locals = {user:{name:'local'}};
14300 * expect(getter(context)).toEqual('angular');
14301 * setter(context, 'newValue');
14302 * expect(context.user.name).toEqual('newValue');
14303 * expect(getter(context, locals)).toEqual('local');
14307 * @param {string} expression String expression to compile.
14308 * @returns {function(context, locals)} a function which represents the compiled expression:
14310 * * `context` – `{object}` – an object against which any expressions embedded in the strings
14311 * are evaluated against (typically a scope object).
14312 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
14315 * The returned function also has the following properties:
14316 * * `literal` – `{boolean}` – whether the expression's top-level node is a JavaScript
14318 * * `constant` – `{boolean}` – whether the expression is made entirely of JavaScript
14319 * constant literals.
14320 * * `assign` – `{?function(context, value)}` – if the expression is assignable, this will be
14321 * set to a function to change its value on the given context.
14328 * @name $parseProvider
14331 * `$parseProvider` can be used for configuring the default behavior of the {@link ng.$parse $parse}
14334 function $ParseProvider() {
14335 var cacheDefault = createMap();
14336 var cacheExpensive = createMap();
14338 this.$get = ['$filter', function($filter) {
14339 var noUnsafeEval = csp().noUnsafeEval;
14340 var $parseOptions = {
14342 expensiveChecks: false
14344 $parseOptionsExpensive = {
14346 expensiveChecks: true
14349 return function $parse(exp, interceptorFn, expensiveChecks) {
14350 var parsedExpression, oneTime, cacheKey;
14352 switch (typeof exp) {
14357 var cache = (expensiveChecks ? cacheExpensive : cacheDefault);
14358 parsedExpression = cache[cacheKey];
14360 if (!parsedExpression) {
14361 if (exp.charAt(0) === ':' && exp.charAt(1) === ':') {
14363 exp = exp.substring(2);
14365 var parseOptions = expensiveChecks ? $parseOptionsExpensive : $parseOptions;
14366 var lexer = new Lexer(parseOptions);
14367 var parser = new Parser(lexer, $filter, parseOptions);
14368 parsedExpression = parser.parse(exp);
14369 if (parsedExpression.constant) {
14370 parsedExpression.$$watchDelegate = constantWatchDelegate;
14371 } else if (oneTime) {
14372 parsedExpression.$$watchDelegate = parsedExpression.literal ?
14373 oneTimeLiteralWatchDelegate : oneTimeWatchDelegate;
14374 } else if (parsedExpression.inputs) {
14375 parsedExpression.$$watchDelegate = inputsWatchDelegate;
14377 cache[cacheKey] = parsedExpression;
14379 return addInterceptor(parsedExpression, interceptorFn);
14382 return addInterceptor(exp, interceptorFn);
14389 function expressionInputDirtyCheck(newValue, oldValueOfValue) {
14391 if (newValue == null || oldValueOfValue == null) { // null/undefined
14392 return newValue === oldValueOfValue;
14395 if (typeof newValue === 'object') {
14397 // attempt to convert the value to a primitive type
14398 // TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
14399 // be cheaply dirty-checked
14400 newValue = getValueOf(newValue);
14402 if (typeof newValue === 'object') {
14403 // objects/arrays are not supported - deep-watching them would be too expensive
14407 // fall-through to the primitive equality check
14411 return newValue === oldValueOfValue || (newValue !== newValue && oldValueOfValue !== oldValueOfValue);
14414 function inputsWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) {
14415 var inputExpressions = parsedExpression.inputs;
14418 if (inputExpressions.length === 1) {
14419 var oldInputValueOf = expressionInputDirtyCheck; // init to something unique so that equals check fails
14420 inputExpressions = inputExpressions[0];
14421 return scope.$watch(function expressionInputWatch(scope) {
14422 var newInputValue = inputExpressions(scope);
14423 if (!expressionInputDirtyCheck(newInputValue, oldInputValueOf)) {
14424 lastResult = parsedExpression(scope, undefined, undefined, [newInputValue]);
14425 oldInputValueOf = newInputValue && getValueOf(newInputValue);
14428 }, listener, objectEquality, prettyPrintExpression);
14431 var oldInputValueOfValues = [];
14432 var oldInputValues = [];
14433 for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
14434 oldInputValueOfValues[i] = expressionInputDirtyCheck; // init to something unique so that equals check fails
14435 oldInputValues[i] = null;
14438 return scope.$watch(function expressionInputsWatch(scope) {
14439 var changed = false;
14441 for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
14442 var newInputValue = inputExpressions[i](scope);
14443 if (changed || (changed = !expressionInputDirtyCheck(newInputValue, oldInputValueOfValues[i]))) {
14444 oldInputValues[i] = newInputValue;
14445 oldInputValueOfValues[i] = newInputValue && getValueOf(newInputValue);
14450 lastResult = parsedExpression(scope, undefined, undefined, oldInputValues);
14454 }, listener, objectEquality, prettyPrintExpression);
14457 function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression) {
14458 var unwatch, lastValue;
14459 return unwatch = scope.$watch(function oneTimeWatch(scope) {
14460 return parsedExpression(scope);
14461 }, function oneTimeListener(value, old, scope) {
14463 if (isFunction(listener)) {
14464 listener.apply(this, arguments);
14466 if (isDefined(value)) {
14467 scope.$$postDigest(function() {
14468 if (isDefined(lastValue)) {
14473 }, objectEquality);
14476 function oneTimeLiteralWatchDelegate(scope, listener, objectEquality, parsedExpression) {
14477 var unwatch, lastValue;
14478 return unwatch = scope.$watch(function oneTimeWatch(scope) {
14479 return parsedExpression(scope);
14480 }, function oneTimeListener(value, old, scope) {
14482 if (isFunction(listener)) {
14483 listener.call(this, value, old, scope);
14485 if (isAllDefined(value)) {
14486 scope.$$postDigest(function() {
14487 if (isAllDefined(lastValue)) unwatch();
14490 }, objectEquality);
14492 function isAllDefined(value) {
14493 var allDefined = true;
14494 forEach(value, function(val) {
14495 if (!isDefined(val)) allDefined = false;
14501 function constantWatchDelegate(scope, listener, objectEquality, parsedExpression) {
14503 return unwatch = scope.$watch(function constantWatch(scope) {
14504 return parsedExpression(scope);
14505 }, function constantListener(value, old, scope) {
14506 if (isFunction(listener)) {
14507 listener.apply(this, arguments);
14510 }, objectEquality);
14513 function addInterceptor(parsedExpression, interceptorFn) {
14514 if (!interceptorFn) return parsedExpression;
14515 var watchDelegate = parsedExpression.$$watchDelegate;
14516 var useInputs = false;
14519 watchDelegate !== oneTimeLiteralWatchDelegate &&
14520 watchDelegate !== oneTimeWatchDelegate;
14522 var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
14523 var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
14524 return interceptorFn(value, scope, locals);
14525 } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) {
14526 var value = parsedExpression(scope, locals, assign, inputs);
14527 var result = interceptorFn(value, scope, locals);
14528 // we only return the interceptor's result if the
14529 // initial value is defined (for bind-once)
14530 return isDefined(value) ? result : value;
14533 // Propagate $$watchDelegates other then inputsWatchDelegate
14534 if (parsedExpression.$$watchDelegate &&
14535 parsedExpression.$$watchDelegate !== inputsWatchDelegate) {
14536 fn.$$watchDelegate = parsedExpression.$$watchDelegate;
14537 } else if (!interceptorFn.$stateful) {
14538 // If there is an interceptor, but no watchDelegate then treat the interceptor like
14539 // we treat filters - it is assumed to be a pure function unless flagged with $stateful
14540 fn.$$watchDelegate = inputsWatchDelegate;
14541 useInputs = !parsedExpression.inputs;
14542 fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
14553 * @requires $rootScope
14556 * A service that helps you run functions asynchronously, and use their return values (or exceptions)
14557 * when they are done processing.
14559 * This is an implementation of promises/deferred objects inspired by
14560 * [Kris Kowal's Q](https://github.com/kriskowal/q).
14562 * $q can be used in two fashions --- one which is more similar to Kris Kowal's Q or jQuery's Deferred
14563 * implementations, and the other which resembles ES6 promises to some degree.
14567 * The streamlined ES6 style promise is essentially just using $q as a constructor which takes a `resolver`
14568 * function as the first argument. This is similar to the native Promise implementation from ES6 Harmony,
14569 * see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
14571 * While the constructor-style use is supported, not all of the supporting methods from ES6 Harmony promises are
14574 * It can be used like so:
14577 * // for the purpose of this example let's assume that variables `$q` and `okToGreet`
14578 * // are available in the current lexical scope (they could have been injected or passed in).
14580 * function asyncGreet(name) {
14581 * // perform some asynchronous operation, resolve or reject the promise when appropriate.
14582 * return $q(function(resolve, reject) {
14583 * setTimeout(function() {
14584 * if (okToGreet(name)) {
14585 * resolve('Hello, ' + name + '!');
14587 * reject('Greeting ' + name + ' is not allowed.');
14593 * var promise = asyncGreet('Robin Hood');
14594 * promise.then(function(greeting) {
14595 * alert('Success: ' + greeting);
14596 * }, function(reason) {
14597 * alert('Failed: ' + reason);
14601 * Note: progress/notify callbacks are not currently supported via the ES6-style interface.
14603 * Note: unlike ES6 behaviour, an exception thrown in the constructor function will NOT implicitly reject the promise.
14605 * However, the more traditional CommonJS-style usage is still available, and documented below.
14607 * [The CommonJS Promise proposal](http://wiki.commonjs.org/wiki/Promises) describes a promise as an
14608 * interface for interacting with an object that represents the result of an action that is
14609 * performed asynchronously, and may or may not be finished at any given point in time.
14611 * From the perspective of dealing with error handling, deferred and promise APIs are to
14612 * asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming.
14615 * // for the purpose of this example let's assume that variables `$q` and `okToGreet`
14616 * // are available in the current lexical scope (they could have been injected or passed in).
14618 * function asyncGreet(name) {
14619 * var deferred = $q.defer();
14621 * setTimeout(function() {
14622 * deferred.notify('About to greet ' + name + '.');
14624 * if (okToGreet(name)) {
14625 * deferred.resolve('Hello, ' + name + '!');
14627 * deferred.reject('Greeting ' + name + ' is not allowed.');
14631 * return deferred.promise;
14634 * var promise = asyncGreet('Robin Hood');
14635 * promise.then(function(greeting) {
14636 * alert('Success: ' + greeting);
14637 * }, function(reason) {
14638 * alert('Failed: ' + reason);
14639 * }, function(update) {
14640 * alert('Got notification: ' + update);
14644 * At first it might not be obvious why this extra complexity is worth the trouble. The payoff
14645 * comes in the way of guarantees that promise and deferred APIs make, see
14646 * https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md.
14648 * Additionally the promise api allows for composition that is very hard to do with the
14649 * traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach.
14650 * For more on this please see the [Q documentation](https://github.com/kriskowal/q) especially the
14651 * section on serial or parallel joining of promises.
14653 * # The Deferred API
14655 * A new instance of deferred is constructed by calling `$q.defer()`.
14657 * The purpose of the deferred object is to expose the associated Promise instance as well as APIs
14658 * that can be used for signaling the successful or unsuccessful completion, as well as the status
14663 * - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection
14664 * constructed via `$q.reject`, the promise will be rejected instead.
14665 * - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
14666 * resolving it with a rejection constructed via `$q.reject`.
14667 * - `notify(value)` - provides updates on the status of the promise's execution. This may be called
14668 * multiple times before the promise is either resolved or rejected.
14672 * - promise – `{Promise}` – promise object associated with this deferred.
14675 * # The Promise API
14677 * A new promise instance is created when a deferred instance is created and can be retrieved by
14678 * calling `deferred.promise`.
14680 * The purpose of the promise object is to allow for interested parties to get access to the result
14681 * of the deferred task when it completes.
14685 * - `then(successCallback, errorCallback, notifyCallback)` – regardless of when the promise was or
14686 * will be resolved or rejected, `then` calls one of the success or error callbacks asynchronously
14687 * as soon as the result is available. The callbacks are called with a single argument: the result
14688 * or rejection reason. Additionally, the notify callback may be called zero or more times to
14689 * provide a progress indication, before the promise is resolved or rejected.
14691 * This method *returns a new promise* which is resolved or rejected via the return value of the
14692 * `successCallback`, `errorCallback` (unless that value is a promise, in which case it is resolved
14693 * with the value which is resolved in that promise using
14694 * [promise chaining](http://www.html5rocks.com/en/tutorials/es6/promises/#toc-promises-queues)).
14695 * It also notifies via the return value of the `notifyCallback` method. The promise cannot be
14696 * resolved or rejected from the notifyCallback method.
14698 * - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
14700 * - `finally(callback, notifyCallback)` – allows you to observe either the fulfillment or rejection of a promise,
14701 * but to do so without modifying the final value. This is useful to release resources or do some
14702 * clean-up that needs to be done whether the promise was rejected or resolved. See the [full
14703 * specification](https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback) for
14704 * more information.
14706 * # Chaining promises
14708 * Because calling the `then` method of a promise returns a new derived promise, it is easily
14709 * possible to create a chain of promises:
14712 * promiseB = promiseA.then(function(result) {
14713 * return result + 1;
14716 * // promiseB will be resolved immediately after promiseA is resolved and its value
14717 * // will be the result of promiseA incremented by 1
14720 * It is possible to create chains of any length and since a promise can be resolved with another
14721 * promise (which will defer its resolution further), it is possible to pause/defer resolution of
14722 * the promises at any point in the chain. This makes it possible to implement powerful APIs like
14723 * $http's response interceptors.
14726 * # Differences between Kris Kowal's Q and $q
14728 * There are two main differences:
14730 * - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation
14731 * mechanism in angular, which means faster propagation of resolution or rejection into your
14732 * models and avoiding unnecessary browser repaints, which would result in flickering UI.
14733 * - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains
14734 * all the important functionality needed for common async tasks.
14739 * it('should simulate promise', inject(function($q, $rootScope) {
14740 * var deferred = $q.defer();
14741 * var promise = deferred.promise;
14742 * var resolvedValue;
14744 * promise.then(function(value) { resolvedValue = value; });
14745 * expect(resolvedValue).toBeUndefined();
14747 * // Simulate resolving of promise
14748 * deferred.resolve(123);
14749 * // Note that the 'then' function does not get called synchronously.
14750 * // This is because we want the promise API to always be async, whether or not
14751 * // it got called synchronously or asynchronously.
14752 * expect(resolvedValue).toBeUndefined();
14754 * // Propagate promise resolution to 'then' functions using $apply().
14755 * $rootScope.$apply();
14756 * expect(resolvedValue).toEqual(123);
14760 * @param {function(function, function)} resolver Function which is responsible for resolving or
14761 * rejecting the newly created promise. The first parameter is a function which resolves the
14762 * promise, the second parameter is a function which rejects the promise.
14764 * @returns {Promise} The newly created promise.
14766 function $QProvider() {
14768 this.$get = ['$rootScope', '$exceptionHandler', function($rootScope, $exceptionHandler) {
14769 return qFactory(function(callback) {
14770 $rootScope.$evalAsync(callback);
14771 }, $exceptionHandler);
14775 function $$QProvider() {
14776 this.$get = ['$browser', '$exceptionHandler', function($browser, $exceptionHandler) {
14777 return qFactory(function(callback) {
14778 $browser.defer(callback);
14779 }, $exceptionHandler);
14784 * Constructs a promise manager.
14786 * @param {function(function)} nextTick Function for executing functions in the next turn.
14787 * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for
14788 * debugging purposes.
14789 * @returns {object} Promise manager.
14791 function qFactory(nextTick, exceptionHandler) {
14792 var $qMinErr = minErr('$q', TypeError);
14793 function callOnce(self, resolveFn, rejectFn) {
14794 var called = false;
14795 function wrap(fn) {
14796 return function(value) {
14797 if (called) return;
14799 fn.call(self, value);
14803 return [wrap(resolveFn), wrap(rejectFn)];
14808 * @name ng.$q#defer
14812 * Creates a `Deferred` object which represents a task which will finish in the future.
14814 * @returns {Deferred} Returns a new instance of deferred.
14816 var defer = function() {
14817 return new Deferred();
14820 function Promise() {
14821 this.$$state = { status: 0 };
14824 extend(Promise.prototype, {
14825 then: function(onFulfilled, onRejected, progressBack) {
14826 if (isUndefined(onFulfilled) && isUndefined(onRejected) && isUndefined(progressBack)) {
14829 var result = new Deferred();
14831 this.$$state.pending = this.$$state.pending || [];
14832 this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]);
14833 if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);
14835 return result.promise;
14838 "catch": function(callback) {
14839 return this.then(null, callback);
14842 "finally": function(callback, progressBack) {
14843 return this.then(function(value) {
14844 return handleCallback(value, true, callback);
14845 }, function(error) {
14846 return handleCallback(error, false, callback);
14851 //Faster, more basic than angular.bind http://jsperf.com/angular-bind-vs-custom-vs-native
14852 function simpleBind(context, fn) {
14853 return function(value) {
14854 fn.call(context, value);
14858 function processQueue(state) {
14859 var fn, deferred, pending;
14861 pending = state.pending;
14862 state.processScheduled = false;
14863 state.pending = undefined;
14864 for (var i = 0, ii = pending.length; i < ii; ++i) {
14865 deferred = pending[i][0];
14866 fn = pending[i][state.status];
14868 if (isFunction(fn)) {
14869 deferred.resolve(fn(state.value));
14870 } else if (state.status === 1) {
14871 deferred.resolve(state.value);
14873 deferred.reject(state.value);
14876 deferred.reject(e);
14877 exceptionHandler(e);
14882 function scheduleProcessQueue(state) {
14883 if (state.processScheduled || !state.pending) return;
14884 state.processScheduled = true;
14885 nextTick(function() { processQueue(state); });
14888 function Deferred() {
14889 this.promise = new Promise();
14890 //Necessary to support unbound execution :/
14891 this.resolve = simpleBind(this, this.resolve);
14892 this.reject = simpleBind(this, this.reject);
14893 this.notify = simpleBind(this, this.notify);
14896 extend(Deferred.prototype, {
14897 resolve: function(val) {
14898 if (this.promise.$$state.status) return;
14899 if (val === this.promise) {
14900 this.$$reject($qMinErr(
14902 "Expected promise to be resolved with value other than itself '{0}'",
14905 this.$$resolve(val);
14910 $$resolve: function(val) {
14913 fns = callOnce(this, this.$$resolve, this.$$reject);
14915 if ((isObject(val) || isFunction(val))) then = val && val.then;
14916 if (isFunction(then)) {
14917 this.promise.$$state.status = -1;
14918 then.call(val, fns[0], fns[1], this.notify);
14920 this.promise.$$state.value = val;
14921 this.promise.$$state.status = 1;
14922 scheduleProcessQueue(this.promise.$$state);
14926 exceptionHandler(e);
14930 reject: function(reason) {
14931 if (this.promise.$$state.status) return;
14932 this.$$reject(reason);
14935 $$reject: function(reason) {
14936 this.promise.$$state.value = reason;
14937 this.promise.$$state.status = 2;
14938 scheduleProcessQueue(this.promise.$$state);
14941 notify: function(progress) {
14942 var callbacks = this.promise.$$state.pending;
14944 if ((this.promise.$$state.status <= 0) && callbacks && callbacks.length) {
14945 nextTick(function() {
14946 var callback, result;
14947 for (var i = 0, ii = callbacks.length; i < ii; i++) {
14948 result = callbacks[i][0];
14949 callback = callbacks[i][3];
14951 result.notify(isFunction(callback) ? callback(progress) : progress);
14953 exceptionHandler(e);
14967 * Creates a promise that is resolved as rejected with the specified `reason`. This api should be
14968 * used to forward rejection in a chain of promises. If you are dealing with the last promise in
14969 * a promise chain, you don't need to worry about it.
14971 * When comparing deferreds/promises to the familiar behavior of try/catch/throw, think of
14972 * `reject` as the `throw` keyword in JavaScript. This also means that if you "catch" an error via
14973 * a promise error callback and you want to forward the error to the promise derived from the
14974 * current promise, you have to "rethrow" the error by returning a rejection constructed via
14978 * promiseB = promiseA.then(function(result) {
14979 * // success: do something and resolve promiseB
14980 * // with the old or a new result
14982 * }, function(reason) {
14983 * // error: handle the error if possible and
14984 * // resolve promiseB with newPromiseOrValue,
14985 * // otherwise forward the rejection to promiseB
14986 * if (canHandle(reason)) {
14987 * // handle the error and recover
14988 * return newPromiseOrValue;
14990 * return $q.reject(reason);
14994 * @param {*} reason Constant, message, exception or an object representing the rejection reason.
14995 * @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`.
14997 var reject = function(reason) {
14998 var result = new Deferred();
14999 result.reject(reason);
15000 return result.promise;
15003 var makePromise = function makePromise(value, resolved) {
15004 var result = new Deferred();
15006 result.resolve(value);
15008 result.reject(value);
15010 return result.promise;
15013 var handleCallback = function handleCallback(value, isResolved, callback) {
15014 var callbackOutput = null;
15016 if (isFunction(callback)) callbackOutput = callback();
15018 return makePromise(e, false);
15020 if (isPromiseLike(callbackOutput)) {
15021 return callbackOutput.then(function() {
15022 return makePromise(value, isResolved);
15023 }, function(error) {
15024 return makePromise(error, false);
15027 return makePromise(value, isResolved);
15037 * Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise.
15038 * This is useful when you are dealing with an object that might or might not be a promise, or if
15039 * the promise comes from a source that can't be trusted.
15041 * @param {*} value Value or a promise
15042 * @param {Function=} successCallback
15043 * @param {Function=} errorCallback
15044 * @param {Function=} progressCallback
15045 * @returns {Promise} Returns a promise of the passed value or promise
15049 var when = function(value, callback, errback, progressBack) {
15050 var result = new Deferred();
15051 result.resolve(value);
15052 return result.promise.then(callback, errback, progressBack);
15061 * Alias of {@link ng.$q#when when} to maintain naming consistency with ES6.
15063 * @param {*} value Value or a promise
15064 * @param {Function=} successCallback
15065 * @param {Function=} errorCallback
15066 * @param {Function=} progressCallback
15067 * @returns {Promise} Returns a promise of the passed value or promise
15069 var resolve = when;
15077 * Combines multiple promises into a single promise that is resolved when all of the input
15078 * promises are resolved.
15080 * @param {Array.<Promise>|Object.<Promise>} promises An array or hash of promises.
15081 * @returns {Promise} Returns a single promise that will be resolved with an array/hash of values,
15082 * each value corresponding to the promise at the same index/key in the `promises` array/hash.
15083 * If any of the promises is resolved with a rejection, this resulting promise will be rejected
15084 * with the same rejection value.
15087 function all(promises) {
15088 var deferred = new Deferred(),
15090 results = isArray(promises) ? [] : {};
15092 forEach(promises, function(promise, key) {
15094 when(promise).then(function(value) {
15095 if (results.hasOwnProperty(key)) return;
15096 results[key] = value;
15097 if (!(--counter)) deferred.resolve(results);
15098 }, function(reason) {
15099 if (results.hasOwnProperty(key)) return;
15100 deferred.reject(reason);
15104 if (counter === 0) {
15105 deferred.resolve(results);
15108 return deferred.promise;
15111 var $Q = function Q(resolver) {
15112 if (!isFunction(resolver)) {
15113 throw $qMinErr('norslvr', "Expected resolverFn, got '{0}'", resolver);
15116 if (!(this instanceof Q)) {
15117 // More useful when $Q is the Promise itself.
15118 return new Q(resolver);
15121 var deferred = new Deferred();
15123 function resolveFn(value) {
15124 deferred.resolve(value);
15127 function rejectFn(reason) {
15128 deferred.reject(reason);
15131 resolver(resolveFn, rejectFn);
15133 return deferred.promise;
15137 $Q.reject = reject;
15139 $Q.resolve = resolve;
15145 function $$RAFProvider() { //rAF
15146 this.$get = ['$window', '$timeout', function($window, $timeout) {
15147 var requestAnimationFrame = $window.requestAnimationFrame ||
15148 $window.webkitRequestAnimationFrame;
15150 var cancelAnimationFrame = $window.cancelAnimationFrame ||
15151 $window.webkitCancelAnimationFrame ||
15152 $window.webkitCancelRequestAnimationFrame;
15154 var rafSupported = !!requestAnimationFrame;
15155 var raf = rafSupported
15157 var id = requestAnimationFrame(fn);
15158 return function() {
15159 cancelAnimationFrame(id);
15163 var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666
15164 return function() {
15165 $timeout.cancel(timer);
15169 raf.supported = rafSupported;
15178 * The design decisions behind the scope are heavily favored for speed and memory consumption.
15180 * The typical use of scope is to watch the expressions, which most of the time return the same
15181 * value as last time so we optimize the operation.
15183 * Closures construction is expensive in terms of speed as well as memory:
15184 * - No closures, instead use prototypical inheritance for API
15185 * - Internal state needs to be stored on scope directly, which means that private state is
15186 * exposed as $$____ properties
15188 * Loop operations are optimized by using while(count--) { ... }
15189 * - This means that in order to keep the same order of execution as addition we have to add
15190 * items to the array at the beginning (unshift) instead of at the end (push)
15192 * Child scopes are created and removed often
15193 * - Using an array would be slow since inserts in the middle are expensive; so we use linked lists
15195 * There are fewer watches than observers. This is why you don't want the observer to be implemented
15196 * in the same way as watch. Watch requires return of the initialization function which is expensive
15203 * @name $rootScopeProvider
15206 * Provider for the $rootScope service.
15211 * @name $rootScopeProvider#digestTtl
15214 * Sets the number of `$digest` iterations the scope should attempt to execute before giving up and
15215 * assuming that the model is unstable.
15217 * The current default is 10 iterations.
15219 * In complex applications it's possible that the dependencies between `$watch`s will result in
15220 * several digest iterations. However if an application needs more than the default 10 digest
15221 * iterations for its model to stabilize then you should investigate what is causing the model to
15222 * continuously change during the digest.
15224 * Increasing the TTL could have performance implications, so you should not change it without
15225 * proper justification.
15227 * @param {number} limit The number of digest iterations.
15236 * Every application has a single root {@link ng.$rootScope.Scope scope}.
15237 * All other scopes are descendant scopes of the root scope. Scopes provide separation
15238 * between the model and the view, via a mechanism for watching the model for changes.
15239 * They also provide event emission/broadcast and subscription facility. See the
15240 * {@link guide/scope developer guide on scopes}.
15242 function $RootScopeProvider() {
15244 var $rootScopeMinErr = minErr('$rootScope');
15245 var lastDirtyWatch = null;
15246 var applyAsyncId = null;
15248 this.digestTtl = function(value) {
15249 if (arguments.length) {
15255 function createChildScopeClass(parent) {
15256 function ChildScope() {
15257 this.$$watchers = this.$$nextSibling =
15258 this.$$childHead = this.$$childTail = null;
15259 this.$$listeners = {};
15260 this.$$listenerCount = {};
15261 this.$$watchersCount = 0;
15262 this.$id = nextUid();
15263 this.$$ChildScope = null;
15265 ChildScope.prototype = parent;
15269 this.$get = ['$injector', '$exceptionHandler', '$parse', '$browser',
15270 function($injector, $exceptionHandler, $parse, $browser) {
15272 function destroyChildScope($event) {
15273 $event.currentScope.$$destroyed = true;
15276 function cleanUpScope($scope) {
15279 // There is a memory leak in IE9 if all child scopes are not disconnected
15280 // completely when a scope is destroyed. So this code will recurse up through
15281 // all this scopes children
15283 // See issue https://github.com/angular/angular.js/issues/10706
15284 $scope.$$childHead && cleanUpScope($scope.$$childHead);
15285 $scope.$$nextSibling && cleanUpScope($scope.$$nextSibling);
15288 // The code below works around IE9 and V8's memory leaks
15291 // - https://code.google.com/p/v8/issues/detail?id=2073#c26
15292 // - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909
15293 // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451
15295 $scope.$parent = $scope.$$nextSibling = $scope.$$prevSibling = $scope.$$childHead =
15296 $scope.$$childTail = $scope.$root = $scope.$$watchers = null;
15301 * @name $rootScope.Scope
15304 * A root scope can be retrieved using the {@link ng.$rootScope $rootScope} key from the
15305 * {@link auto.$injector $injector}. Child scopes are created using the
15306 * {@link ng.$rootScope.Scope#$new $new()} method. (Most scopes are created automatically when
15307 * compiled HTML template is executed.) See also the {@link guide/scope Scopes guide} for
15308 * an in-depth introduction and usage examples.
15312 * A scope can inherit from a parent scope, as in this example:
15314 var parent = $rootScope;
15315 var child = parent.$new();
15317 parent.salutation = "Hello";
15318 expect(child.salutation).toEqual('Hello');
15320 child.salutation = "Welcome";
15321 expect(child.salutation).toEqual('Welcome');
15322 expect(parent.salutation).toEqual('Hello');
15325 * When interacting with `Scope` in tests, additional helper methods are available on the
15326 * instances of `Scope` type. See {@link ngMock.$rootScope.Scope ngMock Scope} for additional
15330 * @param {Object.<string, function()>=} providers Map of service factory which need to be
15331 * provided for the current scope. Defaults to {@link ng}.
15332 * @param {Object.<string, *>=} instanceCache Provides pre-instantiated services which should
15333 * append/override services provided by `providers`. This is handy
15334 * when unit-testing and having the need to override a default
15336 * @returns {Object} Newly created scope.
15340 this.$id = nextUid();
15341 this.$$phase = this.$parent = this.$$watchers =
15342 this.$$nextSibling = this.$$prevSibling =
15343 this.$$childHead = this.$$childTail = null;
15345 this.$$destroyed = false;
15346 this.$$listeners = {};
15347 this.$$listenerCount = {};
15348 this.$$watchersCount = 0;
15349 this.$$isolateBindings = null;
15354 * @name $rootScope.Scope#$id
15357 * Unique scope ID (monotonically increasing) useful for debugging.
15362 * @name $rootScope.Scope#$parent
15365 * Reference to the parent scope.
15370 * @name $rootScope.Scope#$root
15373 * Reference to the root scope.
15376 Scope.prototype = {
15377 constructor: Scope,
15380 * @name $rootScope.Scope#$new
15384 * Creates a new child {@link ng.$rootScope.Scope scope}.
15386 * The parent scope will propagate the {@link ng.$rootScope.Scope#$digest $digest()} event.
15387 * The scope can be removed from the scope hierarchy using {@link ng.$rootScope.Scope#$destroy $destroy()}.
15389 * {@link ng.$rootScope.Scope#$destroy $destroy()} must be called on a scope when it is
15390 * desired for the scope and its child scopes to be permanently detached from the parent and
15391 * thus stop participating in model change detection and listener notification by invoking.
15393 * @param {boolean} isolate If true, then the scope does not prototypically inherit from the
15394 * parent scope. The scope is isolated, as it can not see parent scope properties.
15395 * When creating widgets, it is useful for the widget to not accidentally read parent
15398 * @param {Scope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
15399 * of the newly created scope. Defaults to `this` scope if not provided.
15400 * This is used when creating a transclude scope to correctly place it
15401 * in the scope hierarchy while maintaining the correct prototypical
15404 * @returns {Object} The newly created child scope.
15407 $new: function(isolate, parent) {
15410 parent = parent || this;
15413 child = new Scope();
15414 child.$root = this.$root;
15416 // Only create a child scope class if somebody asks for one,
15417 // but cache it to allow the VM to optimize lookups.
15418 if (!this.$$ChildScope) {
15419 this.$$ChildScope = createChildScopeClass(this);
15421 child = new this.$$ChildScope();
15423 child.$parent = parent;
15424 child.$$prevSibling = parent.$$childTail;
15425 if (parent.$$childHead) {
15426 parent.$$childTail.$$nextSibling = child;
15427 parent.$$childTail = child;
15429 parent.$$childHead = parent.$$childTail = child;
15432 // When the new scope is not isolated or we inherit from `this`, and
15433 // the parent scope is destroyed, the property `$$destroyed` is inherited
15434 // prototypically. In all other cases, this property needs to be set
15435 // when the parent scope is destroyed.
15436 // The listener needs to be added after the parent is set
15437 if (isolate || parent != this) child.$on('$destroy', destroyChildScope);
15444 * @name $rootScope.Scope#$watch
15448 * Registers a `listener` callback to be executed whenever the `watchExpression` changes.
15450 * - The `watchExpression` is called on every call to {@link ng.$rootScope.Scope#$digest
15451 * $digest()} and should return the value that will be watched. (`watchExpression` should not change
15452 * its value when executed multiple times with the same input because it may be executed multiple
15453 * times by {@link ng.$rootScope.Scope#$digest $digest()}. That is, `watchExpression` should be
15454 * [idempotent](http://en.wikipedia.org/wiki/Idempotence).
15455 * - The `listener` is called only when the value from the current `watchExpression` and the
15456 * previous call to `watchExpression` are not equal (with the exception of the initial run,
15457 * see below). Inequality is determined according to reference inequality,
15458 * [strict comparison](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators)
15459 * via the `!==` Javascript operator, unless `objectEquality == true`
15461 * - When `objectEquality == true`, inequality of the `watchExpression` is determined
15462 * according to the {@link angular.equals} function. To save the value of the object for
15463 * later comparison, the {@link angular.copy} function is used. This therefore means that
15464 * watching complex objects will have adverse memory and performance implications.
15465 * - The watch `listener` may change the model, which may trigger other `listener`s to fire.
15466 * This is achieved by rerunning the watchers until no changes are detected. The rerun
15467 * iteration limit is 10 to prevent an infinite loop deadlock.
15470 * If you want to be notified whenever {@link ng.$rootScope.Scope#$digest $digest} is called,
15471 * you can register a `watchExpression` function with no `listener`. (Be prepared for
15472 * multiple calls to your `watchExpression` because it will execute multiple times in a
15473 * single {@link ng.$rootScope.Scope#$digest $digest} cycle if a change is detected.)
15475 * After a watcher is registered with the scope, the `listener` fn is called asynchronously
15476 * (via {@link ng.$rootScope.Scope#$evalAsync $evalAsync}) to initialize the
15477 * watcher. In rare cases, this is undesirable because the listener is called when the result
15478 * of `watchExpression` didn't change. To detect this scenario within the `listener` fn, you
15479 * can compare the `newVal` and `oldVal`. If these two values are identical (`===`) then the
15480 * listener was called due to initialization.
15486 // let's assume that scope was dependency injected as the $rootScope
15487 var scope = $rootScope;
15488 scope.name = 'misko';
15491 expect(scope.counter).toEqual(0);
15492 scope.$watch('name', function(newValue, oldValue) {
15493 scope.counter = scope.counter + 1;
15495 expect(scope.counter).toEqual(0);
15498 // the listener is always called during the first $digest loop after it was registered
15499 expect(scope.counter).toEqual(1);
15502 // but now it will not be called unless the value changes
15503 expect(scope.counter).toEqual(1);
15505 scope.name = 'adam';
15507 expect(scope.counter).toEqual(2);
15511 // Using a function as a watchExpression
15513 scope.foodCounter = 0;
15514 expect(scope.foodCounter).toEqual(0);
15516 // This function returns the value being watched. It is called for each turn of the $digest loop
15517 function() { return food; },
15518 // This is the change listener, called when the value returned from the above function changes
15519 function(newValue, oldValue) {
15520 if ( newValue !== oldValue ) {
15521 // Only increment the counter if the value changed
15522 scope.foodCounter = scope.foodCounter + 1;
15526 // No digest has been run so the counter will be zero
15527 expect(scope.foodCounter).toEqual(0);
15529 // Run the digest but since food has not changed count will still be zero
15531 expect(scope.foodCounter).toEqual(0);
15533 // Update food and run digest. Now the counter will increment
15534 food = 'cheeseburger';
15536 expect(scope.foodCounter).toEqual(1);
15542 * @param {(function()|string)} watchExpression Expression that is evaluated on each
15543 * {@link ng.$rootScope.Scope#$digest $digest} cycle. A change in the return value triggers
15544 * a call to the `listener`.
15546 * - `string`: Evaluated as {@link guide/expression expression}
15547 * - `function(scope)`: called with current `scope` as a parameter.
15548 * @param {function(newVal, oldVal, scope)} listener Callback called whenever the value
15549 * of `watchExpression` changes.
15551 * - `newVal` contains the current value of the `watchExpression`
15552 * - `oldVal` contains the previous value of the `watchExpression`
15553 * - `scope` refers to the current scope
15554 * @param {boolean=} objectEquality Compare for object equality using {@link angular.equals} instead of
15555 * comparing for reference equality.
15556 * @returns {function()} Returns a deregistration function for this listener.
15558 $watch: function(watchExp, listener, objectEquality, prettyPrintExpression) {
15559 var get = $parse(watchExp);
15561 if (get.$$watchDelegate) {
15562 return get.$$watchDelegate(this, listener, objectEquality, get, watchExp);
15565 array = scope.$$watchers,
15568 last: initWatchVal,
15570 exp: prettyPrintExpression || watchExp,
15571 eq: !!objectEquality
15574 lastDirtyWatch = null;
15576 if (!isFunction(listener)) {
15581 array = scope.$$watchers = [];
15583 // we use unshift since we use a while loop in $digest for speed.
15584 // the while loop reads in reverse order.
15585 array.unshift(watcher);
15586 incrementWatchersCount(this, 1);
15588 return function deregisterWatch() {
15589 if (arrayRemove(array, watcher) >= 0) {
15590 incrementWatchersCount(scope, -1);
15592 lastDirtyWatch = null;
15598 * @name $rootScope.Scope#$watchGroup
15602 * A variant of {@link ng.$rootScope.Scope#$watch $watch()} where it watches an array of `watchExpressions`.
15603 * If any one expression in the collection changes the `listener` is executed.
15605 * - The items in the `watchExpressions` array are observed via standard $watch operation and are examined on every
15606 * call to $digest() to see if any items changes.
15607 * - The `listener` is called whenever any expression in the `watchExpressions` array changes.
15609 * @param {Array.<string|Function(scope)>} watchExpressions Array of expressions that will be individually
15610 * watched using {@link ng.$rootScope.Scope#$watch $watch()}
15612 * @param {function(newValues, oldValues, scope)} listener Callback called whenever the return value of any
15613 * expression in `watchExpressions` changes
15614 * The `newValues` array contains the current values of the `watchExpressions`, with the indexes matching
15615 * those of `watchExpression`
15616 * and the `oldValues` array contains the previous values of the `watchExpressions`, with the indexes matching
15617 * those of `watchExpression`
15618 * The `scope` refers to the current scope.
15619 * @returns {function()} Returns a de-registration function for all listeners.
15621 $watchGroup: function(watchExpressions, listener) {
15622 var oldValues = new Array(watchExpressions.length);
15623 var newValues = new Array(watchExpressions.length);
15624 var deregisterFns = [];
15626 var changeReactionScheduled = false;
15627 var firstRun = true;
15629 if (!watchExpressions.length) {
15630 // No expressions means we call the listener ASAP
15631 var shouldCall = true;
15632 self.$evalAsync(function() {
15633 if (shouldCall) listener(newValues, newValues, self);
15635 return function deregisterWatchGroup() {
15636 shouldCall = false;
15640 if (watchExpressions.length === 1) {
15641 // Special case size of one
15642 return this.$watch(watchExpressions[0], function watchGroupAction(value, oldValue, scope) {
15643 newValues[0] = value;
15644 oldValues[0] = oldValue;
15645 listener(newValues, (value === oldValue) ? newValues : oldValues, scope);
15649 forEach(watchExpressions, function(expr, i) {
15650 var unwatchFn = self.$watch(expr, function watchGroupSubAction(value, oldValue) {
15651 newValues[i] = value;
15652 oldValues[i] = oldValue;
15653 if (!changeReactionScheduled) {
15654 changeReactionScheduled = true;
15655 self.$evalAsync(watchGroupAction);
15658 deregisterFns.push(unwatchFn);
15661 function watchGroupAction() {
15662 changeReactionScheduled = false;
15666 listener(newValues, newValues, self);
15668 listener(newValues, oldValues, self);
15672 return function deregisterWatchGroup() {
15673 while (deregisterFns.length) {
15674 deregisterFns.shift()();
15682 * @name $rootScope.Scope#$watchCollection
15686 * Shallow watches the properties of an object and fires whenever any of the properties change
15687 * (for arrays, this implies watching the array items; for object maps, this implies watching
15688 * the properties). If a change is detected, the `listener` callback is fired.
15690 * - The `obj` collection is observed via standard $watch operation and is examined on every
15691 * call to $digest() to see if any items have been added, removed, or moved.
15692 * - The `listener` is called whenever anything within the `obj` has changed. Examples include
15693 * adding, removing, and moving items belonging to an object or array.
15698 $scope.names = ['igor', 'matias', 'misko', 'james'];
15699 $scope.dataCount = 4;
15701 $scope.$watchCollection('names', function(newNames, oldNames) {
15702 $scope.dataCount = newNames.length;
15705 expect($scope.dataCount).toEqual(4);
15708 //still at 4 ... no changes
15709 expect($scope.dataCount).toEqual(4);
15711 $scope.names.pop();
15714 //now there's been a change
15715 expect($scope.dataCount).toEqual(3);
15719 * @param {string|function(scope)} obj Evaluated as {@link guide/expression expression}. The
15720 * expression value should evaluate to an object or an array which is observed on each
15721 * {@link ng.$rootScope.Scope#$digest $digest} cycle. Any shallow change within the
15722 * collection will trigger a call to the `listener`.
15724 * @param {function(newCollection, oldCollection, scope)} listener a callback function called
15725 * when a change is detected.
15726 * - The `newCollection` object is the newly modified data obtained from the `obj` expression
15727 * - The `oldCollection` object is a copy of the former collection data.
15728 * Due to performance considerations, the`oldCollection` value is computed only if the
15729 * `listener` function declares two or more arguments.
15730 * - The `scope` argument refers to the current scope.
15732 * @returns {function()} Returns a de-registration function for this listener. When the
15733 * de-registration function is executed, the internal watch operation is terminated.
15735 $watchCollection: function(obj, listener) {
15736 $watchCollectionInterceptor.$stateful = true;
15739 // the current value, updated on each dirty-check run
15741 // a shallow copy of the newValue from the last dirty-check run,
15742 // updated to match newValue during dirty-check run
15744 // a shallow copy of the newValue from when the last change happened
15746 // only track veryOldValue if the listener is asking for it
15747 var trackVeryOldValue = (listener.length > 1);
15748 var changeDetected = 0;
15749 var changeDetector = $parse(obj, $watchCollectionInterceptor);
15750 var internalArray = [];
15751 var internalObject = {};
15752 var initRun = true;
15755 function $watchCollectionInterceptor(_value) {
15757 var newLength, key, bothNaN, newItem, oldItem;
15759 // If the new value is undefined, then return undefined as the watch may be a one-time watch
15760 if (isUndefined(newValue)) return;
15762 if (!isObject(newValue)) { // if primitive
15763 if (oldValue !== newValue) {
15764 oldValue = newValue;
15767 } else if (isArrayLike(newValue)) {
15768 if (oldValue !== internalArray) {
15769 // we are transitioning from something which was not an array into array.
15770 oldValue = internalArray;
15771 oldLength = oldValue.length = 0;
15775 newLength = newValue.length;
15777 if (oldLength !== newLength) {
15778 // if lengths do not match we need to trigger change notification
15780 oldValue.length = oldLength = newLength;
15782 // copy the items to oldValue and look for changes.
15783 for (var i = 0; i < newLength; i++) {
15784 oldItem = oldValue[i];
15785 newItem = newValue[i];
15787 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
15788 if (!bothNaN && (oldItem !== newItem)) {
15790 oldValue[i] = newItem;
15794 if (oldValue !== internalObject) {
15795 // we are transitioning from something which was not an object into object.
15796 oldValue = internalObject = {};
15800 // copy the items to oldValue and look for changes.
15802 for (key in newValue) {
15803 if (hasOwnProperty.call(newValue, key)) {
15805 newItem = newValue[key];
15806 oldItem = oldValue[key];
15808 if (key in oldValue) {
15809 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
15810 if (!bothNaN && (oldItem !== newItem)) {
15812 oldValue[key] = newItem;
15816 oldValue[key] = newItem;
15821 if (oldLength > newLength) {
15822 // we used to have more keys, need to find them and destroy them.
15824 for (key in oldValue) {
15825 if (!hasOwnProperty.call(newValue, key)) {
15827 delete oldValue[key];
15832 return changeDetected;
15835 function $watchCollectionAction() {
15838 listener(newValue, newValue, self);
15840 listener(newValue, veryOldValue, self);
15843 // make a copy for the next time a collection is changed
15844 if (trackVeryOldValue) {
15845 if (!isObject(newValue)) {
15847 veryOldValue = newValue;
15848 } else if (isArrayLike(newValue)) {
15849 veryOldValue = new Array(newValue.length);
15850 for (var i = 0; i < newValue.length; i++) {
15851 veryOldValue[i] = newValue[i];
15853 } else { // if object
15855 for (var key in newValue) {
15856 if (hasOwnProperty.call(newValue, key)) {
15857 veryOldValue[key] = newValue[key];
15864 return this.$watch(changeDetector, $watchCollectionAction);
15869 * @name $rootScope.Scope#$digest
15873 * Processes all of the {@link ng.$rootScope.Scope#$watch watchers} of the current scope and
15874 * its children. Because a {@link ng.$rootScope.Scope#$watch watcher}'s listener can change
15875 * the model, the `$digest()` keeps calling the {@link ng.$rootScope.Scope#$watch watchers}
15876 * until no more listeners are firing. This means that it is possible to get into an infinite
15877 * loop. This function will throw `'Maximum iteration limit exceeded.'` if the number of
15878 * iterations exceeds 10.
15880 * Usually, you don't call `$digest()` directly in
15881 * {@link ng.directive:ngController controllers} or in
15882 * {@link ng.$compileProvider#directive directives}.
15883 * Instead, you should call {@link ng.$rootScope.Scope#$apply $apply()} (typically from within
15884 * a {@link ng.$compileProvider#directive directive}), which will force a `$digest()`.
15886 * If you want to be notified whenever `$digest()` is called,
15887 * you can register a `watchExpression` function with
15888 * {@link ng.$rootScope.Scope#$watch $watch()} with no `listener`.
15890 * In unit tests, you may need to call `$digest()` to simulate the scope life cycle.
15895 scope.name = 'misko';
15898 expect(scope.counter).toEqual(0);
15899 scope.$watch('name', function(newValue, oldValue) {
15900 scope.counter = scope.counter + 1;
15902 expect(scope.counter).toEqual(0);
15905 // the listener is always called during the first $digest loop after it was registered
15906 expect(scope.counter).toEqual(1);
15909 // but now it will not be called unless the value changes
15910 expect(scope.counter).toEqual(1);
15912 scope.name = 'adam';
15914 expect(scope.counter).toEqual(2);
15918 $digest: function() {
15919 var watch, value, last,
15923 next, current, target = this,
15925 logIdx, logMsg, asyncTask;
15927 beginPhase('$digest');
15928 // Check for changes to browser url that happened in sync before the call to $digest
15929 $browser.$$checkUrlChange();
15931 if (this === $rootScope && applyAsyncId !== null) {
15932 // If this is the root scope, and $applyAsync has scheduled a deferred $apply(), then
15933 // cancel the scheduled $apply and flush the queue of expressions to be evaluated.
15934 $browser.defer.cancel(applyAsyncId);
15938 lastDirtyWatch = null;
15940 do { // "while dirty" loop
15944 while (asyncQueue.length) {
15946 asyncTask = asyncQueue.shift();
15947 asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals);
15949 $exceptionHandler(e);
15951 lastDirtyWatch = null;
15954 traverseScopesLoop:
15955 do { // "traverse the scopes" loop
15956 if ((watchers = current.$$watchers)) {
15957 // process our watches
15958 length = watchers.length;
15961 watch = watchers[length];
15962 // Most common watches are on primitives, in which case we can short
15963 // circuit it with === operator, only when === fails do we use .equals
15965 if ((value = watch.get(current)) !== (last = watch.last) &&
15967 ? equals(value, last)
15968 : (typeof value === 'number' && typeof last === 'number'
15969 && isNaN(value) && isNaN(last)))) {
15971 lastDirtyWatch = watch;
15972 watch.last = watch.eq ? copy(value, null) : value;
15973 watch.fn(value, ((last === initWatchVal) ? value : last), current);
15976 if (!watchLog[logIdx]) watchLog[logIdx] = [];
15977 watchLog[logIdx].push({
15978 msg: isFunction(watch.exp) ? 'fn: ' + (watch.exp.name || watch.exp.toString()) : watch.exp,
15983 } else if (watch === lastDirtyWatch) {
15984 // If the most recently dirty watcher is now clean, short circuit since the remaining watchers
15985 // have already been tested.
15987 break traverseScopesLoop;
15991 $exceptionHandler(e);
15996 // Insanity Warning: scope depth-first traversal
15997 // yes, this code is a bit crazy, but it works and we have tests to prove it!
15998 // this piece should be kept in sync with the traversal in $broadcast
15999 if (!(next = ((current.$$watchersCount && current.$$childHead) ||
16000 (current !== target && current.$$nextSibling)))) {
16001 while (current !== target && !(next = current.$$nextSibling)) {
16002 current = current.$parent;
16005 } while ((current = next));
16007 // `break traverseScopesLoop;` takes us to here
16009 if ((dirty || asyncQueue.length) && !(ttl--)) {
16011 throw $rootScopeMinErr('infdig',
16012 '{0} $digest() iterations reached. Aborting!\n' +
16013 'Watchers fired in the last 5 iterations: {1}',
16017 } while (dirty || asyncQueue.length);
16021 while (postDigestQueue.length) {
16023 postDigestQueue.shift()();
16025 $exceptionHandler(e);
16033 * @name $rootScope.Scope#$destroy
16034 * @eventType broadcast on scope being destroyed
16037 * Broadcasted when a scope and its children are being destroyed.
16039 * Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to
16040 * clean up DOM bindings before an element is removed from the DOM.
16045 * @name $rootScope.Scope#$destroy
16049 * Removes the current scope (and all of its children) from the parent scope. Removal implies
16050 * that calls to {@link ng.$rootScope.Scope#$digest $digest()} will no longer
16051 * propagate to the current scope and its children. Removal also implies that the current
16052 * scope is eligible for garbage collection.
16054 * The `$destroy()` is usually used by directives such as
16055 * {@link ng.directive:ngRepeat ngRepeat} for managing the
16056 * unrolling of the loop.
16058 * Just before a scope is destroyed, a `$destroy` event is broadcasted on this scope.
16059 * Application code can register a `$destroy` event handler that will give it a chance to
16060 * perform any necessary cleanup.
16062 * Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to
16063 * clean up DOM bindings before an element is removed from the DOM.
16065 $destroy: function() {
16066 // We can't destroy a scope that has been already destroyed.
16067 if (this.$$destroyed) return;
16068 var parent = this.$parent;
16070 this.$broadcast('$destroy');
16071 this.$$destroyed = true;
16073 if (this === $rootScope) {
16074 //Remove handlers attached to window when $rootScope is removed
16075 $browser.$$applicationDestroyed();
16078 incrementWatchersCount(this, -this.$$watchersCount);
16079 for (var eventName in this.$$listenerCount) {
16080 decrementListenerCount(this, this.$$listenerCount[eventName], eventName);
16083 // sever all the references to parent scopes (after this cleanup, the current scope should
16084 // not be retained by any of our references and should be eligible for garbage collection)
16085 if (parent && parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
16086 if (parent && parent.$$childTail == this) parent.$$childTail = this.$$prevSibling;
16087 if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling;
16088 if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling;
16090 // Disable listeners, watchers and apply/digest methods
16091 this.$destroy = this.$digest = this.$apply = this.$evalAsync = this.$applyAsync = noop;
16092 this.$on = this.$watch = this.$watchGroup = function() { return noop; };
16093 this.$$listeners = {};
16095 // Disconnect the next sibling to prevent `cleanUpScope` destroying those too
16096 this.$$nextSibling = null;
16097 cleanUpScope(this);
16102 * @name $rootScope.Scope#$eval
16106 * Executes the `expression` on the current scope and returns the result. Any exceptions in
16107 * the expression are propagated (uncaught). This is useful when evaluating Angular
16112 var scope = ng.$rootScope.Scope();
16116 expect(scope.$eval('a+b')).toEqual(3);
16117 expect(scope.$eval(function(scope){ return scope.a + scope.b; })).toEqual(3);
16120 * @param {(string|function())=} expression An angular expression to be executed.
16122 * - `string`: execute using the rules as defined in {@link guide/expression expression}.
16123 * - `function(scope)`: execute the function with the current `scope` parameter.
16125 * @param {(object)=} locals Local variables object, useful for overriding values in scope.
16126 * @returns {*} The result of evaluating the expression.
16128 $eval: function(expr, locals) {
16129 return $parse(expr)(this, locals);
16134 * @name $rootScope.Scope#$evalAsync
16138 * Executes the expression on the current scope at a later point in time.
16140 * The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only
16143 * - it will execute after the function that scheduled the evaluation (preferably before DOM
16145 * - at least one {@link ng.$rootScope.Scope#$digest $digest cycle} will be performed after
16146 * `expression` execution.
16148 * Any exceptions from the execution of the expression are forwarded to the
16149 * {@link ng.$exceptionHandler $exceptionHandler} service.
16151 * __Note:__ if this function is called outside of a `$digest` cycle, a new `$digest` cycle
16152 * will be scheduled. However, it is encouraged to always call code that changes the model
16153 * from within an `$apply` call. That includes code evaluated via `$evalAsync`.
16155 * @param {(string|function())=} expression An angular expression to be executed.
16157 * - `string`: execute using the rules as defined in {@link guide/expression expression}.
16158 * - `function(scope)`: execute the function with the current `scope` parameter.
16160 * @param {(object)=} locals Local variables object, useful for overriding values in scope.
16162 $evalAsync: function(expr, locals) {
16163 // if we are outside of an $digest loop and this is the first time we are scheduling async
16164 // task also schedule async auto-flush
16165 if (!$rootScope.$$phase && !asyncQueue.length) {
16166 $browser.defer(function() {
16167 if (asyncQueue.length) {
16168 $rootScope.$digest();
16173 asyncQueue.push({scope: this, expression: expr, locals: locals});
16176 $$postDigest: function(fn) {
16177 postDigestQueue.push(fn);
16182 * @name $rootScope.Scope#$apply
16186 * `$apply()` is used to execute an expression in angular from outside of the angular
16187 * framework. (For example from browser DOM events, setTimeout, XHR or third party libraries).
16188 * Because we are calling into the angular framework we need to perform proper scope life
16189 * cycle of {@link ng.$exceptionHandler exception handling},
16190 * {@link ng.$rootScope.Scope#$digest executing watches}.
16194 * # Pseudo-Code of `$apply()`
16196 function $apply(expr) {
16198 return $eval(expr);
16200 $exceptionHandler(e);
16208 * Scope's `$apply()` method transitions through the following stages:
16210 * 1. The {@link guide/expression expression} is executed using the
16211 * {@link ng.$rootScope.Scope#$eval $eval()} method.
16212 * 2. Any exceptions from the execution of the expression are forwarded to the
16213 * {@link ng.$exceptionHandler $exceptionHandler} service.
16214 * 3. The {@link ng.$rootScope.Scope#$watch watch} listeners are fired immediately after the
16215 * expression was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method.
16218 * @param {(string|function())=} exp An angular expression to be executed.
16220 * - `string`: execute using the rules as defined in {@link guide/expression expression}.
16221 * - `function(scope)`: execute the function with current `scope` parameter.
16223 * @returns {*} The result of evaluating the expression.
16225 $apply: function(expr) {
16227 beginPhase('$apply');
16229 return this.$eval(expr);
16234 $exceptionHandler(e);
16237 $rootScope.$digest();
16239 $exceptionHandler(e);
16247 * @name $rootScope.Scope#$applyAsync
16251 * Schedule the invocation of $apply to occur at a later time. The actual time difference
16252 * varies across browsers, but is typically around ~10 milliseconds.
16254 * This can be used to queue up multiple expressions which need to be evaluated in the same
16257 * @param {(string|function())=} exp An angular expression to be executed.
16259 * - `string`: execute using the rules as defined in {@link guide/expression expression}.
16260 * - `function(scope)`: execute the function with current `scope` parameter.
16262 $applyAsync: function(expr) {
16264 expr && applyAsyncQueue.push($applyAsyncExpression);
16265 scheduleApplyAsync();
16267 function $applyAsyncExpression() {
16274 * @name $rootScope.Scope#$on
16278 * Listens on events of a given type. See {@link ng.$rootScope.Scope#$emit $emit} for
16279 * discussion of event life cycle.
16281 * The event listener function format is: `function(event, args...)`. The `event` object
16282 * passed into the listener has the following attributes:
16284 * - `targetScope` - `{Scope}`: the scope on which the event was `$emit`-ed or
16286 * - `currentScope` - `{Scope}`: the scope that is currently handling the event. Once the
16287 * event propagates through the scope hierarchy, this property is set to null.
16288 * - `name` - `{string}`: name of the event.
16289 * - `stopPropagation` - `{function=}`: calling `stopPropagation` function will cancel
16290 * further event propagation (available only for events that were `$emit`-ed).
16291 * - `preventDefault` - `{function}`: calling `preventDefault` sets `defaultPrevented` flag
16293 * - `defaultPrevented` - `{boolean}`: true if `preventDefault` was called.
16295 * @param {string} name Event name to listen on.
16296 * @param {function(event, ...args)} listener Function to call when the event is emitted.
16297 * @returns {function()} Returns a deregistration function for this listener.
16299 $on: function(name, listener) {
16300 var namedListeners = this.$$listeners[name];
16301 if (!namedListeners) {
16302 this.$$listeners[name] = namedListeners = [];
16304 namedListeners.push(listener);
16306 var current = this;
16308 if (!current.$$listenerCount[name]) {
16309 current.$$listenerCount[name] = 0;
16311 current.$$listenerCount[name]++;
16312 } while ((current = current.$parent));
16315 return function() {
16316 var indexOfListener = namedListeners.indexOf(listener);
16317 if (indexOfListener !== -1) {
16318 namedListeners[indexOfListener] = null;
16319 decrementListenerCount(self, 1, name);
16327 * @name $rootScope.Scope#$emit
16331 * Dispatches an event `name` upwards through the scope hierarchy notifying the
16332 * registered {@link ng.$rootScope.Scope#$on} listeners.
16334 * The event life cycle starts at the scope on which `$emit` was called. All
16335 * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get
16336 * notified. Afterwards, the event traverses upwards toward the root scope and calls all
16337 * registered listeners along the way. The event will stop propagating if one of the listeners
16340 * Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed
16341 * onto the {@link ng.$exceptionHandler $exceptionHandler} service.
16343 * @param {string} name Event name to emit.
16344 * @param {...*} args Optional one or more arguments which will be passed onto the event listeners.
16345 * @return {Object} Event object (see {@link ng.$rootScope.Scope#$on}).
16347 $emit: function(name, args) {
16351 stopPropagation = false,
16354 targetScope: scope,
16355 stopPropagation: function() {stopPropagation = true;},
16356 preventDefault: function() {
16357 event.defaultPrevented = true;
16359 defaultPrevented: false
16361 listenerArgs = concat([event], arguments, 1),
16365 namedListeners = scope.$$listeners[name] || empty;
16366 event.currentScope = scope;
16367 for (i = 0, length = namedListeners.length; i < length; i++) {
16369 // if listeners were deregistered, defragment the array
16370 if (!namedListeners[i]) {
16371 namedListeners.splice(i, 1);
16377 //allow all listeners attached to the current scope to run
16378 namedListeners[i].apply(null, listenerArgs);
16380 $exceptionHandler(e);
16383 //if any listener on the current scope stops propagation, prevent bubbling
16384 if (stopPropagation) {
16385 event.currentScope = null;
16389 scope = scope.$parent;
16392 event.currentScope = null;
16400 * @name $rootScope.Scope#$broadcast
16404 * Dispatches an event `name` downwards to all child scopes (and their children) notifying the
16405 * registered {@link ng.$rootScope.Scope#$on} listeners.
16407 * The event life cycle starts at the scope on which `$broadcast` was called. All
16408 * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get
16409 * notified. Afterwards, the event propagates to all direct and indirect scopes of the current
16410 * scope and calls all registered listeners along the way. The event cannot be canceled.
16412 * Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed
16413 * onto the {@link ng.$exceptionHandler $exceptionHandler} service.
16415 * @param {string} name Event name to broadcast.
16416 * @param {...*} args Optional one or more arguments which will be passed onto the event listeners.
16417 * @return {Object} Event object, see {@link ng.$rootScope.Scope#$on}
16419 $broadcast: function(name, args) {
16425 targetScope: target,
16426 preventDefault: function() {
16427 event.defaultPrevented = true;
16429 defaultPrevented: false
16432 if (!target.$$listenerCount[name]) return event;
16434 var listenerArgs = concat([event], arguments, 1),
16435 listeners, i, length;
16437 //down while you can, then up and next sibling or up and next sibling until back at root
16438 while ((current = next)) {
16439 event.currentScope = current;
16440 listeners = current.$$listeners[name] || [];
16441 for (i = 0, length = listeners.length; i < length; i++) {
16442 // if listeners were deregistered, defragment the array
16443 if (!listeners[i]) {
16444 listeners.splice(i, 1);
16451 listeners[i].apply(null, listenerArgs);
16453 $exceptionHandler(e);
16457 // Insanity Warning: scope depth-first traversal
16458 // yes, this code is a bit crazy, but it works and we have tests to prove it!
16459 // this piece should be kept in sync with the traversal in $digest
16460 // (though it differs due to having the extra check for $$listenerCount)
16461 if (!(next = ((current.$$listenerCount[name] && current.$$childHead) ||
16462 (current !== target && current.$$nextSibling)))) {
16463 while (current !== target && !(next = current.$$nextSibling)) {
16464 current = current.$parent;
16469 event.currentScope = null;
16474 var $rootScope = new Scope();
16476 //The internal queues. Expose them on the $rootScope for debugging/testing purposes.
16477 var asyncQueue = $rootScope.$$asyncQueue = [];
16478 var postDigestQueue = $rootScope.$$postDigestQueue = [];
16479 var applyAsyncQueue = $rootScope.$$applyAsyncQueue = [];
16484 function beginPhase(phase) {
16485 if ($rootScope.$$phase) {
16486 throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase);
16489 $rootScope.$$phase = phase;
16492 function clearPhase() {
16493 $rootScope.$$phase = null;
16496 function incrementWatchersCount(current, count) {
16498 current.$$watchersCount += count;
16499 } while ((current = current.$parent));
16502 function decrementListenerCount(current, count, name) {
16504 current.$$listenerCount[name] -= count;
16506 if (current.$$listenerCount[name] === 0) {
16507 delete current.$$listenerCount[name];
16509 } while ((current = current.$parent));
16513 * function used as an initial value for watchers.
16514 * because it's unique we can easily tell it apart from other values
16516 function initWatchVal() {}
16518 function flushApplyAsync() {
16519 while (applyAsyncQueue.length) {
16521 applyAsyncQueue.shift()();
16523 $exceptionHandler(e);
16526 applyAsyncId = null;
16529 function scheduleApplyAsync() {
16530 if (applyAsyncId === null) {
16531 applyAsyncId = $browser.defer(function() {
16532 $rootScope.$apply(flushApplyAsync);
16541 * Private service to sanitize uris for links and images. Used by $compile and $sanitize.
16543 function $$SanitizeUriProvider() {
16544 var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
16545 imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob):|data:image\/)/;
16549 * Retrieves or overrides the default regular expression that is used for whitelisting of safe
16550 * urls during a[href] sanitization.
16552 * The sanitization is a security measure aimed at prevent XSS attacks via html links.
16554 * Any url about to be assigned to a[href] via data-binding is first normalized and turned into
16555 * an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist`
16556 * regular expression. If a match is found, the original url is written into the dom. Otherwise,
16557 * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
16559 * @param {RegExp=} regexp New regexp to whitelist urls with.
16560 * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
16561 * chaining otherwise.
16563 this.aHrefSanitizationWhitelist = function(regexp) {
16564 if (isDefined(regexp)) {
16565 aHrefSanitizationWhitelist = regexp;
16568 return aHrefSanitizationWhitelist;
16574 * Retrieves or overrides the default regular expression that is used for whitelisting of safe
16575 * urls during img[src] sanitization.
16577 * The sanitization is a security measure aimed at prevent XSS attacks via html links.
16579 * Any url about to be assigned to img[src] via data-binding is first normalized and turned into
16580 * an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist`
16581 * regular expression. If a match is found, the original url is written into the dom. Otherwise,
16582 * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
16584 * @param {RegExp=} regexp New regexp to whitelist urls with.
16585 * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
16586 * chaining otherwise.
16588 this.imgSrcSanitizationWhitelist = function(regexp) {
16589 if (isDefined(regexp)) {
16590 imgSrcSanitizationWhitelist = regexp;
16593 return imgSrcSanitizationWhitelist;
16596 this.$get = function() {
16597 return function sanitizeUri(uri, isImage) {
16598 var regex = isImage ? imgSrcSanitizationWhitelist : aHrefSanitizationWhitelist;
16600 normalizedVal = urlResolve(uri).href;
16601 if (normalizedVal !== '' && !normalizedVal.match(regex)) {
16602 return 'unsafe:' + normalizedVal;
16609 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
16610 * Any commits to this file should be reviewed with security in mind. *
16611 * Changes to this file can potentially create security vulnerabilities. *
16612 * An approval from 2 Core members with history of modifying *
16613 * this file is required. *
16615 * Does the change somehow allow for arbitrary javascript to be executed? *
16616 * Or allows for someone to change the prototype of built-in objects? *
16617 * Or gives undesired access to variables likes document or window? *
16618 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16620 var $sceMinErr = minErr('$sce');
16622 var SCE_CONTEXTS = {
16626 // RESOURCE_URL is a subtype of URL used in contexts where a privileged resource is sourced from a
16627 // url. (e.g. ng-include, script src, templateUrl)
16628 RESOURCE_URL: 'resourceUrl',
16632 // Helper functions follow.
16634 function adjustMatcher(matcher) {
16635 if (matcher === 'self') {
16637 } else if (isString(matcher)) {
16638 // Strings match exactly except for 2 wildcards - '*' and '**'.
16639 // '*' matches any character except those from the set ':/.?&'.
16640 // '**' matches any character (like .* in a RegExp).
16641 // More than 2 *'s raises an error as it's ill defined.
16642 if (matcher.indexOf('***') > -1) {
16643 throw $sceMinErr('iwcard',
16644 'Illegal sequence *** in string matcher. String: {0}', matcher);
16646 matcher = escapeForRegexp(matcher).
16647 replace('\\*\\*', '.*').
16648 replace('\\*', '[^:/.?&;]*');
16649 return new RegExp('^' + matcher + '$');
16650 } else if (isRegExp(matcher)) {
16651 // The only other type of matcher allowed is a Regexp.
16652 // Match entire URL / disallow partial matches.
16653 // Flags are reset (i.e. no global, ignoreCase or multiline)
16654 return new RegExp('^' + matcher.source + '$');
16656 throw $sceMinErr('imatcher',
16657 'Matchers may only be "self", string patterns or RegExp objects');
16662 function adjustMatchers(matchers) {
16663 var adjustedMatchers = [];
16664 if (isDefined(matchers)) {
16665 forEach(matchers, function(matcher) {
16666 adjustedMatchers.push(adjustMatcher(matcher));
16669 return adjustedMatchers;
16675 * @name $sceDelegate
16680 * `$sceDelegate` is a service that is used by the `$sce` service to provide {@link ng.$sce Strict
16681 * Contextual Escaping (SCE)} services to AngularJS.
16683 * Typically, you would configure or override the {@link ng.$sceDelegate $sceDelegate} instead of
16684 * the `$sce` service to customize the way Strict Contextual Escaping works in AngularJS. This is
16685 * because, while the `$sce` provides numerous shorthand methods, etc., you really only need to
16686 * override 3 core functions (`trustAs`, `getTrusted` and `valueOf`) to replace the way things
16687 * work because `$sce` delegates to `$sceDelegate` for these operations.
16689 * Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} to configure this service.
16691 * The default instance of `$sceDelegate` should work out of the box with little pain. While you
16692 * can override it completely to change the behavior of `$sce`, the common case would
16693 * involve configuring the {@link ng.$sceDelegateProvider $sceDelegateProvider} instead by setting
16694 * your own whitelists and blacklists for trusting URLs used for loading AngularJS resources such as
16695 * templates. Refer {@link ng.$sceDelegateProvider#resourceUrlWhitelist
16696 * $sceDelegateProvider.resourceUrlWhitelist} and {@link
16697 * ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
16702 * @name $sceDelegateProvider
16705 * The `$sceDelegateProvider` provider allows developers to configure the {@link ng.$sceDelegate
16706 * $sceDelegate} service. This allows one to get/set the whitelists and blacklists used to ensure
16707 * that the URLs used for sourcing Angular templates are safe. Refer {@link
16708 * ng.$sceDelegateProvider#resourceUrlWhitelist $sceDelegateProvider.resourceUrlWhitelist} and
16709 * {@link ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}
16711 * For the general details about this service in Angular, read the main page for {@link ng.$sce
16712 * Strict Contextual Escaping (SCE)}.
16714 * **Example**: Consider the following case. <a name="example"></a>
16716 * - your app is hosted at url `http://myapp.example.com/`
16717 * - but some of your templates are hosted on other domains you control such as
16718 * `http://srv01.assets.example.com/`, `http://srv02.assets.example.com/`, etc.
16719 * - and you have an open redirect at `http://myapp.example.com/clickThru?...`.
16721 * Here is what a secure configuration for this scenario might look like:
16724 * angular.module('myApp', []).config(function($sceDelegateProvider) {
16725 * $sceDelegateProvider.resourceUrlWhitelist([
16726 * // Allow same origin resource loads.
16728 * // Allow loading from our assets domain. Notice the difference between * and **.
16729 * 'http://srv*.assets.example.com/**'
16732 * // The blacklist overrides the whitelist so the open redirect here is blocked.
16733 * $sceDelegateProvider.resourceUrlBlacklist([
16734 * 'http://myapp.example.com/clickThru**'
16740 function $SceDelegateProvider() {
16741 this.SCE_CONTEXTS = SCE_CONTEXTS;
16743 // Resource URLs can also be trusted by policy.
16744 var resourceUrlWhitelist = ['self'],
16745 resourceUrlBlacklist = [];
16749 * @name $sceDelegateProvider#resourceUrlWhitelist
16752 * @param {Array=} whitelist When provided, replaces the resourceUrlWhitelist with the value
16753 * provided. This must be an array or null. A snapshot of this array is used so further
16754 * changes to the array are ignored.
16756 * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
16757 * allowed in this array.
16759 * Note: **an empty whitelist array will block all URLs**!
16761 * @return {Array} the currently set whitelist array.
16763 * The **default value** when no whitelist has been explicitly set is `['self']` allowing only
16764 * same origin resource requests.
16767 * Sets/Gets the whitelist of trusted resource URLs.
16769 this.resourceUrlWhitelist = function(value) {
16770 if (arguments.length) {
16771 resourceUrlWhitelist = adjustMatchers(value);
16773 return resourceUrlWhitelist;
16778 * @name $sceDelegateProvider#resourceUrlBlacklist
16781 * @param {Array=} blacklist When provided, replaces the resourceUrlBlacklist with the value
16782 * provided. This must be an array or null. A snapshot of this array is used so further
16783 * changes to the array are ignored.
16785 * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items
16786 * allowed in this array.
16788 * The typical usage for the blacklist is to **block
16789 * [open redirects](http://cwe.mitre.org/data/definitions/601.html)** served by your domain as
16790 * these would otherwise be trusted but actually return content from the redirected domain.
16792 * Finally, **the blacklist overrides the whitelist** and has the final say.
16794 * @return {Array} the currently set blacklist array.
16796 * The **default value** when no whitelist has been explicitly set is the empty array (i.e. there
16797 * is no blacklist.)
16800 * Sets/Gets the blacklist of trusted resource URLs.
16803 this.resourceUrlBlacklist = function(value) {
16804 if (arguments.length) {
16805 resourceUrlBlacklist = adjustMatchers(value);
16807 return resourceUrlBlacklist;
16810 this.$get = ['$injector', function($injector) {
16812 var htmlSanitizer = function htmlSanitizer(html) {
16813 throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
16816 if ($injector.has('$sanitize')) {
16817 htmlSanitizer = $injector.get('$sanitize');
16821 function matchUrl(matcher, parsedUrl) {
16822 if (matcher === 'self') {
16823 return urlIsSameOrigin(parsedUrl);
16825 // definitely a regex. See adjustMatchers()
16826 return !!matcher.exec(parsedUrl.href);
16830 function isResourceUrlAllowedByPolicy(url) {
16831 var parsedUrl = urlResolve(url.toString());
16832 var i, n, allowed = false;
16833 // Ensure that at least one item from the whitelist allows this url.
16834 for (i = 0, n = resourceUrlWhitelist.length; i < n; i++) {
16835 if (matchUrl(resourceUrlWhitelist[i], parsedUrl)) {
16841 // Ensure that no item from the blacklist blocked this url.
16842 for (i = 0, n = resourceUrlBlacklist.length; i < n; i++) {
16843 if (matchUrl(resourceUrlBlacklist[i], parsedUrl)) {
16852 function generateHolderType(Base) {
16853 var holderType = function TrustedValueHolderType(trustedValue) {
16854 this.$$unwrapTrustedValue = function() {
16855 return trustedValue;
16859 holderType.prototype = new Base();
16861 holderType.prototype.valueOf = function sceValueOf() {
16862 return this.$$unwrapTrustedValue();
16864 holderType.prototype.toString = function sceToString() {
16865 return this.$$unwrapTrustedValue().toString();
16870 var trustedValueHolderBase = generateHolderType(),
16873 byType[SCE_CONTEXTS.HTML] = generateHolderType(trustedValueHolderBase);
16874 byType[SCE_CONTEXTS.CSS] = generateHolderType(trustedValueHolderBase);
16875 byType[SCE_CONTEXTS.URL] = generateHolderType(trustedValueHolderBase);
16876 byType[SCE_CONTEXTS.JS] = generateHolderType(trustedValueHolderBase);
16877 byType[SCE_CONTEXTS.RESOURCE_URL] = generateHolderType(byType[SCE_CONTEXTS.URL]);
16881 * @name $sceDelegate#trustAs
16884 * Returns an object that is trusted by angular for use in specified strict
16885 * contextual escaping contexts (such as ng-bind-html, ng-include, any src
16886 * attribute interpolation, any dom event binding attribute interpolation
16887 * such as for onclick, etc.) that uses the provided value.
16888 * See {@link ng.$sce $sce} for enabling strict contextual escaping.
16890 * @param {string} type The kind of context in which this value is safe for use. e.g. url,
16891 * resourceUrl, html, js and css.
16892 * @param {*} value The value that that should be considered trusted/safe.
16893 * @returns {*} A value that can be used to stand in for the provided `value` in places
16894 * where Angular expects a $sce.trustAs() return value.
16896 function trustAs(type, trustedValue) {
16897 var Constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
16898 if (!Constructor) {
16899 throw $sceMinErr('icontext',
16900 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}',
16901 type, trustedValue);
16903 if (trustedValue === null || isUndefined(trustedValue) || trustedValue === '') {
16904 return trustedValue;
16906 // All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting
16907 // mutable objects, we ensure here that the value passed in is actually a string.
16908 if (typeof trustedValue !== 'string') {
16909 throw $sceMinErr('itype',
16910 'Attempted to trust a non-string value in a content requiring a string: Context: {0}',
16913 return new Constructor(trustedValue);
16918 * @name $sceDelegate#valueOf
16921 * If the passed parameter had been returned by a prior call to {@link ng.$sceDelegate#trustAs
16922 * `$sceDelegate.trustAs`}, returns the value that had been passed to {@link
16923 * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}.
16925 * If the passed parameter is not a value that had been returned by {@link
16926 * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}, returns it as-is.
16928 * @param {*} value The result of a prior {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}
16929 * call or anything else.
16930 * @returns {*} The `value` that was originally provided to {@link ng.$sceDelegate#trustAs
16931 * `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns
16932 * `value` unchanged.
16934 function valueOf(maybeTrusted) {
16935 if (maybeTrusted instanceof trustedValueHolderBase) {
16936 return maybeTrusted.$$unwrapTrustedValue();
16938 return maybeTrusted;
16944 * @name $sceDelegate#getTrusted
16947 * Takes the result of a {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`} call and
16948 * returns the originally supplied value if the queried context type is a supertype of the
16949 * created type. If this condition isn't satisfied, throws an exception.
16951 * @param {string} type The kind of context in which this value is to be used.
16952 * @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs
16953 * `$sceDelegate.trustAs`} call.
16954 * @returns {*} The value the was originally provided to {@link ng.$sceDelegate#trustAs
16955 * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception.
16957 function getTrusted(type, maybeTrusted) {
16958 if (maybeTrusted === null || isUndefined(maybeTrusted) || maybeTrusted === '') {
16959 return maybeTrusted;
16961 var constructor = (byType.hasOwnProperty(type) ? byType[type] : null);
16962 if (constructor && maybeTrusted instanceof constructor) {
16963 return maybeTrusted.$$unwrapTrustedValue();
16965 // If we get here, then we may only take one of two actions.
16966 // 1. sanitize the value for the requested type, or
16967 // 2. throw an exception.
16968 if (type === SCE_CONTEXTS.RESOURCE_URL) {
16969 if (isResourceUrlAllowedByPolicy(maybeTrusted)) {
16970 return maybeTrusted;
16972 throw $sceMinErr('insecurl',
16973 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}',
16974 maybeTrusted.toString());
16976 } else if (type === SCE_CONTEXTS.HTML) {
16977 return htmlSanitizer(maybeTrusted);
16979 throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.');
16982 return { trustAs: trustAs,
16983 getTrusted: getTrusted,
16984 valueOf: valueOf };
16991 * @name $sceProvider
16994 * The $sceProvider provider allows developers to configure the {@link ng.$sce $sce} service.
16995 * - enable/disable Strict Contextual Escaping (SCE) in a module
16996 * - override the default implementation with a custom delegate
16998 * Read more about {@link ng.$sce Strict Contextual Escaping (SCE)}.
17001 /* jshint maxlen: false*/
17010 * `$sce` is a service that provides Strict Contextual Escaping services to AngularJS.
17012 * # Strict Contextual Escaping
17014 * Strict Contextual Escaping (SCE) is a mode in which AngularJS requires bindings in certain
17015 * contexts to result in a value that is marked as safe to use for that context. One example of
17016 * such a context is binding arbitrary html controlled by the user via `ng-bind-html`. We refer
17017 * to these contexts as privileged or SCE contexts.
17019 * As of version 1.2, Angular ships with SCE enabled by default.
17021 * Note: When enabled (the default), IE<11 in quirks mode is not supported. In this mode, IE<11 allow
17022 * one to execute arbitrary javascript by the use of the expression() syntax. Refer
17023 * <http://blogs.msdn.com/b/ie/archive/2008/10/16/ending-expressions.aspx> to learn more about them.
17024 * You can ensure your document is in standards mode and not quirks mode by adding `<!doctype html>`
17025 * to the top of your HTML document.
17027 * SCE assists in writing code in way that (a) is secure by default and (b) makes auditing for
17028 * security vulnerabilities such as XSS, clickjacking, etc. a lot easier.
17030 * Here's an example of a binding in a privileged context:
17033 * <input ng-model="userHtml" aria-label="User input">
17034 * <div ng-bind-html="userHtml"></div>
17037 * Notice that `ng-bind-html` is bound to `userHtml` controlled by the user. With SCE
17038 * disabled, this application allows the user to render arbitrary HTML into the DIV.
17039 * In a more realistic example, one may be rendering user comments, blog articles, etc. via
17040 * bindings. (HTML is just one example of a context where rendering user controlled input creates
17041 * security vulnerabilities.)
17043 * For the case of HTML, you might use a library, either on the client side, or on the server side,
17044 * to sanitize unsafe HTML before binding to the value and rendering it in the document.
17046 * How would you ensure that every place that used these types of bindings was bound to a value that
17047 * was sanitized by your library (or returned as safe for rendering by your server?) How can you
17048 * ensure that you didn't accidentally delete the line that sanitized the value, or renamed some
17049 * properties/fields and forgot to update the binding to the sanitized value?
17051 * To be secure by default, you want to ensure that any such bindings are disallowed unless you can
17052 * determine that something explicitly says it's safe to use a value for binding in that
17053 * context. You can then audit your code (a simple grep would do) to ensure that this is only done
17054 * for those values that you can easily tell are safe - because they were received from your server,
17055 * sanitized by your library, etc. You can organize your codebase to help with this - perhaps
17056 * allowing only the files in a specific directory to do this. Ensuring that the internal API
17057 * exposed by that code doesn't markup arbitrary values as safe then becomes a more manageable task.
17059 * In the case of AngularJS' SCE service, one uses {@link ng.$sce#trustAs $sce.trustAs}
17060 * (and shorthand methods such as {@link ng.$sce#trustAsHtml $sce.trustAsHtml}, etc.) to
17061 * obtain values that will be accepted by SCE / privileged contexts.
17064 * ## How does it work?
17066 * In privileged contexts, directives and code will bind to the result of {@link ng.$sce#getTrusted
17067 * $sce.getTrusted(context, value)} rather than to the value directly. Directives use {@link
17068 * ng.$sce#parseAs $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs the
17069 * {@link ng.$sce#getTrusted $sce.getTrusted} behind the scenes on non-constant literals.
17071 * As an example, {@link ng.directive:ngBindHtml ngBindHtml} uses {@link
17072 * ng.$sce#parseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly
17076 * var ngBindHtmlDirective = ['$sce', function($sce) {
17077 * return function(scope, element, attr) {
17078 * scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) {
17079 * element.html(value || '');
17085 * ## Impact on loading templates
17087 * This applies both to the {@link ng.directive:ngInclude `ng-include`} directive as well as
17088 * `templateUrl`'s specified by {@link guide/directive directives}.
17090 * By default, Angular only loads templates from the same domain and protocol as the application
17091 * document. This is done by calling {@link ng.$sce#getTrustedResourceUrl
17092 * $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or
17093 * protocols, you may either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist
17094 * them} or {@link ng.$sce#trustAsResourceUrl wrap it} into a trusted value.
17098 * [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
17099 * and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
17100 * policy apply in addition to this and may further restrict whether the template is successfully
17101 * loaded. This means that without the right CORS policy, loading templates from a different domain
17102 * won't work on all browsers. Also, loading templates from `file://` URL does not work on some
17105 * ## This feels like too much overhead
17107 * It's important to remember that SCE only applies to interpolation expressions.
17109 * If your expressions are constant literals, they're automatically trusted and you don't need to
17110 * call `$sce.trustAs` on them (remember to include the `ngSanitize` module) (e.g.
17111 * `<div ng-bind-html="'<b>implicitly trusted</b>'"></div>`) just works.
17113 * Additionally, `a[href]` and `img[src]` automatically sanitize their URLs and do not pass them
17114 * through {@link ng.$sce#getTrusted $sce.getTrusted}. SCE doesn't play a role here.
17116 * The included {@link ng.$sceDelegate $sceDelegate} comes with sane defaults to allow you to load
17117 * templates in `ng-include` from your application's domain without having to even know about SCE.
17118 * It blocks loading templates from other domains or loading templates over http from an https
17119 * served document. You can change these by setting your own custom {@link
17120 * ng.$sceDelegateProvider#resourceUrlWhitelist whitelists} and {@link
17121 * ng.$sceDelegateProvider#resourceUrlBlacklist blacklists} for matching such URLs.
17123 * This significantly reduces the overhead. It is far easier to pay the small overhead and have an
17124 * application that's secure and can be audited to verify that with much more ease than bolting
17125 * security onto an application later.
17127 * <a name="contexts"></a>
17128 * ## What trusted context types are supported?
17130 * | Context | Notes |
17131 * |---------------------|----------------|
17132 * | `$sce.HTML` | For HTML that's safe to source into the application. The {@link ng.directive:ngBindHtml ngBindHtml} directive uses this context for bindings. If an unsafe value is encountered and the {@link ngSanitize $sanitize} module is present this will sanitize the value instead of throwing an error. |
17133 * | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. |
17134 * | `$sce.URL` | For URLs that are safe to follow as links. Currently unused (`<a href=` and `<img src=` sanitize their urls and don't constitute an SCE context. |
17135 * | `$sce.RESOURCE_URL` | For URLs that are not only safe to follow as links, but whose contents are also safe to include in your application. Examples include `ng-include`, `src` / `ngSrc` bindings for tags other than `IMG` (e.g. `IFRAME`, `OBJECT`, etc.) <br><br>Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` does and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` are required. |
17136 * | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. |
17138 * ## Format of items in {@link ng.$sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#resourceUrlBlacklist Blacklist} <a name="resourceUrlPatternItem"></a>
17140 * Each element in these arrays must be one of the following:
17143 * - The special **string**, `'self'`, can be used to match against all URLs of the **same
17144 * domain** as the application document using the **same protocol**.
17145 * - **String** (except the special value `'self'`)
17146 * - The string is matched against the full *normalized / absolute URL* of the resource
17147 * being tested (substring matches are not good enough.)
17148 * - There are exactly **two wildcard sequences** - `*` and `**`. All other characters
17149 * match themselves.
17150 * - `*`: matches zero or more occurrences of any character other than one of the following 6
17151 * characters: '`:`', '`/`', '`.`', '`?`', '`&`' and '`;`'. It's a useful wildcard for use
17153 * - `**`: matches zero or more occurrences of *any* character. As such, it's not
17154 * appropriate for use in a scheme, domain, etc. as it would match too much. (e.g.
17155 * http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might
17156 * not have been the intention.) Its usage at the very end of the path is ok. (e.g.
17157 * http://foo.example.com/templates/**).
17158 * - **RegExp** (*see caveat below*)
17159 * - *Caveat*: While regular expressions are powerful and offer great flexibility, their syntax
17160 * (and all the inevitable escaping) makes them *harder to maintain*. It's easy to
17161 * accidentally introduce a bug when one updates a complex expression (imho, all regexes should
17162 * have good test coverage). For instance, the use of `.` in the regex is correct only in a
17163 * small number of cases. A `.` character in the regex used when matching the scheme or a
17164 * subdomain could be matched against a `:` or literal `.` that was likely not intended. It
17165 * is highly recommended to use the string patterns and only fall back to regular expressions
17166 * as a last resort.
17167 * - The regular expression must be an instance of RegExp (i.e. not a string.) It is
17168 * matched against the **entire** *normalized / absolute URL* of the resource being tested
17169 * (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags
17170 * present on the RegExp (such as multiline, global, ignoreCase) are ignored.
17171 * - If you are generating your JavaScript from some other templating engine (not
17172 * recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)),
17173 * remember to escape your regular expression (and be aware that you might need more than
17174 * one level of escaping depending on your templating engine and the way you interpolated
17175 * the value.) Do make use of your platform's escaping mechanism as it might be good
17176 * enough before coding your own. E.g. Ruby has
17177 * [Regexp.escape(str)](http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-c-escape)
17178 * and Python has [re.escape](http://docs.python.org/library/re.html#re.escape).
17179 * Javascript lacks a similar built in function for escaping. Take a look at Google
17180 * Closure library's [goog.string.regExpEscape(s)](
17181 * http://docs.closure-library.googlecode.com/git/closure_goog_string_string.js.source.html#line962).
17183 * Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} for an example.
17185 * ## Show me an example using SCE.
17187 * <example module="mySceApp" deps="angular-sanitize.js">
17188 * <file name="index.html">
17189 * <div ng-controller="AppController as myCtrl">
17190 * <i ng-bind-html="myCtrl.explicitlyTrustedHtml" id="explicitlyTrustedHtml"></i><br><br>
17191 * <b>User comments</b><br>
17192 * By default, HTML that isn't explicitly trusted (e.g. Alice's comment) is sanitized when
17193 * $sanitize is available. If $sanitize isn't available, this results in an error instead of an
17195 * <div class="well">
17196 * <div ng-repeat="userComment in myCtrl.userComments">
17197 * <b>{{userComment.name}}</b>:
17198 * <span ng-bind-html="userComment.htmlComment" class="htmlComment"></span>
17205 * <file name="script.js">
17206 * angular.module('mySceApp', ['ngSanitize'])
17207 * .controller('AppController', ['$http', '$templateCache', '$sce',
17208 * function($http, $templateCache, $sce) {
17210 * $http.get("test_data.json", {cache: $templateCache}).success(function(userComments) {
17211 * self.userComments = userComments;
17213 * self.explicitlyTrustedHtml = $sce.trustAsHtml(
17214 * '<span onmouseover="this.textContent="Explicitly trusted HTML bypasses ' +
17215 * 'sanitization."">Hover over this text.</span>');
17219 * <file name="test_data.json">
17221 * { "name": "Alice",
17223 * "<span onmouseover='this.textContent=\"PWN3D!\"'>Is <i>anyone</i> reading this?</span>"
17226 * "htmlComment": "<i>Yes!</i> Am I the only other one?"
17231 * <file name="protractor.js" type="protractor">
17232 * describe('SCE doc demo', function() {
17233 * it('should sanitize untrusted values', function() {
17234 * expect(element.all(by.css('.htmlComment')).first().getInnerHtml())
17235 * .toBe('<span>Is <i>anyone</i> reading this?</span>');
17238 * it('should NOT sanitize explicitly trusted values', function() {
17239 * expect(element(by.id('explicitlyTrustedHtml')).getInnerHtml()).toBe(
17240 * '<span onmouseover="this.textContent="Explicitly trusted HTML bypasses ' +
17241 * 'sanitization."">Hover over this text.</span>');
17249 * ## Can I disable SCE completely?
17251 * Yes, you can. However, this is strongly discouraged. SCE gives you a lot of security benefits
17252 * for little coding overhead. It will be much harder to take an SCE disabled application and
17253 * either secure it on your own or enable SCE at a later stage. It might make sense to disable SCE
17254 * for cases where you have a lot of existing code that was written before SCE was introduced and
17255 * you're migrating them a module at a time.
17257 * That said, here's how you can completely disable SCE:
17260 * angular.module('myAppWithSceDisabledmyApp', []).config(function($sceProvider) {
17261 * // Completely disable SCE. For demonstration purposes only!
17262 * // Do not use in new projects.
17263 * $sceProvider.enabled(false);
17268 /* jshint maxlen: 100 */
17270 function $SceProvider() {
17271 var enabled = true;
17275 * @name $sceProvider#enabled
17278 * @param {boolean=} value If provided, then enables/disables SCE.
17279 * @return {boolean} true if SCE is enabled, false otherwise.
17282 * Enables/disables SCE and returns the current value.
17284 this.enabled = function(value) {
17285 if (arguments.length) {
17292 /* Design notes on the default implementation for SCE.
17294 * The API contract for the SCE delegate
17295 * -------------------------------------
17296 * The SCE delegate object must provide the following 3 methods:
17298 * - trustAs(contextEnum, value)
17299 * This method is used to tell the SCE service that the provided value is OK to use in the
17300 * contexts specified by contextEnum. It must return an object that will be accepted by
17301 * getTrusted() for a compatible contextEnum and return this value.
17304 * For values that were not produced by trustAs(), return them as is. For values that were
17305 * produced by trustAs(), return the corresponding input value to trustAs. Basically, if
17306 * trustAs is wrapping the given values into some type, this operation unwraps it when given
17309 * - getTrusted(contextEnum, value)
17310 * This function should return the a value that is safe to use in the context specified by
17311 * contextEnum or throw and exception otherwise.
17313 * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be
17314 * opaque or wrapped in some holder object. That happens to be an implementation detail. For
17315 * instance, an implementation could maintain a registry of all trusted objects by context. In
17316 * such a case, trustAs() would return the same object that was passed in. getTrusted() would
17317 * return the same object passed in if it was found in the registry under a compatible context or
17318 * throw an exception otherwise. An implementation might only wrap values some of the time based
17319 * on some criteria. getTrusted() might return a value and not throw an exception for special
17320 * constants or objects even if not wrapped. All such implementations fulfill this contract.
17323 * A note on the inheritance model for SCE contexts
17324 * ------------------------------------------------
17325 * I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This
17326 * is purely an implementation details.
17328 * The contract is simply this:
17330 * getTrusted($sce.RESOURCE_URL, value) succeeding implies that getTrusted($sce.URL, value)
17331 * will also succeed.
17333 * Inheritance happens to capture this in a natural way. In some future, we
17334 * may not use inheritance anymore. That is OK because no code outside of
17335 * sce.js and sceSpecs.js would need to be aware of this detail.
17338 this.$get = ['$parse', '$sceDelegate', function(
17339 $parse, $sceDelegate) {
17340 // Prereq: Ensure that we're not running in IE<11 quirks mode. In that mode, IE < 11 allow
17341 // the "expression(javascript expression)" syntax which is insecure.
17342 if (enabled && msie < 8) {
17343 throw $sceMinErr('iequirks',
17344 'Strict Contextual Escaping does not support Internet Explorer version < 11 in quirks ' +
17345 'mode. You can fix this by adding the text <!doctype html> to the top of your HTML ' +
17346 'document. See http://docs.angularjs.org/api/ng.$sce for more information.');
17349 var sce = shallowCopy(SCE_CONTEXTS);
17353 * @name $sce#isEnabled
17356 * @return {Boolean} true if SCE is enabled, false otherwise. If you want to set the value, you
17357 * have to do it at module config time on {@link ng.$sceProvider $sceProvider}.
17360 * Returns a boolean indicating if SCE is enabled.
17362 sce.isEnabled = function() {
17365 sce.trustAs = $sceDelegate.trustAs;
17366 sce.getTrusted = $sceDelegate.getTrusted;
17367 sce.valueOf = $sceDelegate.valueOf;
17370 sce.trustAs = sce.getTrusted = function(type, value) { return value; };
17371 sce.valueOf = identity;
17376 * @name $sce#parseAs
17379 * Converts Angular {@link guide/expression expression} into a function. This is like {@link
17380 * ng.$parse $parse} and is identical when the expression is a literal constant. Otherwise, it
17381 * wraps the expression in a call to {@link ng.$sce#getTrusted $sce.getTrusted(*type*,
17384 * @param {string} type The kind of SCE context in which this result will be used.
17385 * @param {string} expression String expression to compile.
17386 * @returns {function(context, locals)} a function which represents the compiled expression:
17388 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17389 * are evaluated against (typically a scope object).
17390 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17393 sce.parseAs = function sceParseAs(type, expr) {
17394 var parsed = $parse(expr);
17395 if (parsed.literal && parsed.constant) {
17398 return $parse(expr, function(value) {
17399 return sce.getTrusted(type, value);
17406 * @name $sce#trustAs
17409 * Delegates to {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}. As such,
17410 * returns an object that is trusted by angular for use in specified strict contextual
17411 * escaping contexts (such as ng-bind-html, ng-include, any src attribute
17412 * interpolation, any dom event binding attribute interpolation such as for onclick, etc.)
17413 * that uses the provided value. See * {@link ng.$sce $sce} for enabling strict contextual
17416 * @param {string} type The kind of context in which this value is safe for use. e.g. url,
17417 * resourceUrl, html, js and css.
17418 * @param {*} value The value that that should be considered trusted/safe.
17419 * @returns {*} A value that can be used to stand in for the provided `value` in places
17420 * where Angular expects a $sce.trustAs() return value.
17425 * @name $sce#trustAsHtml
17428 * Shorthand method. `$sce.trustAsHtml(value)` →
17429 * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.HTML, value)`}
17431 * @param {*} value The value to trustAs.
17432 * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedHtml
17433 * $sce.getTrustedHtml(value)} to obtain the original value. (privileged directives
17434 * only accept expressions that are either literal constants or are the
17435 * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
17440 * @name $sce#trustAsUrl
17443 * Shorthand method. `$sce.trustAsUrl(value)` →
17444 * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.URL, value)`}
17446 * @param {*} value The value to trustAs.
17447 * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedUrl
17448 * $sce.getTrustedUrl(value)} to obtain the original value. (privileged directives
17449 * only accept expressions that are either literal constants or are the
17450 * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
17455 * @name $sce#trustAsResourceUrl
17458 * Shorthand method. `$sce.trustAsResourceUrl(value)` →
17459 * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`}
17461 * @param {*} value The value to trustAs.
17462 * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedResourceUrl
17463 * $sce.getTrustedResourceUrl(value)} to obtain the original value. (privileged directives
17464 * only accept expressions that are either literal constants or are the return
17465 * value of {@link ng.$sce#trustAs $sce.trustAs}.)
17470 * @name $sce#trustAsJs
17473 * Shorthand method. `$sce.trustAsJs(value)` →
17474 * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.JS, value)`}
17476 * @param {*} value The value to trustAs.
17477 * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedJs
17478 * $sce.getTrustedJs(value)} to obtain the original value. (privileged directives
17479 * only accept expressions that are either literal constants or are the
17480 * return value of {@link ng.$sce#trustAs $sce.trustAs}.)
17485 * @name $sce#getTrusted
17488 * Delegates to {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted`}. As such,
17489 * takes the result of a {@link ng.$sce#trustAs `$sce.trustAs`}() call and returns the
17490 * originally supplied value if the queried context type is a supertype of the created type.
17491 * If this condition isn't satisfied, throws an exception.
17493 * @param {string} type The kind of context in which this value is to be used.
17494 * @param {*} maybeTrusted The result of a prior {@link ng.$sce#trustAs `$sce.trustAs`}
17496 * @returns {*} The value the was originally provided to
17497 * {@link ng.$sce#trustAs `$sce.trustAs`} if valid in this context.
17498 * Otherwise, throws an exception.
17503 * @name $sce#getTrustedHtml
17506 * Shorthand method. `$sce.getTrustedHtml(value)` →
17507 * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`}
17509 * @param {*} value The value to pass to `$sce.getTrusted`.
17510 * @returns {*} The return value of `$sce.getTrusted($sce.HTML, value)`
17515 * @name $sce#getTrustedCss
17518 * Shorthand method. `$sce.getTrustedCss(value)` →
17519 * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`}
17521 * @param {*} value The value to pass to `$sce.getTrusted`.
17522 * @returns {*} The return value of `$sce.getTrusted($sce.CSS, value)`
17527 * @name $sce#getTrustedUrl
17530 * Shorthand method. `$sce.getTrustedUrl(value)` →
17531 * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.URL, value)`}
17533 * @param {*} value The value to pass to `$sce.getTrusted`.
17534 * @returns {*} The return value of `$sce.getTrusted($sce.URL, value)`
17539 * @name $sce#getTrustedResourceUrl
17542 * Shorthand method. `$sce.getTrustedResourceUrl(value)` →
17543 * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`}
17545 * @param {*} value The value to pass to `$sceDelegate.getTrusted`.
17546 * @returns {*} The return value of `$sce.getTrusted($sce.RESOURCE_URL, value)`
17551 * @name $sce#getTrustedJs
17554 * Shorthand method. `$sce.getTrustedJs(value)` →
17555 * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.JS, value)`}
17557 * @param {*} value The value to pass to `$sce.getTrusted`.
17558 * @returns {*} The return value of `$sce.getTrusted($sce.JS, value)`
17563 * @name $sce#parseAsHtml
17566 * Shorthand method. `$sce.parseAsHtml(expression string)` →
17567 * {@link ng.$sce#parseAs `$sce.parseAs($sce.HTML, value)`}
17569 * @param {string} expression String expression to compile.
17570 * @returns {function(context, locals)} a function which represents the compiled expression:
17572 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17573 * are evaluated against (typically a scope object).
17574 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17580 * @name $sce#parseAsCss
17583 * Shorthand method. `$sce.parseAsCss(value)` →
17584 * {@link ng.$sce#parseAs `$sce.parseAs($sce.CSS, value)`}
17586 * @param {string} expression String expression to compile.
17587 * @returns {function(context, locals)} a function which represents the compiled expression:
17589 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17590 * are evaluated against (typically a scope object).
17591 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17597 * @name $sce#parseAsUrl
17600 * Shorthand method. `$sce.parseAsUrl(value)` →
17601 * {@link ng.$sce#parseAs `$sce.parseAs($sce.URL, value)`}
17603 * @param {string} expression String expression to compile.
17604 * @returns {function(context, locals)} a function which represents the compiled expression:
17606 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17607 * are evaluated against (typically a scope object).
17608 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17614 * @name $sce#parseAsResourceUrl
17617 * Shorthand method. `$sce.parseAsResourceUrl(value)` →
17618 * {@link ng.$sce#parseAs `$sce.parseAs($sce.RESOURCE_URL, value)`}
17620 * @param {string} expression String expression to compile.
17621 * @returns {function(context, locals)} a function which represents the compiled expression:
17623 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17624 * are evaluated against (typically a scope object).
17625 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17631 * @name $sce#parseAsJs
17634 * Shorthand method. `$sce.parseAsJs(value)` →
17635 * {@link ng.$sce#parseAs `$sce.parseAs($sce.JS, value)`}
17637 * @param {string} expression String expression to compile.
17638 * @returns {function(context, locals)} a function which represents the compiled expression:
17640 * * `context` – `{object}` – an object against which any expressions embedded in the strings
17641 * are evaluated against (typically a scope object).
17642 * * `locals` – `{object=}` – local variables context object, useful for overriding values in
17646 // Shorthand delegations.
17647 var parse = sce.parseAs,
17648 getTrusted = sce.getTrusted,
17649 trustAs = sce.trustAs;
17651 forEach(SCE_CONTEXTS, function(enumValue, name) {
17652 var lName = lowercase(name);
17653 sce[camelCase("parse_as_" + lName)] = function(expr) {
17654 return parse(enumValue, expr);
17656 sce[camelCase("get_trusted_" + lName)] = function(value) {
17657 return getTrusted(enumValue, value);
17659 sce[camelCase("trust_as_" + lName)] = function(value) {
17660 return trustAs(enumValue, value);
17669 * !!! This is an undocumented "private" service !!!
17672 * @requires $window
17673 * @requires $document
17675 * @property {boolean} history Does the browser support html5 history api ?
17676 * @property {boolean} transitions Does the browser support CSS transition events ?
17677 * @property {boolean} animations Does the browser support CSS animation events ?
17680 * This is very simple implementation of testing browser's features.
17682 function $SnifferProvider() {
17683 this.$get = ['$window', '$document', function($window, $document) {
17684 var eventSupport = {},
17686 toInt((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]),
17687 boxee = /Boxee/i.test(($window.navigator || {}).userAgent),
17688 document = $document[0] || {},
17690 vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/,
17691 bodyStyle = document.body && document.body.style,
17692 transitions = false,
17693 animations = false,
17697 for (var prop in bodyStyle) {
17698 if (match = vendorRegex.exec(prop)) {
17699 vendorPrefix = match[0];
17700 vendorPrefix = vendorPrefix.substr(0, 1).toUpperCase() + vendorPrefix.substr(1);
17705 if (!vendorPrefix) {
17706 vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit';
17709 transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
17710 animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
17712 if (android && (!transitions || !animations)) {
17713 transitions = isString(bodyStyle.webkitTransition);
17714 animations = isString(bodyStyle.webkitAnimation);
17720 // Android has history.pushState, but it does not update location correctly
17721 // so let's not use the history API at all.
17722 // http://code.google.com/p/android/issues/detail?id=17471
17723 // https://github.com/angular/angular.js/issues/904
17725 // older webkit browser (533.9) on Boxee box has exactly the same problem as Android has
17726 // so let's not use the history API also
17727 // We are purposefully using `!(android < 4)` to cover the case when `android` is undefined
17729 history: !!($window.history && $window.history.pushState && !(android < 4) && !boxee),
17731 hasEvent: function(event) {
17732 // IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have
17733 // it. In particular the event is not fired when backspace or delete key are pressed or
17734 // when cut operation is performed.
17735 // IE10+ implements 'input' event but it erroneously fires under various situations,
17736 // e.g. when placeholder changes, or a form is focused.
17737 if (event === 'input' && msie <= 11) return false;
17739 if (isUndefined(eventSupport[event])) {
17740 var divElm = document.createElement('div');
17741 eventSupport[event] = 'on' + event in divElm;
17744 return eventSupport[event];
17747 vendorPrefix: vendorPrefix,
17748 transitions: transitions,
17749 animations: animations,
17755 var $compileMinErr = minErr('$compile');
17759 * @name $templateRequest
17762 * The `$templateRequest` service runs security checks then downloads the provided template using
17763 * `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request
17764 * fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the
17765 * exception can be thwarted by setting the 2nd parameter of the function to true). Note that the
17766 * contents of `$templateCache` are trusted, so the call to `$sce.getTrustedUrl(tpl)` is omitted
17767 * when `tpl` is of type string and `$templateCache` has the matching entry.
17769 * @param {string|TrustedResourceUrl} tpl The HTTP request template URL
17770 * @param {boolean=} ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty
17772 * @return {Promise} a promise for the HTTP response data of the given URL.
17774 * @property {number} totalPendingRequests total amount of pending template requests being downloaded.
17776 function $TemplateRequestProvider() {
17777 this.$get = ['$templateCache', '$http', '$q', '$sce', function($templateCache, $http, $q, $sce) {
17778 function handleRequestFn(tpl, ignoreRequestError) {
17779 handleRequestFn.totalPendingRequests++;
17781 // We consider the template cache holds only trusted templates, so
17782 // there's no need to go through whitelisting again for keys that already
17783 // are included in there. This also makes Angular accept any script
17784 // directive, no matter its name. However, we still need to unwrap trusted
17786 if (!isString(tpl) || !$templateCache.get(tpl)) {
17787 tpl = $sce.getTrustedResourceUrl(tpl);
17790 var transformResponse = $http.defaults && $http.defaults.transformResponse;
17792 if (isArray(transformResponse)) {
17793 transformResponse = transformResponse.filter(function(transformer) {
17794 return transformer !== defaultHttpResponseTransform;
17796 } else if (transformResponse === defaultHttpResponseTransform) {
17797 transformResponse = null;
17800 var httpOptions = {
17801 cache: $templateCache,
17802 transformResponse: transformResponse
17805 return $http.get(tpl, httpOptions)
17806 ['finally'](function() {
17807 handleRequestFn.totalPendingRequests--;
17809 .then(function(response) {
17810 $templateCache.put(tpl, response.data);
17811 return response.data;
17814 function handleError(resp) {
17815 if (!ignoreRequestError) {
17816 throw $compileMinErr('tpload', 'Failed to load template: {0} (HTTP status: {1} {2})',
17817 tpl, resp.status, resp.statusText);
17819 return $q.reject(resp);
17823 handleRequestFn.totalPendingRequests = 0;
17825 return handleRequestFn;
17829 function $$TestabilityProvider() {
17830 this.$get = ['$rootScope', '$browser', '$location',
17831 function($rootScope, $browser, $location) {
17834 * @name $testability
17837 * The private $$testability service provides a collection of methods for use when debugging
17838 * or by automated test and debugging tools.
17840 var testability = {};
17843 * @name $$testability#findBindings
17846 * Returns an array of elements that are bound (via ng-bind or {{}})
17847 * to expressions matching the input.
17849 * @param {Element} element The element root to search from.
17850 * @param {string} expression The binding expression to match.
17851 * @param {boolean} opt_exactMatch If true, only returns exact matches
17852 * for the expression. Filters and whitespace are ignored.
17854 testability.findBindings = function(element, expression, opt_exactMatch) {
17855 var bindings = element.getElementsByClassName('ng-binding');
17857 forEach(bindings, function(binding) {
17858 var dataBinding = angular.element(binding).data('$binding');
17860 forEach(dataBinding, function(bindingName) {
17861 if (opt_exactMatch) {
17862 var matcher = new RegExp('(^|\\s)' + escapeForRegexp(expression) + '(\\s|\\||$)');
17863 if (matcher.test(bindingName)) {
17864 matches.push(binding);
17867 if (bindingName.indexOf(expression) != -1) {
17868 matches.push(binding);
17878 * @name $$testability#findModels
17881 * Returns an array of elements that are two-way found via ng-model to
17882 * expressions matching the input.
17884 * @param {Element} element The element root to search from.
17885 * @param {string} expression The model expression to match.
17886 * @param {boolean} opt_exactMatch If true, only returns exact matches
17887 * for the expression.
17889 testability.findModels = function(element, expression, opt_exactMatch) {
17890 var prefixes = ['ng-', 'data-ng-', 'ng\\:'];
17891 for (var p = 0; p < prefixes.length; ++p) {
17892 var attributeEquals = opt_exactMatch ? '=' : '*=';
17893 var selector = '[' + prefixes[p] + 'model' + attributeEquals + '"' + expression + '"]';
17894 var elements = element.querySelectorAll(selector);
17895 if (elements.length) {
17902 * @name $$testability#getLocation
17905 * Shortcut for getting the location in a browser agnostic way. Returns
17906 * the path, search, and hash. (e.g. /path?a=b#hash)
17908 testability.getLocation = function() {
17909 return $location.url();
17913 * @name $$testability#setLocation
17916 * Shortcut for navigating to a location without doing a full page reload.
17918 * @param {string} url The location url (path, search and hash,
17919 * e.g. /path?a=b#hash) to go to.
17921 testability.setLocation = function(url) {
17922 if (url !== $location.url()) {
17923 $location.url(url);
17924 $rootScope.$digest();
17929 * @name $$testability#whenStable
17932 * Calls the callback when $timeout and $http requests are completed.
17934 * @param {function} callback
17936 testability.whenStable = function(callback) {
17937 $browser.notifyWhenNoOutstandingRequests(callback);
17940 return testability;
17944 function $TimeoutProvider() {
17945 this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler',
17946 function($rootScope, $browser, $q, $$q, $exceptionHandler) {
17948 var deferreds = {};
17956 * Angular's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch
17957 * block and delegates any exceptions to
17958 * {@link ng.$exceptionHandler $exceptionHandler} service.
17960 * The return value of calling `$timeout` is a promise, which will be resolved when
17961 * the delay has passed and the timeout function, if provided, is executed.
17963 * To cancel a timeout request, call `$timeout.cancel(promise)`.
17965 * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to
17966 * synchronously flush the queue of deferred functions.
17968 * If you only want a promise that will be resolved after some specified delay
17969 * then you can call `$timeout` without the `fn` function.
17971 * @param {function()=} fn A function, whose execution should be delayed.
17972 * @param {number=} [delay=0] Delay in milliseconds.
17973 * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
17974 * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
17975 * @param {...*=} Pass additional parameters to the executed function.
17976 * @returns {Promise} Promise that will be resolved when the timeout is reached. The value this
17977 * promise will be resolved with is the return value of the `fn` function.
17980 function timeout(fn, delay, invokeApply) {
17981 if (!isFunction(fn)) {
17982 invokeApply = delay;
17987 var args = sliceArgs(arguments, 3),
17988 skipApply = (isDefined(invokeApply) && !invokeApply),
17989 deferred = (skipApply ? $$q : $q).defer(),
17990 promise = deferred.promise,
17993 timeoutId = $browser.defer(function() {
17995 deferred.resolve(fn.apply(null, args));
17997 deferred.reject(e);
17998 $exceptionHandler(e);
18001 delete deferreds[promise.$$timeoutId];
18004 if (!skipApply) $rootScope.$apply();
18007 promise.$$timeoutId = timeoutId;
18008 deferreds[timeoutId] = deferred;
18016 * @name $timeout#cancel
18019 * Cancels a task associated with the `promise`. As a result of this, the promise will be
18020 * resolved with a rejection.
18022 * @param {Promise=} promise Promise returned by the `$timeout` function.
18023 * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
18026 timeout.cancel = function(promise) {
18027 if (promise && promise.$$timeoutId in deferreds) {
18028 deferreds[promise.$$timeoutId].reject('canceled');
18029 delete deferreds[promise.$$timeoutId];
18030 return $browser.defer.cancel(promise.$$timeoutId);
18039 // NOTE: The usage of window and document instead of $window and $document here is
18040 // deliberate. This service depends on the specific behavior of anchor nodes created by the
18041 // browser (resolving and parsing URLs) that is unlikely to be provided by mock objects and
18042 // cause us to break tests. In addition, when the browser resolves a URL for XHR, it
18043 // doesn't know about mocked locations and resolves URLs to the real document - which is
18044 // exactly the behavior needed here. There is little value is mocking these out for this
18046 var urlParsingNode = document.createElement("a");
18047 var originUrl = urlResolve(window.location.href);
18052 * Implementation Notes for non-IE browsers
18053 * ----------------------------------------
18054 * Assigning a URL to the href property of an anchor DOM node, even one attached to the DOM,
18055 * results both in the normalizing and parsing of the URL. Normalizing means that a relative
18056 * URL will be resolved into an absolute URL in the context of the application document.
18057 * Parsing means that the anchor node's host, hostname, protocol, port, pathname and related
18058 * properties are all populated to reflect the normalized URL. This approach has wide
18059 * compatibility - Safari 1+, Mozilla 1+, Opera 7+,e etc. See
18060 * http://www.aptana.com/reference/html/api/HTMLAnchorElement.html
18062 * Implementation Notes for IE
18063 * ---------------------------
18064 * IE <= 10 normalizes the URL when assigned to the anchor node similar to the other
18065 * browsers. However, the parsed components will not be set if the URL assigned did not specify
18066 * them. (e.g. if you assign a.href = "foo", then a.protocol, a.host, etc. will be empty.) We
18067 * work around that by performing the parsing in a 2nd step by taking a previously normalized
18068 * URL (e.g. by assigning to a.href) and assigning it a.href again. This correctly populates the
18069 * properties such as protocol, hostname, port, etc.
18072 * http://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement
18073 * http://www.aptana.com/reference/html/api/HTMLAnchorElement.html
18074 * http://url.spec.whatwg.org/#urlutils
18075 * https://github.com/angular/angular.js/pull/2902
18076 * http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
18079 * @param {string} url The URL to be parsed.
18080 * @description Normalizes and parses a URL.
18081 * @returns {object} Returns the normalized URL as a dictionary.
18083 * | member name | Description |
18084 * |---------------|----------------|
18085 * | href | A normalized version of the provided URL if it was not an absolute URL |
18086 * | protocol | The protocol including the trailing colon |
18087 * | host | The host and port (if the port is non-default) of the normalizedUrl |
18088 * | search | The search params, minus the question mark |
18089 * | hash | The hash string, minus the hash symbol
18090 * | hostname | The hostname
18091 * | port | The port, without ":"
18092 * | pathname | The pathname, beginning with "/"
18095 function urlResolve(url) {
18099 // Normalize before parse. Refer Implementation Notes on why this is
18100 // done in two steps on IE.
18101 urlParsingNode.setAttribute("href", href);
18102 href = urlParsingNode.href;
18105 urlParsingNode.setAttribute('href', href);
18107 // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
18109 href: urlParsingNode.href,
18110 protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
18111 host: urlParsingNode.host,
18112 search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
18113 hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
18114 hostname: urlParsingNode.hostname,
18115 port: urlParsingNode.port,
18116 pathname: (urlParsingNode.pathname.charAt(0) === '/')
18117 ? urlParsingNode.pathname
18118 : '/' + urlParsingNode.pathname
18123 * Parse a request URL and determine whether this is a same-origin request as the application document.
18125 * @param {string|object} requestUrl The url of the request as a string that will be resolved
18126 * or a parsed URL object.
18127 * @returns {boolean} Whether the request is for the same origin as the application document.
18129 function urlIsSameOrigin(requestUrl) {
18130 var parsed = (isString(requestUrl)) ? urlResolve(requestUrl) : requestUrl;
18131 return (parsed.protocol === originUrl.protocol &&
18132 parsed.host === originUrl.host);
18140 * A reference to the browser's `window` object. While `window`
18141 * is globally available in JavaScript, it causes testability problems, because
18142 * it is a global variable. In angular we always refer to it through the
18143 * `$window` service, so it may be overridden, removed or mocked for testing.
18145 * Expressions, like the one defined for the `ngClick` directive in the example
18146 * below, are evaluated with respect to the current scope. Therefore, there is
18147 * no risk of inadvertently coding in a dependency on a global value in such an
18151 <example module="windowExample">
18152 <file name="index.html">
18154 angular.module('windowExample', [])
18155 .controller('ExampleController', ['$scope', '$window', function($scope, $window) {
18156 $scope.greeting = 'Hello, World!';
18157 $scope.doGreeting = function(greeting) {
18158 $window.alert(greeting);
18162 <div ng-controller="ExampleController">
18163 <input type="text" ng-model="greeting" aria-label="greeting" />
18164 <button ng-click="doGreeting(greeting)">ALERT</button>
18167 <file name="protractor.js" type="protractor">
18168 it('should display the greeting in the input box', function() {
18169 element(by.model('greeting')).sendKeys('Hello, E2E Tests');
18170 // If we click the button it will block the test runner
18171 // element(':button').click();
18176 function $WindowProvider() {
18177 this.$get = valueFn(window);
18181 * @name $$cookieReader
18182 * @requires $document
18185 * This is a private service for reading cookies used by $http and ngCookies
18187 * @return {Object} a key/value map of the current cookies
18189 function $$CookieReader($document) {
18190 var rawDocument = $document[0] || {};
18191 var lastCookies = {};
18192 var lastCookieString = '';
18194 function safeDecodeURIComponent(str) {
18196 return decodeURIComponent(str);
18202 return function() {
18203 var cookieArray, cookie, i, index, name;
18204 var currentCookieString = rawDocument.cookie || '';
18206 if (currentCookieString !== lastCookieString) {
18207 lastCookieString = currentCookieString;
18208 cookieArray = lastCookieString.split('; ');
18211 for (i = 0; i < cookieArray.length; i++) {
18212 cookie = cookieArray[i];
18213 index = cookie.indexOf('=');
18214 if (index > 0) { //ignore nameless cookies
18215 name = safeDecodeURIComponent(cookie.substring(0, index));
18216 // the first value that is seen for a cookie is the most
18217 // specific one. values for the same cookie name that
18218 // follow are for less specific paths.
18219 if (isUndefined(lastCookies[name])) {
18220 lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1));
18225 return lastCookies;
18229 $$CookieReader.$inject = ['$document'];
18231 function $$CookieReaderProvider() {
18232 this.$get = $$CookieReader;
18235 /* global currencyFilter: true,
18237 filterFilter: true,
18239 limitToFilter: true,
18240 lowercaseFilter: true,
18241 numberFilter: true,
18242 orderByFilter: true,
18243 uppercaseFilter: true,
18248 * @name $filterProvider
18251 * Filters are just functions which transform input to an output. However filters need to be
18252 * Dependency Injected. To achieve this a filter definition consists of a factory function which is
18253 * annotated with dependencies and is responsible for creating a filter function.
18255 * <div class="alert alert-warning">
18256 * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`.
18257 * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
18258 * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
18259 * (`myapp_subsection_filterx`).
18263 * // Filter registration
18264 * function MyModule($provide, $filterProvider) {
18265 * // create a service to demonstrate injection (not always needed)
18266 * $provide.value('greet', function(name){
18267 * return 'Hello ' + name + '!';
18270 * // register a filter factory which uses the
18271 * // greet service to demonstrate DI.
18272 * $filterProvider.register('greet', function(greet){
18273 * // return the filter function which uses the greet service
18274 * // to generate salutation
18275 * return function(text) {
18276 * // filters need to be forgiving so check input validity
18277 * return text && greet(text) || text;
18283 * The filter function is registered with the `$injector` under the filter name suffix with
18287 * it('should be the same instance', inject(
18288 * function($filterProvider) {
18289 * $filterProvider.register('reverse', function(){
18293 * function($filter, reverseFilter) {
18294 * expect($filter('reverse')).toBe(reverseFilter);
18299 * For more information about how angular filters work, and how to create your own filters, see
18300 * {@link guide/filter Filters} in the Angular Developer Guide.
18308 * Filters are used for formatting data displayed to the user.
18310 * The general syntax in templates is as follows:
18312 * {{ expression [| filter_name[:parameter_value] ... ] }}
18314 * @param {String} name Name of the filter function to retrieve
18315 * @return {Function} the filter function
18317 <example name="$filter" module="filterExample">
18318 <file name="index.html">
18319 <div ng-controller="MainCtrl">
18320 <h3>{{ originalText }}</h3>
18321 <h3>{{ filteredText }}</h3>
18325 <file name="script.js">
18326 angular.module('filterExample', [])
18327 .controller('MainCtrl', function($scope, $filter) {
18328 $scope.originalText = 'hello';
18329 $scope.filteredText = $filter('uppercase')($scope.originalText);
18334 $FilterProvider.$inject = ['$provide'];
18335 function $FilterProvider($provide) {
18336 var suffix = 'Filter';
18340 * @name $filterProvider#register
18341 * @param {string|Object} name Name of the filter function, or an object map of filters where
18342 * the keys are the filter names and the values are the filter factories.
18344 * <div class="alert alert-warning">
18345 * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`.
18346 * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
18347 * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
18348 * (`myapp_subsection_filterx`).
18350 * @param {Function} factory If the first argument was a string, a factory function for the filter to be registered.
18351 * @returns {Object} Registered filter instance, or if a map of filters was provided then a map
18352 * of the registered filter instances.
18354 function register(name, factory) {
18355 if (isObject(name)) {
18357 forEach(name, function(filter, key) {
18358 filters[key] = register(key, filter);
18362 return $provide.factory(name + suffix, factory);
18365 this.register = register;
18367 this.$get = ['$injector', function($injector) {
18368 return function(name) {
18369 return $injector.get(name + suffix);
18373 ////////////////////////////////////////
18376 currencyFilter: false,
18378 filterFilter: false,
18380 limitToFilter: false,
18381 lowercaseFilter: false,
18382 numberFilter: false,
18383 orderByFilter: false,
18384 uppercaseFilter: false,
18387 register('currency', currencyFilter);
18388 register('date', dateFilter);
18389 register('filter', filterFilter);
18390 register('json', jsonFilter);
18391 register('limitTo', limitToFilter);
18392 register('lowercase', lowercaseFilter);
18393 register('number', numberFilter);
18394 register('orderBy', orderByFilter);
18395 register('uppercase', uppercaseFilter);
18404 * Selects a subset of items from `array` and returns it as a new array.
18406 * @param {Array} array The source array.
18407 * @param {string|Object|function()} expression The predicate to be used for selecting items from
18412 * - `string`: The string is used for matching against the contents of the `array`. All strings or
18413 * objects with string properties in `array` that match this string will be returned. This also
18414 * applies to nested object properties.
18415 * The predicate can be negated by prefixing the string with `!`.
18417 * - `Object`: A pattern object can be used to filter specific properties on objects contained
18418 * by `array`. For example `{name:"M", phone:"1"}` predicate will return an array of items
18419 * which have property `name` containing "M" and property `phone` containing "1". A special
18420 * property name `$` can be used (as in `{$:"text"}`) to accept a match against any
18421 * property of the object or its nested object properties. That's equivalent to the simple
18422 * substring match with a `string` as described above. The predicate can be negated by prefixing
18423 * the string with `!`.
18424 * For example `{name: "!M"}` predicate will return an array of items which have property `name`
18425 * not containing "M".
18427 * Note that a named property will match properties on the same level only, while the special
18428 * `$` property will match properties on the same level or deeper. E.g. an array item like
18429 * `{name: {first: 'John', last: 'Doe'}}` will **not** be matched by `{name: 'John'}`, but
18430 * **will** be matched by `{$: 'John'}`.
18432 * - `function(value, index, array)`: A predicate function can be used to write arbitrary filters.
18433 * The function is called for each element of the array, with the element, its index, and
18434 * the entire array itself as arguments.
18436 * The final result is an array of those elements that the predicate returned true for.
18438 * @param {function(actual, expected)|true|undefined} comparator Comparator which is used in
18439 * determining if the expected value (from the filter expression) and actual value (from
18440 * the object in the array) should be considered a match.
18444 * - `function(actual, expected)`:
18445 * The function will be given the object value and the predicate value to compare and
18446 * should return true if both values should be considered equal.
18448 * - `true`: A shorthand for `function(actual, expected) { return angular.equals(actual, expected)}`.
18449 * This is essentially strict comparison of expected and actual.
18451 * - `false|undefined`: A short hand for a function which will look for a substring match in case
18454 * Primitive values are converted to strings. Objects are not compared against primitives,
18455 * unless they have a custom `toString` method (e.g. `Date` objects).
18459 <file name="index.html">
18460 <div ng-init="friends = [{name:'John', phone:'555-1276'},
18461 {name:'Mary', phone:'800-BIG-MARY'},
18462 {name:'Mike', phone:'555-4321'},
18463 {name:'Adam', phone:'555-5678'},
18464 {name:'Julie', phone:'555-8765'},
18465 {name:'Juliette', phone:'555-5678'}]"></div>
18467 <label>Search: <input ng-model="searchText"></label>
18468 <table id="searchTextResults">
18469 <tr><th>Name</th><th>Phone</th></tr>
18470 <tr ng-repeat="friend in friends | filter:searchText">
18471 <td>{{friend.name}}</td>
18472 <td>{{friend.phone}}</td>
18476 <label>Any: <input ng-model="search.$"></label> <br>
18477 <label>Name only <input ng-model="search.name"></label><br>
18478 <label>Phone only <input ng-model="search.phone"></label><br>
18479 <label>Equality <input type="checkbox" ng-model="strict"></label><br>
18480 <table id="searchObjResults">
18481 <tr><th>Name</th><th>Phone</th></tr>
18482 <tr ng-repeat="friendObj in friends | filter:search:strict">
18483 <td>{{friendObj.name}}</td>
18484 <td>{{friendObj.phone}}</td>
18488 <file name="protractor.js" type="protractor">
18489 var expectFriendNames = function(expectedNames, key) {
18490 element.all(by.repeater(key + ' in friends').column(key + '.name')).then(function(arr) {
18491 arr.forEach(function(wd, i) {
18492 expect(wd.getText()).toMatch(expectedNames[i]);
18497 it('should search across all fields when filtering with a string', function() {
18498 var searchText = element(by.model('searchText'));
18499 searchText.clear();
18500 searchText.sendKeys('m');
18501 expectFriendNames(['Mary', 'Mike', 'Adam'], 'friend');
18503 searchText.clear();
18504 searchText.sendKeys('76');
18505 expectFriendNames(['John', 'Julie'], 'friend');
18508 it('should search in specific fields when filtering with a predicate object', function() {
18509 var searchAny = element(by.model('search.$'));
18511 searchAny.sendKeys('i');
18512 expectFriendNames(['Mary', 'Mike', 'Julie', 'Juliette'], 'friendObj');
18514 it('should use a equal comparison when comparator is true', function() {
18515 var searchName = element(by.model('search.name'));
18516 var strict = element(by.model('strict'));
18517 searchName.clear();
18518 searchName.sendKeys('Julie');
18520 expectFriendNames(['Julie'], 'friendObj');
18525 function filterFilter() {
18526 return function(array, expression, comparator) {
18527 if (!isArrayLike(array)) {
18528 if (array == null) {
18531 throw minErr('filter')('notarray', 'Expected array but received: {0}', array);
18535 var expressionType = getTypeForFilter(expression);
18537 var matchAgainstAnyProp;
18539 switch (expressionType) {
18541 predicateFn = expression;
18547 matchAgainstAnyProp = true;
18551 predicateFn = createPredicateFn(expression, comparator, matchAgainstAnyProp);
18557 return Array.prototype.filter.call(array, predicateFn);
18561 // Helper functions for `filterFilter`
18562 function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
18563 var shouldMatchPrimitives = isObject(expression) && ('$' in expression);
18566 if (comparator === true) {
18567 comparator = equals;
18568 } else if (!isFunction(comparator)) {
18569 comparator = function(actual, expected) {
18570 if (isUndefined(actual)) {
18571 // No substring matching against `undefined`
18574 if ((actual === null) || (expected === null)) {
18575 // No substring matching against `null`; only match against `null`
18576 return actual === expected;
18578 if (isObject(expected) || (isObject(actual) && !hasCustomToString(actual))) {
18579 // Should not compare primitives against objects, unless they have custom `toString` method
18583 actual = lowercase('' + actual);
18584 expected = lowercase('' + expected);
18585 return actual.indexOf(expected) !== -1;
18589 predicateFn = function(item) {
18590 if (shouldMatchPrimitives && !isObject(item)) {
18591 return deepCompare(item, expression.$, comparator, false);
18593 return deepCompare(item, expression, comparator, matchAgainstAnyProp);
18596 return predicateFn;
18599 function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
18600 var actualType = getTypeForFilter(actual);
18601 var expectedType = getTypeForFilter(expected);
18603 if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
18604 return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp);
18605 } else if (isArray(actual)) {
18606 // In case `actual` is an array, consider it a match
18607 // if ANY of it's items matches `expected`
18608 return actual.some(function(item) {
18609 return deepCompare(item, expected, comparator, matchAgainstAnyProp);
18613 switch (actualType) {
18616 if (matchAgainstAnyProp) {
18617 for (key in actual) {
18618 if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) {
18622 return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false);
18623 } else if (expectedType === 'object') {
18624 for (key in expected) {
18625 var expectedVal = expected[key];
18626 if (isFunction(expectedVal) || isUndefined(expectedVal)) {
18630 var matchAnyProperty = key === '$';
18631 var actualVal = matchAnyProperty ? actual : actual[key];
18632 if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) {
18638 return comparator(actual, expected);
18644 return comparator(actual, expected);
18648 // Used for easily differentiating between `null` and actual `object`
18649 function getTypeForFilter(val) {
18650 return (val === null) ? 'null' : typeof val;
18659 * Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default
18660 * symbol for current locale is used.
18662 * @param {number} amount Input to filter.
18663 * @param {string=} symbol Currency symbol or identifier to be displayed.
18664 * @param {number=} fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale
18665 * @returns {string} Formatted number.
18669 <example module="currencyExample">
18670 <file name="index.html">
18672 angular.module('currencyExample', [])
18673 .controller('ExampleController', ['$scope', function($scope) {
18674 $scope.amount = 1234.56;
18677 <div ng-controller="ExampleController">
18678 <input type="number" ng-model="amount" aria-label="amount"> <br>
18679 default currency symbol ($): <span id="currency-default">{{amount | currency}}</span><br>
18680 custom currency identifier (USD$): <span id="currency-custom">{{amount | currency:"USD$"}}</span>
18681 no fractions (0): <span id="currency-no-fractions">{{amount | currency:"USD$":0}}</span>
18684 <file name="protractor.js" type="protractor">
18685 it('should init with 1234.56', function() {
18686 expect(element(by.id('currency-default')).getText()).toBe('$1,234.56');
18687 expect(element(by.id('currency-custom')).getText()).toBe('USD$1,234.56');
18688 expect(element(by.id('currency-no-fractions')).getText()).toBe('USD$1,235');
18690 it('should update', function() {
18691 if (browser.params.browser == 'safari') {
18692 // Safari does not understand the minus key. See
18693 // https://github.com/angular/protractor/issues/481
18696 element(by.model('amount')).clear();
18697 element(by.model('amount')).sendKeys('-1234');
18698 expect(element(by.id('currency-default')).getText()).toBe('-$1,234.00');
18699 expect(element(by.id('currency-custom')).getText()).toBe('-USD$1,234.00');
18700 expect(element(by.id('currency-no-fractions')).getText()).toBe('-USD$1,234');
18705 currencyFilter.$inject = ['$locale'];
18706 function currencyFilter($locale) {
18707 var formats = $locale.NUMBER_FORMATS;
18708 return function(amount, currencySymbol, fractionSize) {
18709 if (isUndefined(currencySymbol)) {
18710 currencySymbol = formats.CURRENCY_SYM;
18713 if (isUndefined(fractionSize)) {
18714 fractionSize = formats.PATTERNS[1].maxFrac;
18717 // if null or undefined pass it through
18718 return (amount == null)
18720 : formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, fractionSize).
18721 replace(/\u00A4/g, currencySymbol);
18731 * Formats a number as text.
18733 * If the input is null or undefined, it will just be returned.
18734 * If the input is infinite (Infinity/-Infinity) the Infinity symbol '∞' is returned.
18735 * If the input is not a number an empty string is returned.
18738 * @param {number|string} number Number to format.
18739 * @param {(number|string)=} fractionSize Number of decimal places to round the number to.
18740 * If this is not provided then the fraction size is computed from the current locale's number
18741 * formatting pattern. In the case of the default locale, it will be 3.
18742 * @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit.
18745 <example module="numberFilterExample">
18746 <file name="index.html">
18748 angular.module('numberFilterExample', [])
18749 .controller('ExampleController', ['$scope', function($scope) {
18750 $scope.val = 1234.56789;
18753 <div ng-controller="ExampleController">
18754 <label>Enter number: <input ng-model='val'></label><br>
18755 Default formatting: <span id='number-default'>{{val | number}}</span><br>
18756 No fractions: <span>{{val | number:0}}</span><br>
18757 Negative number: <span>{{-val | number:4}}</span>
18760 <file name="protractor.js" type="protractor">
18761 it('should format numbers', function() {
18762 expect(element(by.id('number-default')).getText()).toBe('1,234.568');
18763 expect(element(by.binding('val | number:0')).getText()).toBe('1,235');
18764 expect(element(by.binding('-val | number:4')).getText()).toBe('-1,234.5679');
18767 it('should update', function() {
18768 element(by.model('val')).clear();
18769 element(by.model('val')).sendKeys('3374.333');
18770 expect(element(by.id('number-default')).getText()).toBe('3,374.333');
18771 expect(element(by.binding('val | number:0')).getText()).toBe('3,374');
18772 expect(element(by.binding('-val | number:4')).getText()).toBe('-3,374.3330');
18779 numberFilter.$inject = ['$locale'];
18780 function numberFilter($locale) {
18781 var formats = $locale.NUMBER_FORMATS;
18782 return function(number, fractionSize) {
18784 // if null or undefined pass it through
18785 return (number == null)
18787 : formatNumber(number, formats.PATTERNS[0], formats.GROUP_SEP, formats.DECIMAL_SEP,
18792 var DECIMAL_SEP = '.';
18793 function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
18794 if (isObject(number)) return '';
18796 var isNegative = number < 0;
18797 number = Math.abs(number);
18799 var isInfinity = number === Infinity;
18800 if (!isInfinity && !isFinite(number)) return '';
18802 var numStr = number + '',
18804 hasExponent = false,
18807 if (isInfinity) formatedText = '\u221e';
18809 if (!isInfinity && numStr.indexOf('e') !== -1) {
18810 var match = numStr.match(/([\d\.]+)e(-?)(\d+)/);
18811 if (match && match[2] == '-' && match[3] > fractionSize + 1) {
18814 formatedText = numStr;
18815 hasExponent = true;
18819 if (!isInfinity && !hasExponent) {
18820 var fractionLen = (numStr.split(DECIMAL_SEP)[1] || '').length;
18822 // determine fractionSize if it is not specified
18823 if (isUndefined(fractionSize)) {
18824 fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac);
18827 // safely round numbers in JS without hitting imprecisions of floating-point arithmetics
18829 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
18830 number = +(Math.round(+(number.toString() + 'e' + fractionSize)).toString() + 'e' + -fractionSize);
18832 var fraction = ('' + number).split(DECIMAL_SEP);
18833 var whole = fraction[0];
18834 fraction = fraction[1] || '';
18837 lgroup = pattern.lgSize,
18838 group = pattern.gSize;
18840 if (whole.length >= (lgroup + group)) {
18841 pos = whole.length - lgroup;
18842 for (i = 0; i < pos; i++) {
18843 if ((pos - i) % group === 0 && i !== 0) {
18844 formatedText += groupSep;
18846 formatedText += whole.charAt(i);
18850 for (i = pos; i < whole.length; i++) {
18851 if ((whole.length - i) % lgroup === 0 && i !== 0) {
18852 formatedText += groupSep;
18854 formatedText += whole.charAt(i);
18857 // format fraction part.
18858 while (fraction.length < fractionSize) {
18862 if (fractionSize && fractionSize !== "0") formatedText += decimalSep + fraction.substr(0, fractionSize);
18864 if (fractionSize > 0 && number < 1) {
18865 formatedText = number.toFixed(fractionSize);
18866 number = parseFloat(formatedText);
18867 formatedText = formatedText.replace(DECIMAL_SEP, decimalSep);
18871 if (number === 0) {
18872 isNegative = false;
18875 parts.push(isNegative ? pattern.negPre : pattern.posPre,
18877 isNegative ? pattern.negSuf : pattern.posSuf);
18878 return parts.join('');
18881 function padNumber(num, digits, trim) {
18888 while (num.length < digits) num = '0' + num;
18890 num = num.substr(num.length - digits);
18896 function dateGetter(name, size, offset, trim) {
18897 offset = offset || 0;
18898 return function(date) {
18899 var value = date['get' + name]();
18900 if (offset > 0 || value > -offset) {
18903 if (value === 0 && offset == -12) value = 12;
18904 return padNumber(value, size, trim);
18908 function dateStrGetter(name, shortForm) {
18909 return function(date, formats) {
18910 var value = date['get' + name]();
18911 var get = uppercase(shortForm ? ('SHORT' + name) : name);
18913 return formats[get][value];
18917 function timeZoneGetter(date, formats, offset) {
18918 var zone = -1 * offset;
18919 var paddedZone = (zone >= 0) ? "+" : "";
18921 paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
18922 padNumber(Math.abs(zone % 60), 2);
18927 function getFirstThursdayOfYear(year) {
18928 // 0 = index of January
18929 var dayOfWeekOnFirst = (new Date(year, 0, 1)).getDay();
18930 // 4 = index of Thursday (+1 to account for 1st = 5)
18931 // 11 = index of *next* Thursday (+1 account for 1st = 12)
18932 return new Date(year, 0, ((dayOfWeekOnFirst <= 4) ? 5 : 12) - dayOfWeekOnFirst);
18935 function getThursdayThisWeek(datetime) {
18936 return new Date(datetime.getFullYear(), datetime.getMonth(),
18937 // 4 = index of Thursday
18938 datetime.getDate() + (4 - datetime.getDay()));
18941 function weekGetter(size) {
18942 return function(date) {
18943 var firstThurs = getFirstThursdayOfYear(date.getFullYear()),
18944 thisThurs = getThursdayThisWeek(date);
18946 var diff = +thisThurs - +firstThurs,
18947 result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week
18949 return padNumber(result, size);
18953 function ampmGetter(date, formats) {
18954 return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1];
18957 function eraGetter(date, formats) {
18958 return date.getFullYear() <= 0 ? formats.ERAS[0] : formats.ERAS[1];
18961 function longEraGetter(date, formats) {
18962 return date.getFullYear() <= 0 ? formats.ERANAMES[0] : formats.ERANAMES[1];
18965 var DATE_FORMATS = {
18966 yyyy: dateGetter('FullYear', 4),
18967 yy: dateGetter('FullYear', 2, 0, true),
18968 y: dateGetter('FullYear', 1),
18969 MMMM: dateStrGetter('Month'),
18970 MMM: dateStrGetter('Month', true),
18971 MM: dateGetter('Month', 2, 1),
18972 M: dateGetter('Month', 1, 1),
18973 dd: dateGetter('Date', 2),
18974 d: dateGetter('Date', 1),
18975 HH: dateGetter('Hours', 2),
18976 H: dateGetter('Hours', 1),
18977 hh: dateGetter('Hours', 2, -12),
18978 h: dateGetter('Hours', 1, -12),
18979 mm: dateGetter('Minutes', 2),
18980 m: dateGetter('Minutes', 1),
18981 ss: dateGetter('Seconds', 2),
18982 s: dateGetter('Seconds', 1),
18983 // while ISO 8601 requires fractions to be prefixed with `.` or `,`
18984 // we can be just safely rely on using `sss` since we currently don't support single or two digit fractions
18985 sss: dateGetter('Milliseconds', 3),
18986 EEEE: dateStrGetter('Day'),
18987 EEE: dateStrGetter('Day', true),
18995 GGGG: longEraGetter
18998 var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/,
18999 NUMBER_STRING = /^\-?\d+$/;
19007 * Formats `date` to a string based on the requested `format`.
19009 * `format` string can be composed of the following elements:
19011 * * `'yyyy'`: 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010)
19012 * * `'yy'`: 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
19013 * * `'y'`: 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199)
19014 * * `'MMMM'`: Month in year (January-December)
19015 * * `'MMM'`: Month in year (Jan-Dec)
19016 * * `'MM'`: Month in year, padded (01-12)
19017 * * `'M'`: Month in year (1-12)
19018 * * `'dd'`: Day in month, padded (01-31)
19019 * * `'d'`: Day in month (1-31)
19020 * * `'EEEE'`: Day in Week,(Sunday-Saturday)
19021 * * `'EEE'`: Day in Week, (Sun-Sat)
19022 * * `'HH'`: Hour in day, padded (00-23)
19023 * * `'H'`: Hour in day (0-23)
19024 * * `'hh'`: Hour in AM/PM, padded (01-12)
19025 * * `'h'`: Hour in AM/PM, (1-12)
19026 * * `'mm'`: Minute in hour, padded (00-59)
19027 * * `'m'`: Minute in hour (0-59)
19028 * * `'ss'`: Second in minute, padded (00-59)
19029 * * `'s'`: Second in minute (0-59)
19030 * * `'sss'`: Millisecond in second, padded (000-999)
19031 * * `'a'`: AM/PM marker
19032 * * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200)
19033 * * `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year
19034 * * `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year
19035 * * `'G'`, `'GG'`, `'GGG'`: The abbreviated form of the era string (e.g. 'AD')
19036 * * `'GGGG'`: The long form of the era string (e.g. 'Anno Domini')
19038 * `format` string can also be one of the following predefined
19039 * {@link guide/i18n localizable formats}:
19041 * * `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale
19042 * (e.g. Sep 3, 2010 12:05:08 PM)
19043 * * `'short'`: equivalent to `'M/d/yy h:mm a'` for en_US locale (e.g. 9/3/10 12:05 PM)
19044 * * `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` for en_US locale
19045 * (e.g. Friday, September 3, 2010)
19046 * * `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010)
19047 * * `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010)
19048 * * `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10)
19049 * * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 PM)
19050 * * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 PM)
19052 * `format` string can contain literal values. These need to be escaped by surrounding with single quotes (e.g.
19053 * `"h 'in the morning'"`). In order to output a single quote, escape it - i.e., two single quotes in a sequence
19054 * (e.g. `"h 'o''clock'"`).
19056 * @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
19057 * number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its
19058 * shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is
19059 * specified in the string input, the time is considered to be in the local timezone.
19060 * @param {string=} format Formatting rules (see Description). If not specified,
19061 * `mediumDate` is used.
19062 * @param {string=} timezone Timezone to be used for formatting. It understands UTC/GMT and the
19063 * continental US time zone abbreviations, but for general use, use a time zone offset, for
19064 * example, `'+0430'` (4 hours, 30 minutes east of the Greenwich meridian)
19065 * If not specified, the timezone of the browser will be used.
19066 * @returns {string} Formatted string or the input if input is not recognized as date/millis.
19070 <file name="index.html">
19071 <span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
19072 <span>{{1288323623006 | date:'medium'}}</span><br>
19073 <span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
19074 <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
19075 <span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
19076 <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
19077 <span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
19078 <span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span><br>
19080 <file name="protractor.js" type="protractor">
19081 it('should format date', function() {
19082 expect(element(by.binding("1288323623006 | date:'medium'")).getText()).
19083 toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/);
19084 expect(element(by.binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).getText()).
19085 toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/);
19086 expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()).
19087 toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/);
19088 expect(element(by.binding("'1288323623006' | date:\"MM/dd/yyyy 'at' h:mma\"")).getText()).
19089 toMatch(/10\/2\d\/2010 at \d{1,2}:\d{2}(AM|PM)/);
19094 dateFilter.$inject = ['$locale'];
19095 function dateFilter($locale) {
19098 var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
19099 // 1 2 3 4 5 6 7 8 9 10 11
19100 function jsonStringToDate(string) {
19102 if (match = string.match(R_ISO8601_STR)) {
19103 var date = new Date(0),
19106 dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear,
19107 timeSetter = match[8] ? date.setUTCHours : date.setHours;
19110 tzHour = toInt(match[9] + match[10]);
19111 tzMin = toInt(match[9] + match[11]);
19113 dateSetter.call(date, toInt(match[1]), toInt(match[2]) - 1, toInt(match[3]));
19114 var h = toInt(match[4] || 0) - tzHour;
19115 var m = toInt(match[5] || 0) - tzMin;
19116 var s = toInt(match[6] || 0);
19117 var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
19118 timeSetter.call(date, h, m, s, ms);
19125 return function(date, format, timezone) {
19130 format = format || 'mediumDate';
19131 format = $locale.DATETIME_FORMATS[format] || format;
19132 if (isString(date)) {
19133 date = NUMBER_STRING.test(date) ? toInt(date) : jsonStringToDate(date);
19136 if (isNumber(date)) {
19137 date = new Date(date);
19140 if (!isDate(date) || !isFinite(date.getTime())) {
19145 match = DATE_FORMATS_SPLIT.exec(format);
19147 parts = concat(parts, match, 1);
19148 format = parts.pop();
19150 parts.push(format);
19155 var dateTimezoneOffset = date.getTimezoneOffset();
19157 dateTimezoneOffset = timezoneToOffset(timezone, date.getTimezoneOffset());
19158 date = convertTimezoneToLocal(date, timezone, true);
19160 forEach(parts, function(value) {
19161 fn = DATE_FORMATS[value];
19162 text += fn ? fn(date, $locale.DATETIME_FORMATS, dateTimezoneOffset)
19163 : value.replace(/(^'|'$)/g, '').replace(/''/g, "'");
19177 * Allows you to convert a JavaScript object into JSON string.
19179 * This filter is mostly useful for debugging. When using the double curly {{value}} notation
19180 * the binding is automatically converted to JSON.
19182 * @param {*} object Any JavaScript object (including arrays and primitive types) to filter.
19183 * @param {number=} spacing The number of spaces to use per indentation, defaults to 2.
19184 * @returns {string} JSON string.
19189 <file name="index.html">
19190 <pre id="default-spacing">{{ {'name':'value'} | json }}</pre>
19191 <pre id="custom-spacing">{{ {'name':'value'} | json:4 }}</pre>
19193 <file name="protractor.js" type="protractor">
19194 it('should jsonify filtered objects', function() {
19195 expect(element(by.id('default-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/);
19196 expect(element(by.id('custom-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/);
19202 function jsonFilter() {
19203 return function(object, spacing) {
19204 if (isUndefined(spacing)) {
19207 return toJson(object, spacing);
19217 * Converts string to lowercase.
19218 * @see angular.lowercase
19220 var lowercaseFilter = valueFn(lowercase);
19228 * Converts string to uppercase.
19229 * @see angular.uppercase
19231 var uppercaseFilter = valueFn(uppercase);
19239 * Creates a new array or string containing only a specified number of elements. The elements
19240 * are taken from either the beginning or the end of the source array, string or number, as specified by
19241 * the value and sign (positive or negative) of `limit`. If a number is used as input, it is
19242 * converted to a string.
19244 * @param {Array|string|number} input Source array, string or number to be limited.
19245 * @param {string|number} limit The length of the returned array or string. If the `limit` number
19246 * is positive, `limit` number of items from the beginning of the source array/string are copied.
19247 * If the number is negative, `limit` number of items from the end of the source array/string
19248 * are copied. The `limit` will be trimmed if it exceeds `array.length`. If `limit` is undefined,
19249 * the input will be returned unchanged.
19250 * @param {(string|number)=} begin Index at which to begin limitation. As a negative index, `begin`
19251 * indicates an offset from the end of `input`. Defaults to `0`.
19252 * @returns {Array|string} A new sub-array or substring of length `limit` or less if input array
19253 * had less than `limit` elements.
19256 <example module="limitToExample">
19257 <file name="index.html">
19259 angular.module('limitToExample', [])
19260 .controller('ExampleController', ['$scope', function($scope) {
19261 $scope.numbers = [1,2,3,4,5,6,7,8,9];
19262 $scope.letters = "abcdefghi";
19263 $scope.longNumber = 2345432342;
19264 $scope.numLimit = 3;
19265 $scope.letterLimit = 3;
19266 $scope.longNumberLimit = 3;
19269 <div ng-controller="ExampleController">
19271 Limit {{numbers}} to:
19272 <input type="number" step="1" ng-model="numLimit">
19274 <p>Output numbers: {{ numbers | limitTo:numLimit }}</p>
19276 Limit {{letters}} to:
19277 <input type="number" step="1" ng-model="letterLimit">
19279 <p>Output letters: {{ letters | limitTo:letterLimit }}</p>
19281 Limit {{longNumber}} to:
19282 <input type="number" step="1" ng-model="longNumberLimit">
19284 <p>Output long number: {{ longNumber | limitTo:longNumberLimit }}</p>
19287 <file name="protractor.js" type="protractor">
19288 var numLimitInput = element(by.model('numLimit'));
19289 var letterLimitInput = element(by.model('letterLimit'));
19290 var longNumberLimitInput = element(by.model('longNumberLimit'));
19291 var limitedNumbers = element(by.binding('numbers | limitTo:numLimit'));
19292 var limitedLetters = element(by.binding('letters | limitTo:letterLimit'));
19293 var limitedLongNumber = element(by.binding('longNumber | limitTo:longNumberLimit'));
19295 it('should limit the number array to first three items', function() {
19296 expect(numLimitInput.getAttribute('value')).toBe('3');
19297 expect(letterLimitInput.getAttribute('value')).toBe('3');
19298 expect(longNumberLimitInput.getAttribute('value')).toBe('3');
19299 expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3]');
19300 expect(limitedLetters.getText()).toEqual('Output letters: abc');
19301 expect(limitedLongNumber.getText()).toEqual('Output long number: 234');
19304 // There is a bug in safari and protractor that doesn't like the minus key
19305 // it('should update the output when -3 is entered', function() {
19306 // numLimitInput.clear();
19307 // numLimitInput.sendKeys('-3');
19308 // letterLimitInput.clear();
19309 // letterLimitInput.sendKeys('-3');
19310 // longNumberLimitInput.clear();
19311 // longNumberLimitInput.sendKeys('-3');
19312 // expect(limitedNumbers.getText()).toEqual('Output numbers: [7,8,9]');
19313 // expect(limitedLetters.getText()).toEqual('Output letters: ghi');
19314 // expect(limitedLongNumber.getText()).toEqual('Output long number: 342');
19317 it('should not exceed the maximum size of input array', function() {
19318 numLimitInput.clear();
19319 numLimitInput.sendKeys('100');
19320 letterLimitInput.clear();
19321 letterLimitInput.sendKeys('100');
19322 longNumberLimitInput.clear();
19323 longNumberLimitInput.sendKeys('100');
19324 expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3,4,5,6,7,8,9]');
19325 expect(limitedLetters.getText()).toEqual('Output letters: abcdefghi');
19326 expect(limitedLongNumber.getText()).toEqual('Output long number: 2345432342');
19331 function limitToFilter() {
19332 return function(input, limit, begin) {
19333 if (Math.abs(Number(limit)) === Infinity) {
19334 limit = Number(limit);
19336 limit = toInt(limit);
19338 if (isNaN(limit)) return input;
19340 if (isNumber(input)) input = input.toString();
19341 if (!isArray(input) && !isString(input)) return input;
19343 begin = (!begin || isNaN(begin)) ? 0 : toInt(begin);
19344 begin = (begin < 0) ? Math.max(0, input.length + begin) : begin;
19347 return input.slice(begin, begin + limit);
19350 return input.slice(limit, input.length);
19352 return input.slice(Math.max(0, begin + limit), begin);
19364 * Orders a specified `array` by the `expression` predicate. It is ordered alphabetically
19365 * for strings and numerically for numbers. Note: if you notice numbers are not being sorted
19366 * as expected, make sure they are actually being saved as numbers and not strings.
19368 * @param {Array} array The array to sort.
19369 * @param {function(*)|string|Array.<(function(*)|string)>=} expression A predicate to be
19370 * used by the comparator to determine the order of elements.
19374 * - `function`: Getter function. The result of this function will be sorted using the
19375 * `<`, `===`, `>` operator.
19376 * - `string`: An Angular expression. The result of this expression is used to compare elements
19377 * (for example `name` to sort by a property called `name` or `name.substr(0, 3)` to sort by
19378 * 3 first characters of a property called `name`). The result of a constant expression
19379 * is interpreted as a property name to be used in comparisons (for example `"special name"`
19380 * to sort object by the value of their `special name` property). An expression can be
19381 * optionally prefixed with `+` or `-` to control ascending or descending sort order
19382 * (for example, `+name` or `-name`). If no property is provided, (e.g. `'+'`) then the array
19383 * element itself is used to compare where sorting.
19384 * - `Array`: An array of function or string predicates. The first predicate in the array
19385 * is used for sorting, but when two items are equivalent, the next predicate is used.
19387 * If the predicate is missing or empty then it defaults to `'+'`.
19389 * @param {boolean=} reverse Reverse the order of the array.
19390 * @returns {Array} Sorted copy of the source array.
19394 * The example below demonstrates a simple ngRepeat, where the data is sorted
19395 * by age in descending order (predicate is set to `'-age'`).
19396 * `reverse` is not set, which means it defaults to `false`.
19397 <example module="orderByExample">
19398 <file name="index.html">
19400 angular.module('orderByExample', [])
19401 .controller('ExampleController', ['$scope', function($scope) {
19403 [{name:'John', phone:'555-1212', age:10},
19404 {name:'Mary', phone:'555-9876', age:19},
19405 {name:'Mike', phone:'555-4321', age:21},
19406 {name:'Adam', phone:'555-5678', age:35},
19407 {name:'Julie', phone:'555-8765', age:29}];
19410 <div ng-controller="ExampleController">
19411 <table class="friend">
19414 <th>Phone Number</th>
19417 <tr ng-repeat="friend in friends | orderBy:'-age'">
19418 <td>{{friend.name}}</td>
19419 <td>{{friend.phone}}</td>
19420 <td>{{friend.age}}</td>
19427 * The predicate and reverse parameters can be controlled dynamically through scope properties,
19428 * as shown in the next example.
19430 <example module="orderByExample">
19431 <file name="index.html">
19433 angular.module('orderByExample', [])
19434 .controller('ExampleController', ['$scope', function($scope) {
19436 [{name:'John', phone:'555-1212', age:10},
19437 {name:'Mary', phone:'555-9876', age:19},
19438 {name:'Mike', phone:'555-4321', age:21},
19439 {name:'Adam', phone:'555-5678', age:35},
19440 {name:'Julie', phone:'555-8765', age:29}];
19441 $scope.predicate = 'age';
19442 $scope.reverse = true;
19443 $scope.order = function(predicate) {
19444 $scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
19445 $scope.predicate = predicate;
19449 <style type="text/css">
19453 .sortorder.reverse:after {
19457 <div ng-controller="ExampleController">
19458 <pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre>
19460 [ <a href="" ng-click="predicate=''">unsorted</a> ]
19461 <table class="friend">
19464 <a href="" ng-click="order('name')">Name</a>
19465 <span class="sortorder" ng-show="predicate === 'name'" ng-class="{reverse:reverse}"></span>
19468 <a href="" ng-click="order('phone')">Phone Number</a>
19469 <span class="sortorder" ng-show="predicate === 'phone'" ng-class="{reverse:reverse}"></span>
19472 <a href="" ng-click="order('age')">Age</a>
19473 <span class="sortorder" ng-show="predicate === 'age'" ng-class="{reverse:reverse}"></span>
19476 <tr ng-repeat="friend in friends | orderBy:predicate:reverse">
19477 <td>{{friend.name}}</td>
19478 <td>{{friend.phone}}</td>
19479 <td>{{friend.age}}</td>
19486 * It's also possible to call the orderBy filter manually, by injecting `$filter`, retrieving the
19487 * filter routine with `$filter('orderBy')`, and calling the returned filter routine with the
19488 * desired parameters.
19493 <example module="orderByExample">
19494 <file name="index.html">
19495 <div ng-controller="ExampleController">
19496 <table class="friend">
19498 <th><a href="" ng-click="reverse=false;order('name', false)">Name</a>
19499 (<a href="" ng-click="order('-name',false)">^</a>)</th>
19500 <th><a href="" ng-click="reverse=!reverse;order('phone', reverse)">Phone Number</a></th>
19501 <th><a href="" ng-click="reverse=!reverse;order('age',reverse)">Age</a></th>
19503 <tr ng-repeat="friend in friends">
19504 <td>{{friend.name}}</td>
19505 <td>{{friend.phone}}</td>
19506 <td>{{friend.age}}</td>
19512 <file name="script.js">
19513 angular.module('orderByExample', [])
19514 .controller('ExampleController', ['$scope', '$filter', function($scope, $filter) {
19515 var orderBy = $filter('orderBy');
19517 { name: 'John', phone: '555-1212', age: 10 },
19518 { name: 'Mary', phone: '555-9876', age: 19 },
19519 { name: 'Mike', phone: '555-4321', age: 21 },
19520 { name: 'Adam', phone: '555-5678', age: 35 },
19521 { name: 'Julie', phone: '555-8765', age: 29 }
19523 $scope.order = function(predicate, reverse) {
19524 $scope.friends = orderBy($scope.friends, predicate, reverse);
19526 $scope.order('-age',false);
19531 orderByFilter.$inject = ['$parse'];
19532 function orderByFilter($parse) {
19533 return function(array, sortPredicate, reverseOrder) {
19535 if (!(isArrayLike(array))) return array;
19537 if (!isArray(sortPredicate)) { sortPredicate = [sortPredicate]; }
19538 if (sortPredicate.length === 0) { sortPredicate = ['+']; }
19540 var predicates = processPredicates(sortPredicate, reverseOrder);
19541 // Add a predicate at the end that evaluates to the element index. This makes the
19542 // sort stable as it works as a tie-breaker when all the input predicates cannot
19543 // distinguish between two elements.
19544 predicates.push({ get: function() { return {}; }, descending: reverseOrder ? -1 : 1});
19546 // The next three lines are a version of a Swartzian Transform idiom from Perl
19547 // (sometimes called the Decorate-Sort-Undecorate idiom)
19548 // See https://en.wikipedia.org/wiki/Schwartzian_transform
19549 var compareValues = Array.prototype.map.call(array, getComparisonObject);
19550 compareValues.sort(doComparison);
19551 array = compareValues.map(function(item) { return item.value; });
19555 function getComparisonObject(value, index) {
19558 predicateValues: predicates.map(function(predicate) {
19559 return getPredicateValue(predicate.get(value), index);
19564 function doComparison(v1, v2) {
19566 for (var index=0, length = predicates.length; index < length; ++index) {
19567 result = compare(v1.predicateValues[index], v2.predicateValues[index]) * predicates[index].descending;
19574 function processPredicates(sortPredicate, reverseOrder) {
19575 reverseOrder = reverseOrder ? -1 : 1;
19576 return sortPredicate.map(function(predicate) {
19577 var descending = 1, get = identity;
19579 if (isFunction(predicate)) {
19581 } else if (isString(predicate)) {
19582 if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {
19583 descending = predicate.charAt(0) == '-' ? -1 : 1;
19584 predicate = predicate.substring(1);
19586 if (predicate !== '') {
19587 get = $parse(predicate);
19588 if (get.constant) {
19590 get = function(value) { return value[key]; };
19594 return { get: get, descending: descending * reverseOrder };
19598 function isPrimitive(value) {
19599 switch (typeof value) {
19600 case 'number': /* falls through */
19601 case 'boolean': /* falls through */
19609 function objectValue(value, index) {
19610 // If `valueOf` is a valid function use that
19611 if (typeof value.valueOf === 'function') {
19612 value = value.valueOf();
19613 if (isPrimitive(value)) return value;
19615 // If `toString` is a valid function and not the one from `Object.prototype` use that
19616 if (hasCustomToString(value)) {
19617 value = value.toString();
19618 if (isPrimitive(value)) return value;
19620 // We have a basic object so we use the position of the object in the collection
19624 function getPredicateValue(value, index) {
19625 var type = typeof value;
19626 if (value === null) {
19629 } else if (type === 'string') {
19630 value = value.toLowerCase();
19631 } else if (type === 'object') {
19632 value = objectValue(value, index);
19634 return { value: value, type: type };
19637 function compare(v1, v2) {
19639 if (v1.type === v2.type) {
19640 if (v1.value !== v2.value) {
19641 result = v1.value < v2.value ? -1 : 1;
19644 result = v1.type < v2.type ? -1 : 1;
19650 function ngDirective(directive) {
19651 if (isFunction(directive)) {
19656 directive.restrict = directive.restrict || 'AC';
19657 return valueFn(directive);
19666 * Modifies the default behavior of the html A tag so that the default action is prevented when
19667 * the href attribute is empty.
19669 * This change permits the easy creation of action links with the `ngClick` directive
19670 * without changing the location or causing page reloads, e.g.:
19671 * `<a href="" ng-click="list.addItem()">Add Item</a>`
19673 var htmlAnchorDirective = valueFn({
19675 compile: function(element, attr) {
19676 if (!attr.href && !attr.xlinkHref) {
19677 return function(scope, element) {
19678 // If the linked element is not an anchor tag anymore, do nothing
19679 if (element[0].nodeName.toLowerCase() !== 'a') return;
19681 // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute.
19682 var href = toString.call(element.prop('href')) === '[object SVGAnimatedString]' ?
19683 'xlink:href' : 'href';
19684 element.on('click', function(event) {
19685 // if we have no href url, then don't navigate anywhere.
19686 if (!element.attr(href)) {
19687 event.preventDefault();
19702 * Using Angular markup like `{{hash}}` in an href attribute will
19703 * make the link go to the wrong URL if the user clicks it before
19704 * Angular has a chance to replace the `{{hash}}` markup with its
19705 * value. Until Angular replaces the markup the link will be broken
19706 * and will most likely return a 404 error. The `ngHref` directive
19707 * solves this problem.
19709 * The wrong way to write it:
19711 * <a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
19714 * The correct way to write it:
19716 * <a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
19720 * @param {template} ngHref any string which can contain `{{}}` markup.
19723 * This example shows various combinations of `href`, `ng-href` and `ng-click` attributes
19724 * in links and their different behaviors:
19726 <file name="index.html">
19727 <input ng-model="value" /><br />
19728 <a id="link-1" href ng-click="value = 1">link 1</a> (link, don't reload)<br />
19729 <a id="link-2" href="" ng-click="value = 2">link 2</a> (link, don't reload)<br />
19730 <a id="link-3" ng-href="/{{'123'}}">link 3</a> (link, reload!)<br />
19731 <a id="link-4" href="" name="xx" ng-click="value = 4">anchor</a> (link, don't reload)<br />
19732 <a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br />
19733 <a id="link-6" ng-href="{{value}}">link</a> (link, change location)
19735 <file name="protractor.js" type="protractor">
19736 it('should execute ng-click but not reload when href without value', function() {
19737 element(by.id('link-1')).click();
19738 expect(element(by.model('value')).getAttribute('value')).toEqual('1');
19739 expect(element(by.id('link-1')).getAttribute('href')).toBe('');
19742 it('should execute ng-click but not reload when href empty string', function() {
19743 element(by.id('link-2')).click();
19744 expect(element(by.model('value')).getAttribute('value')).toEqual('2');
19745 expect(element(by.id('link-2')).getAttribute('href')).toBe('');
19748 it('should execute ng-click and change url when ng-href specified', function() {
19749 expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/);
19751 element(by.id('link-3')).click();
19753 // At this point, we navigate away from an Angular page, so we need
19754 // to use browser.driver to get the base webdriver.
19756 browser.wait(function() {
19757 return browser.driver.getCurrentUrl().then(function(url) {
19758 return url.match(/\/123$/);
19760 }, 5000, 'page should navigate to /123');
19763 it('should execute ng-click but not reload when href empty string and name specified', function() {
19764 element(by.id('link-4')).click();
19765 expect(element(by.model('value')).getAttribute('value')).toEqual('4');
19766 expect(element(by.id('link-4')).getAttribute('href')).toBe('');
19769 it('should execute ng-click but not reload when no href but name specified', function() {
19770 element(by.id('link-5')).click();
19771 expect(element(by.model('value')).getAttribute('value')).toEqual('5');
19772 expect(element(by.id('link-5')).getAttribute('href')).toBe(null);
19775 it('should only change url when only ng-href', function() {
19776 element(by.model('value')).clear();
19777 element(by.model('value')).sendKeys('6');
19778 expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/);
19780 element(by.id('link-6')).click();
19782 // At this point, we navigate away from an Angular page, so we need
19783 // to use browser.driver to get the base webdriver.
19784 browser.wait(function() {
19785 return browser.driver.getCurrentUrl().then(function(url) {
19786 return url.match(/\/6$/);
19788 }, 5000, 'page should navigate to /6');
19801 * Using Angular markup like `{{hash}}` in a `src` attribute doesn't
19802 * work right: The browser will fetch from the URL with the literal
19803 * text `{{hash}}` until Angular replaces the expression inside
19804 * `{{hash}}`. The `ngSrc` directive solves this problem.
19806 * The buggy way to write it:
19808 * <img src="http://www.gravatar.com/avatar/{{hash}}" alt="Description"/>
19811 * The correct way to write it:
19813 * <img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />
19817 * @param {template} ngSrc any string which can contain `{{}}` markup.
19827 * Using Angular markup like `{{hash}}` in a `srcset` attribute doesn't
19828 * work right: The browser will fetch from the URL with the literal
19829 * text `{{hash}}` until Angular replaces the expression inside
19830 * `{{hash}}`. The `ngSrcset` directive solves this problem.
19832 * The buggy way to write it:
19834 * <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description"/>
19837 * The correct way to write it:
19839 * <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description" />
19843 * @param {template} ngSrcset any string which can contain `{{}}` markup.
19854 * This directive sets the `disabled` attribute on the element if the
19855 * {@link guide/expression expression} inside `ngDisabled` evaluates to truthy.
19857 * A special directive is necessary because we cannot use interpolation inside the `disabled`
19858 * attribute. The following example would make the button enabled on Chrome/Firefox
19859 * but not on older IEs:
19862 * <!-- See below for an example of ng-disabled being used correctly -->
19863 * <div ng-init="isDisabled = false">
19864 * <button disabled="{{isDisabled}}">Disabled</button>
19868 * This is because the HTML specification does not require browsers to preserve the values of
19869 * boolean attributes such as `disabled` (Their presence means true and their absence means false.)
19870 * If we put an Angular interpolation expression into such an attribute then the
19871 * binding information would be lost when the browser removes the attribute.
19875 <file name="index.html">
19876 <label>Click me to toggle: <input type="checkbox" ng-model="checked"></label><br/>
19877 <button ng-model="button" ng-disabled="checked">Button</button>
19879 <file name="protractor.js" type="protractor">
19880 it('should toggle button', function() {
19881 expect(element(by.css('button')).getAttribute('disabled')).toBeFalsy();
19882 element(by.model('checked')).click();
19883 expect(element(by.css('button')).getAttribute('disabled')).toBeTruthy();
19889 * @param {expression} ngDisabled If the {@link guide/expression expression} is truthy,
19890 * then the `disabled` attribute will be set on the element
19901 * Sets the `checked` attribute on the element, if the expression inside `ngChecked` is truthy.
19903 * Note that this directive should not be used together with {@link ngModel `ngModel`},
19904 * as this can lead to unexpected behavior.
19906 * ### Why do we need `ngChecked`?
19908 * The HTML specification does not require browsers to preserve the values of boolean attributes
19909 * such as checked. (Their presence means true and their absence means false.)
19910 * If we put an Angular interpolation expression into such an attribute then the
19911 * binding information would be lost when the browser removes the attribute.
19912 * The `ngChecked` directive solves this problem for the `checked` attribute.
19913 * This complementary directive is not removed by the browser and so provides
19914 * a permanent reliable place to store the binding information.
19917 <file name="index.html">
19918 <label>Check me to check both: <input type="checkbox" ng-model="master"></label><br/>
19919 <input id="checkSlave" type="checkbox" ng-checked="master" aria-label="Slave input">
19921 <file name="protractor.js" type="protractor">
19922 it('should check both checkBoxes', function() {
19923 expect(element(by.id('checkSlave')).getAttribute('checked')).toBeFalsy();
19924 element(by.model('master')).click();
19925 expect(element(by.id('checkSlave')).getAttribute('checked')).toBeTruthy();
19931 * @param {expression} ngChecked If the {@link guide/expression expression} is truthy,
19932 * then the `checked` attribute will be set on the element
19943 * The HTML specification does not require browsers to preserve the values of boolean attributes
19944 * such as readonly. (Their presence means true and their absence means false.)
19945 * If we put an Angular interpolation expression into such an attribute then the
19946 * binding information would be lost when the browser removes the attribute.
19947 * The `ngReadonly` directive solves this problem for the `readonly` attribute.
19948 * This complementary directive is not removed by the browser and so provides
19949 * a permanent reliable place to store the binding information.
19952 <file name="index.html">
19953 <label>Check me to make text readonly: <input type="checkbox" ng-model="checked"></label><br/>
19954 <input type="text" ng-readonly="checked" value="I'm Angular" aria-label="Readonly field" />
19956 <file name="protractor.js" type="protractor">
19957 it('should toggle readonly attr', function() {
19958 expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeFalsy();
19959 element(by.model('checked')).click();
19960 expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeTruthy();
19966 * @param {expression} ngReadonly If the {@link guide/expression expression} is truthy,
19967 * then special attribute "readonly" will be set on the element
19978 * The HTML specification does not require browsers to preserve the values of boolean attributes
19979 * such as selected. (Their presence means true and their absence means false.)
19980 * If we put an Angular interpolation expression into such an attribute then the
19981 * binding information would be lost when the browser removes the attribute.
19982 * The `ngSelected` directive solves this problem for the `selected` attribute.
19983 * This complementary directive is not removed by the browser and so provides
19984 * a permanent reliable place to store the binding information.
19988 <file name="index.html">
19989 <label>Check me to select: <input type="checkbox" ng-model="selected"></label><br/>
19990 <select aria-label="ngSelected demo">
19991 <option>Hello!</option>
19992 <option id="greet" ng-selected="selected">Greetings!</option>
19995 <file name="protractor.js" type="protractor">
19996 it('should select Greetings!', function() {
19997 expect(element(by.id('greet')).getAttribute('selected')).toBeFalsy();
19998 element(by.model('selected')).click();
19999 expect(element(by.id('greet')).getAttribute('selected')).toBeTruthy();
20005 * @param {expression} ngSelected If the {@link guide/expression expression} is truthy,
20006 * then special attribute "selected" will be set on the element
20016 * The HTML specification does not require browsers to preserve the values of boolean attributes
20017 * such as open. (Their presence means true and their absence means false.)
20018 * If we put an Angular interpolation expression into such an attribute then the
20019 * binding information would be lost when the browser removes the attribute.
20020 * The `ngOpen` directive solves this problem for the `open` attribute.
20021 * This complementary directive is not removed by the browser and so provides
20022 * a permanent reliable place to store the binding information.
20025 <file name="index.html">
20026 <label>Check me check multiple: <input type="checkbox" ng-model="open"></label><br/>
20027 <details id="details" ng-open="open">
20028 <summary>Show/Hide me</summary>
20031 <file name="protractor.js" type="protractor">
20032 it('should toggle open', function() {
20033 expect(element(by.id('details')).getAttribute('open')).toBeFalsy();
20034 element(by.model('open')).click();
20035 expect(element(by.id('details')).getAttribute('open')).toBeTruthy();
20041 * @param {expression} ngOpen If the {@link guide/expression expression} is truthy,
20042 * then special attribute "open" will be set on the element
20045 var ngAttributeAliasDirectives = {};
20047 // boolean attrs are evaluated
20048 forEach(BOOLEAN_ATTR, function(propName, attrName) {
20049 // binding to multiple is not supported
20050 if (propName == "multiple") return;
20052 function defaultLinkFn(scope, element, attr) {
20053 scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
20054 attr.$set(attrName, !!value);
20058 var normalized = directiveNormalize('ng-' + attrName);
20059 var linkFn = defaultLinkFn;
20061 if (propName === 'checked') {
20062 linkFn = function(scope, element, attr) {
20063 // ensuring ngChecked doesn't interfere with ngModel when both are set on the same input
20064 if (attr.ngModel !== attr[normalized]) {
20065 defaultLinkFn(scope, element, attr);
20070 ngAttributeAliasDirectives[normalized] = function() {
20079 // aliased input attrs are evaluated
20080 forEach(ALIASED_ATTR, function(htmlAttr, ngAttr) {
20081 ngAttributeAliasDirectives[ngAttr] = function() {
20084 link: function(scope, element, attr) {
20085 //special case ngPattern when a literal regular expression value
20086 //is used as the expression (this way we don't have to watch anything).
20087 if (ngAttr === "ngPattern" && attr.ngPattern.charAt(0) == "/") {
20088 var match = attr.ngPattern.match(REGEX_STRING_REGEXP);
20090 attr.$set("ngPattern", new RegExp(match[1], match[2]));
20095 scope.$watch(attr[ngAttr], function ngAttrAliasWatchAction(value) {
20096 attr.$set(ngAttr, value);
20103 // ng-src, ng-srcset, ng-href are interpolated
20104 forEach(['src', 'srcset', 'href'], function(attrName) {
20105 var normalized = directiveNormalize('ng-' + attrName);
20106 ngAttributeAliasDirectives[normalized] = function() {
20108 priority: 99, // it needs to run after the attributes are interpolated
20109 link: function(scope, element, attr) {
20110 var propName = attrName,
20113 if (attrName === 'href' &&
20114 toString.call(element.prop('href')) === '[object SVGAnimatedString]') {
20115 name = 'xlinkHref';
20116 attr.$attr[name] = 'xlink:href';
20120 attr.$observe(normalized, function(value) {
20122 if (attrName === 'href') {
20123 attr.$set(name, null);
20128 attr.$set(name, value);
20130 // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
20131 // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
20132 // to set the property as well to achieve the desired effect.
20133 // we use attr[attrName] value since $set can sanitize the url.
20134 if (msie && propName) element.prop(propName, attr[name]);
20141 /* global -nullFormCtrl, -SUBMITTED_CLASS, addSetValidityMethod: true
20143 var nullFormCtrl = {
20145 $$renameControl: nullFormRenameControl,
20146 $removeControl: noop,
20147 $setValidity: noop,
20149 $setPristine: noop,
20150 $setSubmitted: noop
20152 SUBMITTED_CLASS = 'ng-submitted';
20154 function nullFormRenameControl(control, name) {
20155 control.$name = name;
20160 * @name form.FormController
20162 * @property {boolean} $pristine True if user has not interacted with the form yet.
20163 * @property {boolean} $dirty True if user has already interacted with the form.
20164 * @property {boolean} $valid True if all of the containing forms and controls are valid.
20165 * @property {boolean} $invalid True if at least one containing control or form is invalid.
20166 * @property {boolean} $pending True if at least one containing control or form is pending.
20167 * @property {boolean} $submitted True if user has submitted the form even if its invalid.
20169 * @property {Object} $error Is an object hash, containing references to controls or
20170 * forms with failing validators, where:
20172 * - keys are validation tokens (error names),
20173 * - values are arrays of controls or forms that have a failing validator for given error name.
20175 * Built-in validation tokens:
20187 * - `datetimelocal`
20193 * `FormController` keeps track of all its controls and nested forms as well as the state of them,
20194 * such as being valid/invalid or dirty/pristine.
20196 * Each {@link ng.directive:form form} directive creates an instance
20197 * of `FormController`.
20200 //asks for $scope to fool the BC controller module
20201 FormController.$inject = ['$element', '$attrs', '$scope', '$animate', '$interpolate'];
20202 function FormController(element, attrs, $scope, $animate, $interpolate) {
20208 form.$$success = {};
20209 form.$pending = undefined;
20210 form.$name = $interpolate(attrs.name || attrs.ngForm || '')($scope);
20211 form.$dirty = false;
20212 form.$pristine = true;
20213 form.$valid = true;
20214 form.$invalid = false;
20215 form.$submitted = false;
20216 form.$$parentForm = nullFormCtrl;
20220 * @name form.FormController#$rollbackViewValue
20223 * Rollback all form controls pending updates to the `$modelValue`.
20225 * Updates may be pending by a debounced event or because the input is waiting for a some future
20226 * event defined in `ng-model-options`. This method is typically needed by the reset button of
20227 * a form that uses `ng-model-options` to pend updates.
20229 form.$rollbackViewValue = function() {
20230 forEach(controls, function(control) {
20231 control.$rollbackViewValue();
20237 * @name form.FormController#$commitViewValue
20240 * Commit all form controls pending updates to the `$modelValue`.
20242 * Updates may be pending by a debounced event or because the input is waiting for a some future
20243 * event defined in `ng-model-options`. This method is rarely needed as `NgModelController`
20244 * usually handles calling this in response to input events.
20246 form.$commitViewValue = function() {
20247 forEach(controls, function(control) {
20248 control.$commitViewValue();
20254 * @name form.FormController#$addControl
20255 * @param {object} control control object, either a {@link form.FormController} or an
20256 * {@link ngModel.NgModelController}
20259 * Register a control with the form. Input elements using ngModelController do this automatically
20260 * when they are linked.
20262 * Note that the current state of the control will not be reflected on the new parent form. This
20263 * is not an issue with normal use, as freshly compiled and linked controls are in a `$pristine`
20266 * However, if the method is used programmatically, for example by adding dynamically created controls,
20267 * or controls that have been previously removed without destroying their corresponding DOM element,
20268 * it's the developers responsiblity to make sure the current state propagates to the parent form.
20270 * For example, if an input control is added that is already `$dirty` and has `$error` properties,
20271 * calling `$setDirty()` and `$validate()` afterwards will propagate the state to the parent form.
20273 form.$addControl = function(control) {
20274 // Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored
20275 // and not added to the scope. Now we throw an error.
20276 assertNotHasOwnProperty(control.$name, 'input');
20277 controls.push(control);
20279 if (control.$name) {
20280 form[control.$name] = control;
20283 control.$$parentForm = form;
20286 // Private API: rename a form control
20287 form.$$renameControl = function(control, newName) {
20288 var oldName = control.$name;
20290 if (form[oldName] === control) {
20291 delete form[oldName];
20293 form[newName] = control;
20294 control.$name = newName;
20299 * @name form.FormController#$removeControl
20300 * @param {object} control control object, either a {@link form.FormController} or an
20301 * {@link ngModel.NgModelController}
20304 * Deregister a control from the form.
20306 * Input elements using ngModelController do this automatically when they are destroyed.
20308 * Note that only the removed control's validation state (`$errors`etc.) will be removed from the
20309 * form. `$dirty`, `$submitted` states will not be changed, because the expected behavior can be
20310 * different from case to case. For example, removing the only `$dirty` control from a form may or
20311 * may not mean that the form is still `$dirty`.
20313 form.$removeControl = function(control) {
20314 if (control.$name && form[control.$name] === control) {
20315 delete form[control.$name];
20317 forEach(form.$pending, function(value, name) {
20318 form.$setValidity(name, null, control);
20320 forEach(form.$error, function(value, name) {
20321 form.$setValidity(name, null, control);
20323 forEach(form.$$success, function(value, name) {
20324 form.$setValidity(name, null, control);
20327 arrayRemove(controls, control);
20328 control.$$parentForm = nullFormCtrl;
20334 * @name form.FormController#$setValidity
20337 * Sets the validity of a form control.
20339 * This method will also propagate to parent forms.
20341 addSetValidityMethod({
20344 set: function(object, property, controller) {
20345 var list = object[property];
20347 object[property] = [controller];
20349 var index = list.indexOf(controller);
20350 if (index === -1) {
20351 list.push(controller);
20355 unset: function(object, property, controller) {
20356 var list = object[property];
20360 arrayRemove(list, controller);
20361 if (list.length === 0) {
20362 delete object[property];
20370 * @name form.FormController#$setDirty
20373 * Sets the form to a dirty state.
20375 * This method can be called to add the 'ng-dirty' class and set the form to a dirty
20376 * state (ng-dirty class). This method will also propagate to parent forms.
20378 form.$setDirty = function() {
20379 $animate.removeClass(element, PRISTINE_CLASS);
20380 $animate.addClass(element, DIRTY_CLASS);
20381 form.$dirty = true;
20382 form.$pristine = false;
20383 form.$$parentForm.$setDirty();
20388 * @name form.FormController#$setPristine
20391 * Sets the form to its pristine state.
20393 * This method can be called to remove the 'ng-dirty' class and set the form to its pristine
20394 * state (ng-pristine class). This method will also propagate to all the controls contained
20397 * Setting a form back to a pristine state is often useful when we want to 'reuse' a form after
20398 * saving or resetting it.
20400 form.$setPristine = function() {
20401 $animate.setClass(element, PRISTINE_CLASS, DIRTY_CLASS + ' ' + SUBMITTED_CLASS);
20402 form.$dirty = false;
20403 form.$pristine = true;
20404 form.$submitted = false;
20405 forEach(controls, function(control) {
20406 control.$setPristine();
20412 * @name form.FormController#$setUntouched
20415 * Sets the form to its untouched state.
20417 * This method can be called to remove the 'ng-touched' class and set the form controls to their
20418 * untouched state (ng-untouched class).
20420 * Setting a form controls back to their untouched state is often useful when setting the form
20421 * back to its pristine state.
20423 form.$setUntouched = function() {
20424 forEach(controls, function(control) {
20425 control.$setUntouched();
20431 * @name form.FormController#$setSubmitted
20434 * Sets the form to its submitted state.
20436 form.$setSubmitted = function() {
20437 $animate.addClass(element, SUBMITTED_CLASS);
20438 form.$submitted = true;
20439 form.$$parentForm.$setSubmitted();
20449 * Nestable alias of {@link ng.directive:form `form`} directive. HTML
20450 * does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a
20451 * sub-group of controls needs to be determined.
20453 * Note: the purpose of `ngForm` is to group controls,
20454 * but not to be a replacement for the `<form>` tag with all of its capabilities
20455 * (e.g. posting to the server, ...).
20457 * @param {string=} ngForm|name Name of the form. If specified, the form controller will be published into
20458 * related scope, under this name.
20468 * Directive that instantiates
20469 * {@link form.FormController FormController}.
20471 * If the `name` attribute is specified, the form controller is published onto the current scope under
20474 * # Alias: {@link ng.directive:ngForm `ngForm`}
20476 * In Angular, forms can be nested. This means that the outer form is valid when all of the child
20477 * forms are valid as well. However, browsers do not allow nesting of `<form>` elements, so
20478 * Angular provides the {@link ng.directive:ngForm `ngForm`} directive which behaves identically to
20479 * `<form>` but can be nested. This allows you to have nested forms, which is very useful when
20480 * using Angular validation directives in forms that are dynamically generated using the
20481 * {@link ng.directive:ngRepeat `ngRepeat`} directive. Since you cannot dynamically generate the `name`
20482 * attribute of input elements using interpolation, you have to wrap each set of repeated inputs in an
20483 * `ngForm` directive and nest these in an outer `form` element.
20487 * - `ng-valid` is set if the form is valid.
20488 * - `ng-invalid` is set if the form is invalid.
20489 * - `ng-pending` is set if the form is pending.
20490 * - `ng-pristine` is set if the form is pristine.
20491 * - `ng-dirty` is set if the form is dirty.
20492 * - `ng-submitted` is set if the form was submitted.
20494 * Keep in mind that ngAnimate can detect each of these classes when added and removed.
20497 * # Submitting a form and preventing the default action
20499 * Since the role of forms in client-side Angular applications is different than in classical
20500 * roundtrip apps, it is desirable for the browser not to translate the form submission into a full
20501 * page reload that sends the data to the server. Instead some javascript logic should be triggered
20502 * to handle the form submission in an application-specific way.
20504 * For this reason, Angular prevents the default action (form submission to the server) unless the
20505 * `<form>` element has an `action` attribute specified.
20507 * You can use one of the following two ways to specify what javascript method should be called when
20508 * a form is submitted:
20510 * - {@link ng.directive:ngSubmit ngSubmit} directive on the form element
20511 * - {@link ng.directive:ngClick ngClick} directive on the first
20512 * button or input field of type submit (input[type=submit])
20514 * To prevent double execution of the handler, use only one of the {@link ng.directive:ngSubmit ngSubmit}
20515 * or {@link ng.directive:ngClick ngClick} directives.
20516 * This is because of the following form submission rules in the HTML specification:
20518 * - If a form has only one input field then hitting enter in this field triggers form submit
20520 * - if a form has 2+ input fields and no buttons or input[type=submit] then hitting enter
20521 * doesn't trigger submit
20522 * - if a form has one or more input fields and one or more buttons or input[type=submit] then
20523 * hitting enter in any of the input fields will trigger the click handler on the *first* button or
20524 * input[type=submit] (`ngClick`) *and* a submit handler on the enclosing form (`ngSubmit`)
20526 * Any pending `ngModelOptions` changes will take place immediately when an enclosing form is
20527 * submitted. Note that `ngClick` events will occur before the model is updated. Use `ngSubmit`
20528 * to have access to the updated model.
20530 * ## Animation Hooks
20532 * Animations in ngForm are triggered when any of the associated CSS classes are added and removed.
20533 * These classes are: `.ng-pristine`, `.ng-dirty`, `.ng-invalid` and `.ng-valid` as well as any
20534 * other validations that are performed within the form. Animations in ngForm are similar to how
20535 * they work in ngClass and animations can be hooked into using CSS transitions, keyframes as well
20536 * as JS animations.
20538 * The following example shows a simple way to utilize CSS transitions to style a form element
20539 * that has been rendered as invalid after it has been validated:
20542 * //be sure to include ngAnimate as a module to hook into more
20543 * //advanced animations
20545 * transition:0.5s linear all;
20546 * background: white;
20548 * .my-form.ng-invalid {
20555 <example deps="angular-animate.js" animations="true" fixBase="true" module="formExample">
20556 <file name="index.html">
20558 angular.module('formExample', [])
20559 .controller('FormController', ['$scope', function($scope) {
20560 $scope.userType = 'guest';
20565 transition:all linear 0.5s;
20566 background: transparent;
20568 .my-form.ng-invalid {
20572 <form name="myForm" ng-controller="FormController" class="my-form">
20573 userType: <input name="input" ng-model="userType" required>
20574 <span class="error" ng-show="myForm.input.$error.required">Required!</span><br>
20575 <code>userType = {{userType}}</code><br>
20576 <code>myForm.input.$valid = {{myForm.input.$valid}}</code><br>
20577 <code>myForm.input.$error = {{myForm.input.$error}}</code><br>
20578 <code>myForm.$valid = {{myForm.$valid}}</code><br>
20579 <code>myForm.$error.required = {{!!myForm.$error.required}}</code><br>
20582 <file name="protractor.js" type="protractor">
20583 it('should initialize to model', function() {
20584 var userType = element(by.binding('userType'));
20585 var valid = element(by.binding('myForm.input.$valid'));
20587 expect(userType.getText()).toContain('guest');
20588 expect(valid.getText()).toContain('true');
20591 it('should be invalid if empty', function() {
20592 var userType = element(by.binding('userType'));
20593 var valid = element(by.binding('myForm.input.$valid'));
20594 var userInput = element(by.model('userType'));
20597 userInput.sendKeys('');
20599 expect(userType.getText()).toEqual('userType =');
20600 expect(valid.getText()).toContain('false');
20605 * @param {string=} name Name of the form. If specified, the form controller will be published into
20606 * related scope, under this name.
20608 var formDirectiveFactory = function(isNgForm) {
20609 return ['$timeout', '$parse', function($timeout, $parse) {
20610 var formDirective = {
20612 restrict: isNgForm ? 'EAC' : 'E',
20613 require: ['form', '^^?form'], //first is the form's own ctrl, second is an optional parent form
20614 controller: FormController,
20615 compile: function ngFormCompile(formElement, attr) {
20616 // Setup initial state of the control
20617 formElement.addClass(PRISTINE_CLASS).addClass(VALID_CLASS);
20619 var nameAttr = attr.name ? 'name' : (isNgForm && attr.ngForm ? 'ngForm' : false);
20622 pre: function ngFormPreLink(scope, formElement, attr, ctrls) {
20623 var controller = ctrls[0];
20625 // if `action` attr is not present on the form, prevent the default action (submission)
20626 if (!('action' in attr)) {
20627 // we can't use jq events because if a form is destroyed during submission the default
20628 // action is not prevented. see #1238
20630 // IE 9 is not affected because it doesn't fire a submit event and try to do a full
20631 // page reload if the form was destroyed by submission of the form via a click handler
20632 // on a button in the form. Looks like an IE9 specific bug.
20633 var handleFormSubmission = function(event) {
20634 scope.$apply(function() {
20635 controller.$commitViewValue();
20636 controller.$setSubmitted();
20639 event.preventDefault();
20642 addEventListenerFn(formElement[0], 'submit', handleFormSubmission);
20644 // unregister the preventDefault listener so that we don't not leak memory but in a
20645 // way that will achieve the prevention of the default action.
20646 formElement.on('$destroy', function() {
20647 $timeout(function() {
20648 removeEventListenerFn(formElement[0], 'submit', handleFormSubmission);
20653 var parentFormCtrl = ctrls[1] || controller.$$parentForm;
20654 parentFormCtrl.$addControl(controller);
20656 var setter = nameAttr ? getSetter(controller.$name) : noop;
20659 setter(scope, controller);
20660 attr.$observe(nameAttr, function(newValue) {
20661 if (controller.$name === newValue) return;
20662 setter(scope, undefined);
20663 controller.$$parentForm.$$renameControl(controller, newValue);
20664 setter = getSetter(controller.$name);
20665 setter(scope, controller);
20668 formElement.on('$destroy', function() {
20669 controller.$$parentForm.$removeControl(controller);
20670 setter(scope, undefined);
20671 extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards
20678 return formDirective;
20680 function getSetter(expression) {
20681 if (expression === '') {
20682 //create an assignable expression, so forms with an empty name can be renamed later
20683 return $parse('this[""]').assign;
20685 return $parse(expression).assign || noop;
20690 var formDirective = formDirectiveFactory();
20691 var ngFormDirective = formDirectiveFactory(true);
20693 /* global VALID_CLASS: false,
20694 INVALID_CLASS: false,
20695 PRISTINE_CLASS: false,
20696 DIRTY_CLASS: false,
20697 UNTOUCHED_CLASS: false,
20698 TOUCHED_CLASS: false,
20699 ngModelMinErr: false,
20702 // Regex code is obtained from SO: https://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime#answer-3143231
20703 var ISO_DATE_REGEXP = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;
20704 // See valid URLs in RFC3987 (http://tools.ietf.org/html/rfc3987)
20705 var URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.?+=&%@\-/]*)?$/;
20706 var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
20707 var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/;
20708 var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/;
20709 var DATETIMELOCAL_REGEXP = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/;
20710 var WEEK_REGEXP = /^(\d{4})-W(\d\d)$/;
20711 var MONTH_REGEXP = /^(\d{4})-(\d\d)$/;
20712 var TIME_REGEXP = /^(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/;
20718 * @name input[text]
20721 * Standard HTML text input with angular data binding, inherited by most of the `input` elements.
20724 * @param {string} ngModel Assignable angular expression to data-bind to.
20725 * @param {string=} name Property name of the form under which the control is published.
20726 * @param {string=} required Adds `required` validation error key if the value is not entered.
20727 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
20728 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
20729 * `required` when you want to data-bind to the `required` attribute.
20730 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
20732 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
20733 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of
20735 * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string
20736 * that contains the regular expression body that will be converted to a regular expression
20737 * as in the ngPattern directive.
20738 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
20739 * a RegExp found by evaluating the Angular expression given in the attribute value.
20740 * If the expression evaluates to a RegExp object, then this is used directly.
20741 * If the expression evaluates to a string, then it will be converted to a RegExp
20742 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
20743 * `new RegExp('^abc$')`.<br />
20744 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
20745 * start at the index of the last search's match, thus not taking the whole input value into
20747 * @param {string=} ngChange Angular expression to be executed when input changes due to user
20748 * interaction with the input element.
20749 * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
20750 * This parameter is ignored for input[type=password] controls, which will never trim the
20754 <example name="text-input-directive" module="textInputExample">
20755 <file name="index.html">
20757 angular.module('textInputExample', [])
20758 .controller('ExampleController', ['$scope', function($scope) {
20761 word: /^\s*\w*\s*$/
20765 <form name="myForm" ng-controller="ExampleController">
20766 <label>Single word:
20767 <input type="text" name="input" ng-model="example.text"
20768 ng-pattern="example.word" required ng-trim="false">
20771 <span class="error" ng-show="myForm.input.$error.required">
20773 <span class="error" ng-show="myForm.input.$error.pattern">
20774 Single word only!</span>
20776 <tt>text = {{example.text}}</tt><br/>
20777 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
20778 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
20779 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
20780 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
20783 <file name="protractor.js" type="protractor">
20784 var text = element(by.binding('example.text'));
20785 var valid = element(by.binding('myForm.input.$valid'));
20786 var input = element(by.model('example.text'));
20788 it('should initialize to model', function() {
20789 expect(text.getText()).toContain('guest');
20790 expect(valid.getText()).toContain('true');
20793 it('should be invalid if empty', function() {
20795 input.sendKeys('');
20797 expect(text.getText()).toEqual('text =');
20798 expect(valid.getText()).toContain('false');
20801 it('should be invalid if multi word', function() {
20803 input.sendKeys('hello world');
20805 expect(valid.getText()).toContain('false');
20810 'text': textInputType,
20814 * @name input[date]
20817 * Input with date validation and transformation. In browsers that do not yet support
20818 * the HTML5 date input, a text element will be used. In that case, text must be entered in a valid ISO-8601
20819 * date format (yyyy-MM-dd), for example: `2009-01-06`. Since many
20820 * modern browsers do not yet support this input type, it is important to provide cues to users on the
20821 * expected input format via a placeholder or label.
20823 * The model must always be a Date object, otherwise Angular will throw an error.
20824 * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string.
20826 * The timezone to be used to read/write the `Date` instance in the model can be defined using
20827 * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
20829 * @param {string} ngModel Assignable angular expression to data-bind to.
20830 * @param {string=} name Property name of the form under which the control is published.
20831 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be a
20832 * valid ISO date string (yyyy-MM-dd). You can also use interpolation inside this attribute
20833 * (e.g. `min="{{minDate | date:'yyyy-MM-dd'}}"`). Note that `min` will also add native HTML5
20834 * constraint validation.
20835 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must be
20836 * a valid ISO date string (yyyy-MM-dd). You can also use interpolation inside this attribute
20837 * (e.g. `max="{{maxDate | date:'yyyy-MM-dd'}}"`). Note that `max` will also add native HTML5
20838 * constraint validation.
20839 * @param {(date|string)=} ngMin Sets the `min` validation constraint to the Date / ISO date string
20840 * the `ngMin` expression evaluates to. Note that it does not set the `min` attribute.
20841 * @param {(date|string)=} ngMax Sets the `max` validation constraint to the Date / ISO date string
20842 * the `ngMax` expression evaluates to. Note that it does not set the `max` attribute.
20843 * @param {string=} required Sets `required` validation error key if the value is not entered.
20844 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
20845 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
20846 * `required` when you want to data-bind to the `required` attribute.
20847 * @param {string=} ngChange Angular expression to be executed when input changes due to user
20848 * interaction with the input element.
20851 <example name="date-input-directive" module="dateInputExample">
20852 <file name="index.html">
20854 angular.module('dateInputExample', [])
20855 .controller('DateController', ['$scope', function($scope) {
20857 value: new Date(2013, 9, 22)
20861 <form name="myForm" ng-controller="DateController as dateCtrl">
20862 <label for="exampleInput">Pick a date in 2013:</label>
20863 <input type="date" id="exampleInput" name="input" ng-model="example.value"
20864 placeholder="yyyy-MM-dd" min="2013-01-01" max="2013-12-31" required />
20866 <span class="error" ng-show="myForm.input.$error.required">
20868 <span class="error" ng-show="myForm.input.$error.date">
20869 Not a valid date!</span>
20871 <tt>value = {{example.value | date: "yyyy-MM-dd"}}</tt><br/>
20872 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
20873 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
20874 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
20875 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
20878 <file name="protractor.js" type="protractor">
20879 var value = element(by.binding('example.value | date: "yyyy-MM-dd"'));
20880 var valid = element(by.binding('myForm.input.$valid'));
20881 var input = element(by.model('example.value'));
20883 // currently protractor/webdriver does not support
20884 // sending keys to all known HTML5 input controls
20885 // for various browsers (see https://github.com/angular/protractor/issues/562).
20886 function setInput(val) {
20887 // set the value of the element and force validation.
20888 var scr = "var ipt = document.getElementById('exampleInput'); " +
20889 "ipt.value = '" + val + "';" +
20890 "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
20891 browser.executeScript(scr);
20894 it('should initialize to model', function() {
20895 expect(value.getText()).toContain('2013-10-22');
20896 expect(valid.getText()).toContain('myForm.input.$valid = true');
20899 it('should be invalid if empty', function() {
20901 expect(value.getText()).toEqual('value =');
20902 expect(valid.getText()).toContain('myForm.input.$valid = false');
20905 it('should be invalid if over max', function() {
20906 setInput('2015-01-01');
20907 expect(value.getText()).toContain('');
20908 expect(valid.getText()).toContain('myForm.input.$valid = false');
20913 'date': createDateInputType('date', DATE_REGEXP,
20914 createDateParser(DATE_REGEXP, ['yyyy', 'MM', 'dd']),
20919 * @name input[datetime-local]
20922 * Input with datetime validation and transformation. In browsers that do not yet support
20923 * the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
20924 * local datetime format (yyyy-MM-ddTHH:mm:ss), for example: `2010-12-28T14:57:00`.
20926 * The model must always be a Date object, otherwise Angular will throw an error.
20927 * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string.
20929 * The timezone to be used to read/write the `Date` instance in the model can be defined using
20930 * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
20932 * @param {string} ngModel Assignable angular expression to data-bind to.
20933 * @param {string=} name Property name of the form under which the control is published.
20934 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
20935 * This must be a valid ISO datetime format (yyyy-MM-ddTHH:mm:ss). You can also use interpolation
20936 * inside this attribute (e.g. `min="{{minDatetimeLocal | date:'yyyy-MM-ddTHH:mm:ss'}}"`).
20937 * Note that `min` will also add native HTML5 constraint validation.
20938 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
20939 * This must be a valid ISO datetime format (yyyy-MM-ddTHH:mm:ss). You can also use interpolation
20940 * inside this attribute (e.g. `max="{{maxDatetimeLocal | date:'yyyy-MM-ddTHH:mm:ss'}}"`).
20941 * Note that `max` will also add native HTML5 constraint validation.
20942 * @param {(date|string)=} ngMin Sets the `min` validation error key to the Date / ISO datetime string
20943 * the `ngMin` expression evaluates to. Note that it does not set the `min` attribute.
20944 * @param {(date|string)=} ngMax Sets the `max` validation error key to the Date / ISO datetime string
20945 * the `ngMax` expression evaluates to. Note that it does not set the `max` attribute.
20946 * @param {string=} required Sets `required` validation error key if the value is not entered.
20947 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
20948 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
20949 * `required` when you want to data-bind to the `required` attribute.
20950 * @param {string=} ngChange Angular expression to be executed when input changes due to user
20951 * interaction with the input element.
20954 <example name="datetimelocal-input-directive" module="dateExample">
20955 <file name="index.html">
20957 angular.module('dateExample', [])
20958 .controller('DateController', ['$scope', function($scope) {
20960 value: new Date(2010, 11, 28, 14, 57)
20964 <form name="myForm" ng-controller="DateController as dateCtrl">
20965 <label for="exampleInput">Pick a date between in 2013:</label>
20966 <input type="datetime-local" id="exampleInput" name="input" ng-model="example.value"
20967 placeholder="yyyy-MM-ddTHH:mm:ss" min="2001-01-01T00:00:00" max="2013-12-31T00:00:00" required />
20969 <span class="error" ng-show="myForm.input.$error.required">
20971 <span class="error" ng-show="myForm.input.$error.datetimelocal">
20972 Not a valid date!</span>
20974 <tt>value = {{example.value | date: "yyyy-MM-ddTHH:mm:ss"}}</tt><br/>
20975 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
20976 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
20977 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
20978 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
20981 <file name="protractor.js" type="protractor">
20982 var value = element(by.binding('example.value | date: "yyyy-MM-ddTHH:mm:ss"'));
20983 var valid = element(by.binding('myForm.input.$valid'));
20984 var input = element(by.model('example.value'));
20986 // currently protractor/webdriver does not support
20987 // sending keys to all known HTML5 input controls
20988 // for various browsers (https://github.com/angular/protractor/issues/562).
20989 function setInput(val) {
20990 // set the value of the element and force validation.
20991 var scr = "var ipt = document.getElementById('exampleInput'); " +
20992 "ipt.value = '" + val + "';" +
20993 "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
20994 browser.executeScript(scr);
20997 it('should initialize to model', function() {
20998 expect(value.getText()).toContain('2010-12-28T14:57:00');
20999 expect(valid.getText()).toContain('myForm.input.$valid = true');
21002 it('should be invalid if empty', function() {
21004 expect(value.getText()).toEqual('value =');
21005 expect(valid.getText()).toContain('myForm.input.$valid = false');
21008 it('should be invalid if over max', function() {
21009 setInput('2015-01-01T23:59:00');
21010 expect(value.getText()).toContain('');
21011 expect(valid.getText()).toContain('myForm.input.$valid = false');
21016 'datetime-local': createDateInputType('datetimelocal', DATETIMELOCAL_REGEXP,
21017 createDateParser(DATETIMELOCAL_REGEXP, ['yyyy', 'MM', 'dd', 'HH', 'mm', 'ss', 'sss']),
21018 'yyyy-MM-ddTHH:mm:ss.sss'),
21022 * @name input[time]
21025 * Input with time validation and transformation. In browsers that do not yet support
21026 * the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
21027 * local time format (HH:mm:ss), for example: `14:57:00`. Model must be a Date object. This binding will always output a
21028 * Date object to the model of January 1, 1970, or local date `new Date(1970, 0, 1, HH, mm, ss)`.
21030 * The model must always be a Date object, otherwise Angular will throw an error.
21031 * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string.
21033 * The timezone to be used to read/write the `Date` instance in the model can be defined using
21034 * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
21036 * @param {string} ngModel Assignable angular expression to data-bind to.
21037 * @param {string=} name Property name of the form under which the control is published.
21038 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
21039 * This must be a valid ISO time format (HH:mm:ss). You can also use interpolation inside this
21040 * attribute (e.g. `min="{{minTime | date:'HH:mm:ss'}}"`). Note that `min` will also add
21041 * native HTML5 constraint validation.
21042 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
21043 * This must be a valid ISO time format (HH:mm:ss). You can also use interpolation inside this
21044 * attribute (e.g. `max="{{maxTime | date:'HH:mm:ss'}}"`). Note that `max` will also add
21045 * native HTML5 constraint validation.
21046 * @param {(date|string)=} ngMin Sets the `min` validation constraint to the Date / ISO time string the
21047 * `ngMin` expression evaluates to. Note that it does not set the `min` attribute.
21048 * @param {(date|string)=} ngMax Sets the `max` validation constraint to the Date / ISO time string the
21049 * `ngMax` expression evaluates to. Note that it does not set the `max` attribute.
21050 * @param {string=} required Sets `required` validation error key if the value is not entered.
21051 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21052 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21053 * `required` when you want to data-bind to the `required` attribute.
21054 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21055 * interaction with the input element.
21058 <example name="time-input-directive" module="timeExample">
21059 <file name="index.html">
21061 angular.module('timeExample', [])
21062 .controller('DateController', ['$scope', function($scope) {
21064 value: new Date(1970, 0, 1, 14, 57, 0)
21068 <form name="myForm" ng-controller="DateController as dateCtrl">
21069 <label for="exampleInput">Pick a between 8am and 5pm:</label>
21070 <input type="time" id="exampleInput" name="input" ng-model="example.value"
21071 placeholder="HH:mm:ss" min="08:00:00" max="17:00:00" required />
21073 <span class="error" ng-show="myForm.input.$error.required">
21075 <span class="error" ng-show="myForm.input.$error.time">
21076 Not a valid date!</span>
21078 <tt>value = {{example.value | date: "HH:mm:ss"}}</tt><br/>
21079 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21080 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21081 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21082 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21085 <file name="protractor.js" type="protractor">
21086 var value = element(by.binding('example.value | date: "HH:mm:ss"'));
21087 var valid = element(by.binding('myForm.input.$valid'));
21088 var input = element(by.model('example.value'));
21090 // currently protractor/webdriver does not support
21091 // sending keys to all known HTML5 input controls
21092 // for various browsers (https://github.com/angular/protractor/issues/562).
21093 function setInput(val) {
21094 // set the value of the element and force validation.
21095 var scr = "var ipt = document.getElementById('exampleInput'); " +
21096 "ipt.value = '" + val + "';" +
21097 "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
21098 browser.executeScript(scr);
21101 it('should initialize to model', function() {
21102 expect(value.getText()).toContain('14:57:00');
21103 expect(valid.getText()).toContain('myForm.input.$valid = true');
21106 it('should be invalid if empty', function() {
21108 expect(value.getText()).toEqual('value =');
21109 expect(valid.getText()).toContain('myForm.input.$valid = false');
21112 it('should be invalid if over max', function() {
21113 setInput('23:59:00');
21114 expect(value.getText()).toContain('');
21115 expect(valid.getText()).toContain('myForm.input.$valid = false');
21120 'time': createDateInputType('time', TIME_REGEXP,
21121 createDateParser(TIME_REGEXP, ['HH', 'mm', 'ss', 'sss']),
21126 * @name input[week]
21129 * Input with week-of-the-year validation and transformation to Date. In browsers that do not yet support
21130 * the HTML5 week input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
21131 * week format (yyyy-W##), for example: `2013-W02`.
21133 * The model must always be a Date object, otherwise Angular will throw an error.
21134 * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string.
21136 * The timezone to be used to read/write the `Date` instance in the model can be defined using
21137 * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
21139 * @param {string} ngModel Assignable angular expression to data-bind to.
21140 * @param {string=} name Property name of the form under which the control is published.
21141 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
21142 * This must be a valid ISO week format (yyyy-W##). You can also use interpolation inside this
21143 * attribute (e.g. `min="{{minWeek | date:'yyyy-Www'}}"`). Note that `min` will also add
21144 * native HTML5 constraint validation.
21145 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
21146 * This must be a valid ISO week format (yyyy-W##). You can also use interpolation inside this
21147 * attribute (e.g. `max="{{maxWeek | date:'yyyy-Www'}}"`). Note that `max` will also add
21148 * native HTML5 constraint validation.
21149 * @param {(date|string)=} ngMin Sets the `min` validation constraint to the Date / ISO week string
21150 * the `ngMin` expression evaluates to. Note that it does not set the `min` attribute.
21151 * @param {(date|string)=} ngMax Sets the `max` validation constraint to the Date / ISO week string
21152 * the `ngMax` expression evaluates to. Note that it does not set the `max` attribute.
21153 * @param {string=} required Sets `required` validation error key if the value is not entered.
21154 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21155 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21156 * `required` when you want to data-bind to the `required` attribute.
21157 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21158 * interaction with the input element.
21161 <example name="week-input-directive" module="weekExample">
21162 <file name="index.html">
21164 angular.module('weekExample', [])
21165 .controller('DateController', ['$scope', function($scope) {
21167 value: new Date(2013, 0, 3)
21171 <form name="myForm" ng-controller="DateController as dateCtrl">
21172 <label>Pick a date between in 2013:
21173 <input id="exampleInput" type="week" name="input" ng-model="example.value"
21174 placeholder="YYYY-W##" min="2012-W32"
21175 max="2013-W52" required />
21178 <span class="error" ng-show="myForm.input.$error.required">
21180 <span class="error" ng-show="myForm.input.$error.week">
21181 Not a valid date!</span>
21183 <tt>value = {{example.value | date: "yyyy-Www"}}</tt><br/>
21184 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21185 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21186 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21187 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21190 <file name="protractor.js" type="protractor">
21191 var value = element(by.binding('example.value | date: "yyyy-Www"'));
21192 var valid = element(by.binding('myForm.input.$valid'));
21193 var input = element(by.model('example.value'));
21195 // currently protractor/webdriver does not support
21196 // sending keys to all known HTML5 input controls
21197 // for various browsers (https://github.com/angular/protractor/issues/562).
21198 function setInput(val) {
21199 // set the value of the element and force validation.
21200 var scr = "var ipt = document.getElementById('exampleInput'); " +
21201 "ipt.value = '" + val + "';" +
21202 "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
21203 browser.executeScript(scr);
21206 it('should initialize to model', function() {
21207 expect(value.getText()).toContain('2013-W01');
21208 expect(valid.getText()).toContain('myForm.input.$valid = true');
21211 it('should be invalid if empty', function() {
21213 expect(value.getText()).toEqual('value =');
21214 expect(valid.getText()).toContain('myForm.input.$valid = false');
21217 it('should be invalid if over max', function() {
21218 setInput('2015-W01');
21219 expect(value.getText()).toContain('');
21220 expect(valid.getText()).toContain('myForm.input.$valid = false');
21225 'week': createDateInputType('week', WEEK_REGEXP, weekParser, 'yyyy-Www'),
21229 * @name input[month]
21232 * Input with month validation and transformation. In browsers that do not yet support
21233 * the HTML5 month input, a text element will be used. In that case, the text must be entered in a valid ISO-8601
21234 * month format (yyyy-MM), for example: `2009-01`.
21236 * The model must always be a Date object, otherwise Angular will throw an error.
21237 * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string.
21238 * If the model is not set to the first of the month, the next view to model update will set it
21239 * to the first of the month.
21241 * The timezone to be used to read/write the `Date` instance in the model can be defined using
21242 * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser.
21244 * @param {string} ngModel Assignable angular expression to data-bind to.
21245 * @param {string=} name Property name of the form under which the control is published.
21246 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
21247 * This must be a valid ISO month format (yyyy-MM). You can also use interpolation inside this
21248 * attribute (e.g. `min="{{minMonth | date:'yyyy-MM'}}"`). Note that `min` will also add
21249 * native HTML5 constraint validation.
21250 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
21251 * This must be a valid ISO month format (yyyy-MM). You can also use interpolation inside this
21252 * attribute (e.g. `max="{{maxMonth | date:'yyyy-MM'}}"`). Note that `max` will also add
21253 * native HTML5 constraint validation.
21254 * @param {(date|string)=} ngMin Sets the `min` validation constraint to the Date / ISO week string
21255 * the `ngMin` expression evaluates to. Note that it does not set the `min` attribute.
21256 * @param {(date|string)=} ngMax Sets the `max` validation constraint to the Date / ISO week string
21257 * the `ngMax` expression evaluates to. Note that it does not set the `max` attribute.
21259 * @param {string=} required Sets `required` validation error key if the value is not entered.
21260 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21261 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21262 * `required` when you want to data-bind to the `required` attribute.
21263 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21264 * interaction with the input element.
21267 <example name="month-input-directive" module="monthExample">
21268 <file name="index.html">
21270 angular.module('monthExample', [])
21271 .controller('DateController', ['$scope', function($scope) {
21273 value: new Date(2013, 9, 1)
21277 <form name="myForm" ng-controller="DateController as dateCtrl">
21278 <label for="exampleInput">Pick a month in 2013:</label>
21279 <input id="exampleInput" type="month" name="input" ng-model="example.value"
21280 placeholder="yyyy-MM" min="2013-01" max="2013-12" required />
21282 <span class="error" ng-show="myForm.input.$error.required">
21284 <span class="error" ng-show="myForm.input.$error.month">
21285 Not a valid month!</span>
21287 <tt>value = {{example.value | date: "yyyy-MM"}}</tt><br/>
21288 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21289 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21290 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21291 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21294 <file name="protractor.js" type="protractor">
21295 var value = element(by.binding('example.value | date: "yyyy-MM"'));
21296 var valid = element(by.binding('myForm.input.$valid'));
21297 var input = element(by.model('example.value'));
21299 // currently protractor/webdriver does not support
21300 // sending keys to all known HTML5 input controls
21301 // for various browsers (https://github.com/angular/protractor/issues/562).
21302 function setInput(val) {
21303 // set the value of the element and force validation.
21304 var scr = "var ipt = document.getElementById('exampleInput'); " +
21305 "ipt.value = '" + val + "';" +
21306 "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
21307 browser.executeScript(scr);
21310 it('should initialize to model', function() {
21311 expect(value.getText()).toContain('2013-10');
21312 expect(valid.getText()).toContain('myForm.input.$valid = true');
21315 it('should be invalid if empty', function() {
21317 expect(value.getText()).toEqual('value =');
21318 expect(valid.getText()).toContain('myForm.input.$valid = false');
21321 it('should be invalid if over max', function() {
21322 setInput('2015-01');
21323 expect(value.getText()).toContain('');
21324 expect(valid.getText()).toContain('myForm.input.$valid = false');
21329 'month': createDateInputType('month', MONTH_REGEXP,
21330 createDateParser(MONTH_REGEXP, ['yyyy', 'MM']),
21335 * @name input[number]
21338 * Text input with number validation and transformation. Sets the `number` validation
21339 * error if not a valid number.
21341 * <div class="alert alert-warning">
21342 * The model must always be of type `number` otherwise Angular will throw an error.
21343 * Be aware that a string containing a number is not enough. See the {@link ngModel:numfmt}
21344 * error docs for more information and an example of how to convert your model if necessary.
21347 * ## Issues with HTML5 constraint validation
21349 * In browsers that follow the
21350 * [HTML5 specification](https://html.spec.whatwg.org/multipage/forms.html#number-state-%28type=number%29),
21351 * `input[number]` does not work as expected with {@link ngModelOptions `ngModelOptions.allowInvalid`}.
21352 * If a non-number is entered in the input, the browser will report the value as an empty string,
21353 * which means the view / model values in `ngModel` and subsequently the scope value
21354 * will also be an empty string.
21357 * @param {string} ngModel Assignable angular expression to data-bind to.
21358 * @param {string=} name Property name of the form under which the control is published.
21359 * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`.
21360 * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`.
21361 * @param {string=} required Sets `required` validation error key if the value is not entered.
21362 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21363 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21364 * `required` when you want to data-bind to the `required` attribute.
21365 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
21367 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
21368 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of
21370 * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string
21371 * that contains the regular expression body that will be converted to a regular expression
21372 * as in the ngPattern directive.
21373 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
21374 * a RegExp found by evaluating the Angular expression given in the attribute value.
21375 * If the expression evaluates to a RegExp object, then this is used directly.
21376 * If the expression evaluates to a string, then it will be converted to a RegExp
21377 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
21378 * `new RegExp('^abc$')`.<br />
21379 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
21380 * start at the index of the last search's match, thus not taking the whole input value into
21382 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21383 * interaction with the input element.
21386 <example name="number-input-directive" module="numberExample">
21387 <file name="index.html">
21389 angular.module('numberExample', [])
21390 .controller('ExampleController', ['$scope', function($scope) {
21396 <form name="myForm" ng-controller="ExampleController">
21398 <input type="number" name="input" ng-model="example.value"
21399 min="0" max="99" required>
21402 <span class="error" ng-show="myForm.input.$error.required">
21404 <span class="error" ng-show="myForm.input.$error.number">
21405 Not valid number!</span>
21407 <tt>value = {{example.value}}</tt><br/>
21408 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21409 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21410 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21411 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21414 <file name="protractor.js" type="protractor">
21415 var value = element(by.binding('example.value'));
21416 var valid = element(by.binding('myForm.input.$valid'));
21417 var input = element(by.model('example.value'));
21419 it('should initialize to model', function() {
21420 expect(value.getText()).toContain('12');
21421 expect(valid.getText()).toContain('true');
21424 it('should be invalid if empty', function() {
21426 input.sendKeys('');
21427 expect(value.getText()).toEqual('value =');
21428 expect(valid.getText()).toContain('false');
21431 it('should be invalid if over max', function() {
21433 input.sendKeys('123');
21434 expect(value.getText()).toEqual('value =');
21435 expect(valid.getText()).toContain('false');
21440 'number': numberInputType,
21448 * Text input with URL validation. Sets the `url` validation error key if the content is not a
21451 * <div class="alert alert-warning">
21452 * **Note:** `input[url]` uses a regex to validate urls that is derived from the regex
21453 * used in Chromium. If you need stricter validation, you can use `ng-pattern` or modify
21454 * the built-in validators (see the {@link guide/forms Forms guide})
21457 * @param {string} ngModel Assignable angular expression to data-bind to.
21458 * @param {string=} name Property name of the form under which the control is published.
21459 * @param {string=} required Sets `required` validation error key if the value is not entered.
21460 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21461 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21462 * `required` when you want to data-bind to the `required` attribute.
21463 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
21465 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
21466 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of
21468 * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string
21469 * that contains the regular expression body that will be converted to a regular expression
21470 * as in the ngPattern directive.
21471 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
21472 * a RegExp found by evaluating the Angular expression given in the attribute value.
21473 * If the expression evaluates to a RegExp object, then this is used directly.
21474 * If the expression evaluates to a string, then it will be converted to a RegExp
21475 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
21476 * `new RegExp('^abc$')`.<br />
21477 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
21478 * start at the index of the last search's match, thus not taking the whole input value into
21480 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21481 * interaction with the input element.
21484 <example name="url-input-directive" module="urlExample">
21485 <file name="index.html">
21487 angular.module('urlExample', [])
21488 .controller('ExampleController', ['$scope', function($scope) {
21490 text: 'http://google.com'
21494 <form name="myForm" ng-controller="ExampleController">
21496 <input type="url" name="input" ng-model="url.text" required>
21499 <span class="error" ng-show="myForm.input.$error.required">
21501 <span class="error" ng-show="myForm.input.$error.url">
21502 Not valid url!</span>
21504 <tt>text = {{url.text}}</tt><br/>
21505 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21506 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21507 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21508 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21509 <tt>myForm.$error.url = {{!!myForm.$error.url}}</tt><br/>
21512 <file name="protractor.js" type="protractor">
21513 var text = element(by.binding('url.text'));
21514 var valid = element(by.binding('myForm.input.$valid'));
21515 var input = element(by.model('url.text'));
21517 it('should initialize to model', function() {
21518 expect(text.getText()).toContain('http://google.com');
21519 expect(valid.getText()).toContain('true');
21522 it('should be invalid if empty', function() {
21524 input.sendKeys('');
21526 expect(text.getText()).toEqual('text =');
21527 expect(valid.getText()).toContain('false');
21530 it('should be invalid if not url', function() {
21532 input.sendKeys('box');
21534 expect(valid.getText()).toContain('false');
21539 'url': urlInputType,
21544 * @name input[email]
21547 * Text input with email validation. Sets the `email` validation error key if not a valid email
21550 * <div class="alert alert-warning">
21551 * **Note:** `input[email]` uses a regex to validate email addresses that is derived from the regex
21552 * used in Chromium. If you need stricter validation (e.g. requiring a top-level domain), you can
21553 * use `ng-pattern` or modify the built-in validators (see the {@link guide/forms Forms guide})
21556 * @param {string} ngModel Assignable angular expression to data-bind to.
21557 * @param {string=} name Property name of the form under which the control is published.
21558 * @param {string=} required Sets `required` validation error key if the value is not entered.
21559 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
21560 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
21561 * `required` when you want to data-bind to the `required` attribute.
21562 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
21564 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
21565 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of
21567 * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string
21568 * that contains the regular expression body that will be converted to a regular expression
21569 * as in the ngPattern directive.
21570 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
21571 * a RegExp found by evaluating the Angular expression given in the attribute value.
21572 * If the expression evaluates to a RegExp object, then this is used directly.
21573 * If the expression evaluates to a string, then it will be converted to a RegExp
21574 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
21575 * `new RegExp('^abc$')`.<br />
21576 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
21577 * start at the index of the last search's match, thus not taking the whole input value into
21579 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21580 * interaction with the input element.
21583 <example name="email-input-directive" module="emailExample">
21584 <file name="index.html">
21586 angular.module('emailExample', [])
21587 .controller('ExampleController', ['$scope', function($scope) {
21589 text: 'me@example.com'
21593 <form name="myForm" ng-controller="ExampleController">
21595 <input type="email" name="input" ng-model="email.text" required>
21598 <span class="error" ng-show="myForm.input.$error.required">
21600 <span class="error" ng-show="myForm.input.$error.email">
21601 Not valid email!</span>
21603 <tt>text = {{email.text}}</tt><br/>
21604 <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
21605 <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
21606 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
21607 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
21608 <tt>myForm.$error.email = {{!!myForm.$error.email}}</tt><br/>
21611 <file name="protractor.js" type="protractor">
21612 var text = element(by.binding('email.text'));
21613 var valid = element(by.binding('myForm.input.$valid'));
21614 var input = element(by.model('email.text'));
21616 it('should initialize to model', function() {
21617 expect(text.getText()).toContain('me@example.com');
21618 expect(valid.getText()).toContain('true');
21621 it('should be invalid if empty', function() {
21623 input.sendKeys('');
21624 expect(text.getText()).toEqual('text =');
21625 expect(valid.getText()).toContain('false');
21628 it('should be invalid if not email', function() {
21630 input.sendKeys('xxx');
21632 expect(valid.getText()).toContain('false');
21637 'email': emailInputType,
21642 * @name input[radio]
21645 * HTML radio button.
21647 * @param {string} ngModel Assignable angular expression to data-bind to.
21648 * @param {string} value The value to which the `ngModel` expression should be set when selected.
21649 * Note that `value` only supports `string` values, i.e. the scope model needs to be a string,
21650 * too. Use `ngValue` if you need complex models (`number`, `object`, ...).
21651 * @param {string=} name Property name of the form under which the control is published.
21652 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21653 * interaction with the input element.
21654 * @param {string} ngValue Angular expression to which `ngModel` will be be set when the radio
21655 * is selected. Should be used instead of the `value` attribute if you need
21656 * a non-string `ngModel` (`boolean`, `array`, ...).
21659 <example name="radio-input-directive" module="radioExample">
21660 <file name="index.html">
21662 angular.module('radioExample', [])
21663 .controller('ExampleController', ['$scope', function($scope) {
21667 $scope.specialValue = {
21673 <form name="myForm" ng-controller="ExampleController">
21675 <input type="radio" ng-model="color.name" value="red">
21679 <input type="radio" ng-model="color.name" ng-value="specialValue">
21683 <input type="radio" ng-model="color.name" value="blue">
21686 <tt>color = {{color.name | json}}</tt><br/>
21688 Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`.
21690 <file name="protractor.js" type="protractor">
21691 it('should change state', function() {
21692 var color = element(by.binding('color.name'));
21694 expect(color.getText()).toContain('blue');
21696 element.all(by.model('color.name')).get(0).click();
21698 expect(color.getText()).toContain('red');
21703 'radio': radioInputType,
21708 * @name input[checkbox]
21713 * @param {string} ngModel Assignable angular expression to data-bind to.
21714 * @param {string=} name Property name of the form under which the control is published.
21715 * @param {expression=} ngTrueValue The value to which the expression should be set when selected.
21716 * @param {expression=} ngFalseValue The value to which the expression should be set when not selected.
21717 * @param {string=} ngChange Angular expression to be executed when input changes due to user
21718 * interaction with the input element.
21721 <example name="checkbox-input-directive" module="checkboxExample">
21722 <file name="index.html">
21724 angular.module('checkboxExample', [])
21725 .controller('ExampleController', ['$scope', function($scope) {
21726 $scope.checkboxModel = {
21732 <form name="myForm" ng-controller="ExampleController">
21734 <input type="checkbox" ng-model="checkboxModel.value1">
21737 <input type="checkbox" ng-model="checkboxModel.value2"
21738 ng-true-value="'YES'" ng-false-value="'NO'">
21740 <tt>value1 = {{checkboxModel.value1}}</tt><br/>
21741 <tt>value2 = {{checkboxModel.value2}}</tt><br/>
21744 <file name="protractor.js" type="protractor">
21745 it('should change state', function() {
21746 var value1 = element(by.binding('checkboxModel.value1'));
21747 var value2 = element(by.binding('checkboxModel.value2'));
21749 expect(value1.getText()).toContain('true');
21750 expect(value2.getText()).toContain('YES');
21752 element(by.model('checkboxModel.value1')).click();
21753 element(by.model('checkboxModel.value2')).click();
21755 expect(value1.getText()).toContain('false');
21756 expect(value2.getText()).toContain('NO');
21761 'checkbox': checkboxInputType,
21770 function stringBasedInputType(ctrl) {
21771 ctrl.$formatters.push(function(value) {
21772 return ctrl.$isEmpty(value) ? value : value.toString();
21776 function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
21777 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
21778 stringBasedInputType(ctrl);
21781 function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
21782 var type = lowercase(element[0].type);
21784 // In composition mode, users are still inputing intermediate text buffer,
21785 // hold the listener until composition is done.
21786 // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
21787 if (!$sniffer.android) {
21788 var composing = false;
21790 element.on('compositionstart', function(data) {
21794 element.on('compositionend', function() {
21800 var listener = function(ev) {
21802 $browser.defer.cancel(timeout);
21805 if (composing) return;
21806 var value = element.val(),
21807 event = ev && ev.type;
21809 // By default we will trim the value
21810 // If the attribute ng-trim exists we will avoid trimming
21811 // If input type is 'password', the value is never trimmed
21812 if (type !== 'password' && (!attr.ngTrim || attr.ngTrim !== 'false')) {
21813 value = trim(value);
21816 // If a control is suffering from bad input (due to native validators), browsers discard its
21817 // value, so it may be necessary to revalidate (by calling $setViewValue again) even if the
21818 // control's value is the same empty value twice in a row.
21819 if (ctrl.$viewValue !== value || (value === '' && ctrl.$$hasNativeValidators)) {
21820 ctrl.$setViewValue(value, event);
21824 // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the
21825 // input event on backspace, delete or cut
21826 if ($sniffer.hasEvent('input')) {
21827 element.on('input', listener);
21831 var deferListener = function(ev, input, origValue) {
21833 timeout = $browser.defer(function() {
21835 if (!input || input.value !== origValue) {
21842 element.on('keydown', function(event) {
21843 var key = event.keyCode;
21846 // command modifiers arrows
21847 if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;
21849 deferListener(event, this, this.value);
21852 // if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
21853 if ($sniffer.hasEvent('paste')) {
21854 element.on('paste cut', deferListener);
21858 // if user paste into input using mouse on older browser
21859 // or form autocomplete on newer browser, we need "change" event to catch it
21860 element.on('change', listener);
21862 ctrl.$render = function() {
21863 // Workaround for Firefox validation #12102.
21864 var value = ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue;
21865 if (element.val() !== value) {
21866 element.val(value);
21871 function weekParser(isoWeek, existingDate) {
21872 if (isDate(isoWeek)) {
21876 if (isString(isoWeek)) {
21877 WEEK_REGEXP.lastIndex = 0;
21878 var parts = WEEK_REGEXP.exec(isoWeek);
21880 var year = +parts[1],
21886 firstThurs = getFirstThursdayOfYear(year),
21887 addDays = (week - 1) * 7;
21889 if (existingDate) {
21890 hours = existingDate.getHours();
21891 minutes = existingDate.getMinutes();
21892 seconds = existingDate.getSeconds();
21893 milliseconds = existingDate.getMilliseconds();
21896 return new Date(year, 0, firstThurs.getDate() + addDays, hours, minutes, seconds, milliseconds);
21903 function createDateParser(regexp, mapping) {
21904 return function(iso, date) {
21911 if (isString(iso)) {
21912 // When a date is JSON'ified to wraps itself inside of an extra
21913 // set of double quotes. This makes the date parsing code unable
21914 // to match the date string and parse it as a date.
21915 if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
21916 iso = iso.substring(1, iso.length - 1);
21918 if (ISO_DATE_REGEXP.test(iso)) {
21919 return new Date(iso);
21921 regexp.lastIndex = 0;
21922 parts = regexp.exec(iso);
21928 yyyy: date.getFullYear(),
21929 MM: date.getMonth() + 1,
21930 dd: date.getDate(),
21931 HH: date.getHours(),
21932 mm: date.getMinutes(),
21933 ss: date.getSeconds(),
21934 sss: date.getMilliseconds() / 1000
21937 map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 };
21940 forEach(parts, function(part, index) {
21941 if (index < mapping.length) {
21942 map[mapping[index]] = +part;
21945 return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0);
21953 function createDateInputType(type, regexp, parseDate, format) {
21954 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {
21955 badInputChecker(scope, element, attr, ctrl);
21956 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
21957 var timezone = ctrl && ctrl.$options && ctrl.$options.timezone;
21960 ctrl.$$parserName = type;
21961 ctrl.$parsers.push(function(value) {
21962 if (ctrl.$isEmpty(value)) return null;
21963 if (regexp.test(value)) {
21964 // Note: We cannot read ctrl.$modelValue, as there might be a different
21965 // parser/formatter in the processing chain so that the model
21966 // contains some different data format!
21967 var parsedDate = parseDate(value, previousDate);
21969 parsedDate = convertTimezoneToLocal(parsedDate, timezone);
21976 ctrl.$formatters.push(function(value) {
21977 if (value && !isDate(value)) {
21978 throw ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value);
21980 if (isValidDate(value)) {
21981 previousDate = value;
21982 if (previousDate && timezone) {
21983 previousDate = convertTimezoneToLocal(previousDate, timezone, true);
21985 return $filter('date')(value, format, timezone);
21987 previousDate = null;
21992 if (isDefined(attr.min) || attr.ngMin) {
21994 ctrl.$validators.min = function(value) {
21995 return !isValidDate(value) || isUndefined(minVal) || parseDate(value) >= minVal;
21997 attr.$observe('min', function(val) {
21998 minVal = parseObservedDateValue(val);
22003 if (isDefined(attr.max) || attr.ngMax) {
22005 ctrl.$validators.max = function(value) {
22006 return !isValidDate(value) || isUndefined(maxVal) || parseDate(value) <= maxVal;
22008 attr.$observe('max', function(val) {
22009 maxVal = parseObservedDateValue(val);
22014 function isValidDate(value) {
22015 // Invalid Date: getTime() returns NaN
22016 return value && !(value.getTime && value.getTime() !== value.getTime());
22019 function parseObservedDateValue(val) {
22020 return isDefined(val) && !isDate(val) ? parseDate(val) || undefined : val;
22025 function badInputChecker(scope, element, attr, ctrl) {
22026 var node = element[0];
22027 var nativeValidation = ctrl.$$hasNativeValidators = isObject(node.validity);
22028 if (nativeValidation) {
22029 ctrl.$parsers.push(function(value) {
22030 var validity = element.prop(VALIDITY_STATE_PROPERTY) || {};
22031 // Detect bug in FF35 for input[email] (https://bugzilla.mozilla.org/show_bug.cgi?id=1064430):
22032 // - also sets validity.badInput (should only be validity.typeMismatch).
22033 // - see http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-(type=email)
22034 // - can ignore this case as we can still read out the erroneous email...
22035 return validity.badInput && !validity.typeMismatch ? undefined : value;
22040 function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
22041 badInputChecker(scope, element, attr, ctrl);
22042 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
22044 ctrl.$$parserName = 'number';
22045 ctrl.$parsers.push(function(value) {
22046 if (ctrl.$isEmpty(value)) return null;
22047 if (NUMBER_REGEXP.test(value)) return parseFloat(value);
22051 ctrl.$formatters.push(function(value) {
22052 if (!ctrl.$isEmpty(value)) {
22053 if (!isNumber(value)) {
22054 throw ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value);
22056 value = value.toString();
22061 if (isDefined(attr.min) || attr.ngMin) {
22063 ctrl.$validators.min = function(value) {
22064 return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal;
22067 attr.$observe('min', function(val) {
22068 if (isDefined(val) && !isNumber(val)) {
22069 val = parseFloat(val, 10);
22071 minVal = isNumber(val) && !isNaN(val) ? val : undefined;
22072 // TODO(matsko): implement validateLater to reduce number of validations
22077 if (isDefined(attr.max) || attr.ngMax) {
22079 ctrl.$validators.max = function(value) {
22080 return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal;
22083 attr.$observe('max', function(val) {
22084 if (isDefined(val) && !isNumber(val)) {
22085 val = parseFloat(val, 10);
22087 maxVal = isNumber(val) && !isNaN(val) ? val : undefined;
22088 // TODO(matsko): implement validateLater to reduce number of validations
22094 function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) {
22095 // Note: no badInputChecker here by purpose as `url` is only a validation
22096 // in browsers, i.e. we can always read out input.value even if it is not valid!
22097 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
22098 stringBasedInputType(ctrl);
22100 ctrl.$$parserName = 'url';
22101 ctrl.$validators.url = function(modelValue, viewValue) {
22102 var value = modelValue || viewValue;
22103 return ctrl.$isEmpty(value) || URL_REGEXP.test(value);
22107 function emailInputType(scope, element, attr, ctrl, $sniffer, $browser) {
22108 // Note: no badInputChecker here by purpose as `url` is only a validation
22109 // in browsers, i.e. we can always read out input.value even if it is not valid!
22110 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
22111 stringBasedInputType(ctrl);
22113 ctrl.$$parserName = 'email';
22114 ctrl.$validators.email = function(modelValue, viewValue) {
22115 var value = modelValue || viewValue;
22116 return ctrl.$isEmpty(value) || EMAIL_REGEXP.test(value);
22120 function radioInputType(scope, element, attr, ctrl) {
22121 // make the name unique, if not defined
22122 if (isUndefined(attr.name)) {
22123 element.attr('name', nextUid());
22126 var listener = function(ev) {
22127 if (element[0].checked) {
22128 ctrl.$setViewValue(attr.value, ev && ev.type);
22132 element.on('click', listener);
22134 ctrl.$render = function() {
22135 var value = attr.value;
22136 element[0].checked = (value == ctrl.$viewValue);
22139 attr.$observe('value', ctrl.$render);
22142 function parseConstantExpr($parse, context, name, expression, fallback) {
22144 if (isDefined(expression)) {
22145 parseFn = $parse(expression);
22146 if (!parseFn.constant) {
22147 throw ngModelMinErr('constexpr', 'Expected constant expression for `{0}`, but saw ' +
22148 '`{1}`.', name, expression);
22150 return parseFn(context);
22155 function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) {
22156 var trueValue = parseConstantExpr($parse, scope, 'ngTrueValue', attr.ngTrueValue, true);
22157 var falseValue = parseConstantExpr($parse, scope, 'ngFalseValue', attr.ngFalseValue, false);
22159 var listener = function(ev) {
22160 ctrl.$setViewValue(element[0].checked, ev && ev.type);
22163 element.on('click', listener);
22165 ctrl.$render = function() {
22166 element[0].checked = ctrl.$viewValue;
22169 // Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false`
22170 // This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert
22171 // it to a boolean.
22172 ctrl.$isEmpty = function(value) {
22173 return value === false;
22176 ctrl.$formatters.push(function(value) {
22177 return equals(value, trueValue);
22180 ctrl.$parsers.push(function(value) {
22181 return value ? trueValue : falseValue;
22192 * HTML textarea element control with angular data-binding. The data-binding and validation
22193 * properties of this element are exactly the same as those of the
22194 * {@link ng.directive:input input element}.
22196 * @param {string} ngModel Assignable angular expression to data-bind to.
22197 * @param {string=} name Property name of the form under which the control is published.
22198 * @param {string=} required Sets `required` validation error key if the value is not entered.
22199 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
22200 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
22201 * `required` when you want to data-bind to the `required` attribute.
22202 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
22204 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
22205 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any
22207 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
22208 * a RegExp found by evaluating the Angular expression given in the attribute value.
22209 * If the expression evaluates to a RegExp object, then this is used directly.
22210 * If the expression evaluates to a string, then it will be converted to a RegExp
22211 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
22212 * `new RegExp('^abc$')`.<br />
22213 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
22214 * start at the index of the last search's match, thus not taking the whole input value into
22216 * @param {string=} ngChange Angular expression to be executed when input changes due to user
22217 * interaction with the input element.
22218 * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
22228 * HTML input element control. When used together with {@link ngModel `ngModel`}, it provides data-binding,
22229 * input state control, and validation.
22230 * Input control follows HTML5 input types and polyfills the HTML5 validation behavior for older browsers.
22232 * <div class="alert alert-warning">
22233 * **Note:** Not every feature offered is available for all input types.
22234 * Specifically, data binding and event handling via `ng-model` is unsupported for `input[file]`.
22237 * @param {string} ngModel Assignable angular expression to data-bind to.
22238 * @param {string=} name Property name of the form under which the control is published.
22239 * @param {string=} required Sets `required` validation error key if the value is not entered.
22240 * @param {boolean=} ngRequired Sets `required` attribute if set to true
22241 * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than
22243 * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
22244 * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any
22246 * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
22247 * a RegExp found by evaluating the Angular expression given in the attribute value.
22248 * If the expression evaluates to a RegExp object, then this is used directly.
22249 * If the expression evaluates to a string, then it will be converted to a RegExp
22250 * after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
22251 * `new RegExp('^abc$')`.<br />
22252 * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
22253 * start at the index of the last search's match, thus not taking the whole input value into
22255 * @param {string=} ngChange Angular expression to be executed when input changes due to user
22256 * interaction with the input element.
22257 * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
22258 * This parameter is ignored for input[type=password] controls, which will never trim the
22262 <example name="input-directive" module="inputExample">
22263 <file name="index.html">
22265 angular.module('inputExample', [])
22266 .controller('ExampleController', ['$scope', function($scope) {
22267 $scope.user = {name: 'guest', last: 'visitor'};
22270 <div ng-controller="ExampleController">
22271 <form name="myForm">
22274 <input type="text" name="userName" ng-model="user.name" required>
22277 <span class="error" ng-show="myForm.userName.$error.required">
22282 <input type="text" name="lastName" ng-model="user.last"
22283 ng-minlength="3" ng-maxlength="10">
22286 <span class="error" ng-show="myForm.lastName.$error.minlength">
22288 <span class="error" ng-show="myForm.lastName.$error.maxlength">
22293 <tt>user = {{user}}</tt><br/>
22294 <tt>myForm.userName.$valid = {{myForm.userName.$valid}}</tt><br/>
22295 <tt>myForm.userName.$error = {{myForm.userName.$error}}</tt><br/>
22296 <tt>myForm.lastName.$valid = {{myForm.lastName.$valid}}</tt><br/>
22297 <tt>myForm.lastName.$error = {{myForm.lastName.$error}}</tt><br/>
22298 <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
22299 <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
22300 <tt>myForm.$error.minlength = {{!!myForm.$error.minlength}}</tt><br/>
22301 <tt>myForm.$error.maxlength = {{!!myForm.$error.maxlength}}</tt><br/>
22304 <file name="protractor.js" type="protractor">
22305 var user = element(by.exactBinding('user'));
22306 var userNameValid = element(by.binding('myForm.userName.$valid'));
22307 var lastNameValid = element(by.binding('myForm.lastName.$valid'));
22308 var lastNameError = element(by.binding('myForm.lastName.$error'));
22309 var formValid = element(by.binding('myForm.$valid'));
22310 var userNameInput = element(by.model('user.name'));
22311 var userLastInput = element(by.model('user.last'));
22313 it('should initialize to model', function() {
22314 expect(user.getText()).toContain('{"name":"guest","last":"visitor"}');
22315 expect(userNameValid.getText()).toContain('true');
22316 expect(formValid.getText()).toContain('true');
22319 it('should be invalid if empty when required', function() {
22320 userNameInput.clear();
22321 userNameInput.sendKeys('');
22323 expect(user.getText()).toContain('{"last":"visitor"}');
22324 expect(userNameValid.getText()).toContain('false');
22325 expect(formValid.getText()).toContain('false');
22328 it('should be valid if empty when min length is set', function() {
22329 userLastInput.clear();
22330 userLastInput.sendKeys('');
22332 expect(user.getText()).toContain('{"name":"guest","last":""}');
22333 expect(lastNameValid.getText()).toContain('true');
22334 expect(formValid.getText()).toContain('true');
22337 it('should be invalid if less than required min length', function() {
22338 userLastInput.clear();
22339 userLastInput.sendKeys('xx');
22341 expect(user.getText()).toContain('{"name":"guest"}');
22342 expect(lastNameValid.getText()).toContain('false');
22343 expect(lastNameError.getText()).toContain('minlength');
22344 expect(formValid.getText()).toContain('false');
22347 it('should be invalid if longer than max length', function() {
22348 userLastInput.clear();
22349 userLastInput.sendKeys('some ridiculously long name');
22351 expect(user.getText()).toContain('{"name":"guest"}');
22352 expect(lastNameValid.getText()).toContain('false');
22353 expect(lastNameError.getText()).toContain('maxlength');
22354 expect(formValid.getText()).toContain('false');
22359 var inputDirective = ['$browser', '$sniffer', '$filter', '$parse',
22360 function($browser, $sniffer, $filter, $parse) {
22363 require: ['?ngModel'],
22365 pre: function(scope, element, attr, ctrls) {
22367 (inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrls[0], $sniffer,
22368 $browser, $filter, $parse);
22377 var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/;
22383 * Binds the given expression to the value of `<option>` or {@link input[radio] `input[radio]`},
22384 * so that when the element is selected, the {@link ngModel `ngModel`} of that element is set to
22387 * `ngValue` is useful when dynamically generating lists of radio buttons using
22388 * {@link ngRepeat `ngRepeat`}, as shown below.
22390 * Likewise, `ngValue` can be used to generate `<option>` elements for
22391 * the {@link select `select`} element. In that case however, only strings are supported
22392 * for the `value `attribute, so the resulting `ngModel` will always be a string.
22393 * Support for `select` models with non-string values is available via `ngOptions`.
22396 * @param {string=} ngValue angular expression, whose value will be bound to the `value` attribute
22397 * of the `input` element
22400 <example name="ngValue-directive" module="valueExample">
22401 <file name="index.html">
22403 angular.module('valueExample', [])
22404 .controller('ExampleController', ['$scope', function($scope) {
22405 $scope.names = ['pizza', 'unicorns', 'robots'];
22406 $scope.my = { favorite: 'unicorns' };
22409 <form ng-controller="ExampleController">
22410 <h2>Which is your favorite?</h2>
22411 <label ng-repeat="name in names" for="{{name}}">
22413 <input type="radio"
22414 ng-model="my.favorite"
22419 <div>You chose {{my.favorite}}</div>
22422 <file name="protractor.js" type="protractor">
22423 var favorite = element(by.binding('my.favorite'));
22425 it('should initialize to model', function() {
22426 expect(favorite.getText()).toContain('unicorns');
22428 it('should bind the values to the inputs', function() {
22429 element.all(by.model('my.favorite')).get(0).click();
22430 expect(favorite.getText()).toContain('pizza');
22435 var ngValueDirective = function() {
22439 compile: function(tpl, tplAttr) {
22440 if (CONSTANT_VALUE_REGEXP.test(tplAttr.ngValue)) {
22441 return function ngValueConstantLink(scope, elm, attr) {
22442 attr.$set('value', scope.$eval(attr.ngValue));
22445 return function ngValueLink(scope, elm, attr) {
22446 scope.$watch(attr.ngValue, function valueWatchAction(value) {
22447 attr.$set('value', value);
22461 * The `ngBind` attribute tells Angular to replace the text content of the specified HTML element
22462 * with the value of a given expression, and to update the text content when the value of that
22463 * expression changes.
22465 * Typically, you don't use `ngBind` directly, but instead you use the double curly markup like
22466 * `{{ expression }}` which is similar but less verbose.
22468 * It is preferable to use `ngBind` instead of `{{ expression }}` if a template is momentarily
22469 * displayed by the browser in its raw state before Angular compiles it. Since `ngBind` is an
22470 * element attribute, it makes the bindings invisible to the user while the page is loading.
22472 * An alternative solution to this problem would be using the
22473 * {@link ng.directive:ngCloak ngCloak} directive.
22477 * @param {expression} ngBind {@link guide/expression Expression} to evaluate.
22480 * Enter a name in the Live Preview text box; the greeting below the text box changes instantly.
22481 <example module="bindExample">
22482 <file name="index.html">
22484 angular.module('bindExample', [])
22485 .controller('ExampleController', ['$scope', function($scope) {
22486 $scope.name = 'Whirled';
22489 <div ng-controller="ExampleController">
22490 <label>Enter name: <input type="text" ng-model="name"></label><br>
22491 Hello <span ng-bind="name"></span>!
22494 <file name="protractor.js" type="protractor">
22495 it('should check ng-bind', function() {
22496 var nameInput = element(by.model('name'));
22498 expect(element(by.binding('name')).getText()).toBe('Whirled');
22500 nameInput.sendKeys('world');
22501 expect(element(by.binding('name')).getText()).toBe('world');
22506 var ngBindDirective = ['$compile', function($compile) {
22509 compile: function ngBindCompile(templateElement) {
22510 $compile.$$addBindingClass(templateElement);
22511 return function ngBindLink(scope, element, attr) {
22512 $compile.$$addBindingInfo(element, attr.ngBind);
22513 element = element[0];
22514 scope.$watch(attr.ngBind, function ngBindWatchAction(value) {
22515 element.textContent = isUndefined(value) ? '' : value;
22525 * @name ngBindTemplate
22528 * The `ngBindTemplate` directive specifies that the element
22529 * text content should be replaced with the interpolation of the template
22530 * in the `ngBindTemplate` attribute.
22531 * Unlike `ngBind`, the `ngBindTemplate` can contain multiple `{{` `}}`
22532 * expressions. This directive is needed since some HTML elements
22533 * (such as TITLE and OPTION) cannot contain SPAN elements.
22536 * @param {string} ngBindTemplate template of form
22537 * <tt>{{</tt> <tt>expression</tt> <tt>}}</tt> to eval.
22540 * Try it here: enter text in text box and watch the greeting change.
22541 <example module="bindExample">
22542 <file name="index.html">
22544 angular.module('bindExample', [])
22545 .controller('ExampleController', ['$scope', function($scope) {
22546 $scope.salutation = 'Hello';
22547 $scope.name = 'World';
22550 <div ng-controller="ExampleController">
22551 <label>Salutation: <input type="text" ng-model="salutation"></label><br>
22552 <label>Name: <input type="text" ng-model="name"></label><br>
22553 <pre ng-bind-template="{{salutation}} {{name}}!"></pre>
22556 <file name="protractor.js" type="protractor">
22557 it('should check ng-bind', function() {
22558 var salutationElem = element(by.binding('salutation'));
22559 var salutationInput = element(by.model('salutation'));
22560 var nameInput = element(by.model('name'));
22562 expect(salutationElem.getText()).toBe('Hello World!');
22564 salutationInput.clear();
22565 salutationInput.sendKeys('Greetings');
22567 nameInput.sendKeys('user');
22569 expect(salutationElem.getText()).toBe('Greetings user!');
22574 var ngBindTemplateDirective = ['$interpolate', '$compile', function($interpolate, $compile) {
22576 compile: function ngBindTemplateCompile(templateElement) {
22577 $compile.$$addBindingClass(templateElement);
22578 return function ngBindTemplateLink(scope, element, attr) {
22579 var interpolateFn = $interpolate(element.attr(attr.$attr.ngBindTemplate));
22580 $compile.$$addBindingInfo(element, interpolateFn.expressions);
22581 element = element[0];
22582 attr.$observe('ngBindTemplate', function(value) {
22583 element.textContent = isUndefined(value) ? '' : value;
22596 * Evaluates the expression and inserts the resulting HTML into the element in a secure way. By default,
22597 * the resulting HTML content will be sanitized using the {@link ngSanitize.$sanitize $sanitize} service.
22598 * To utilize this functionality, ensure that `$sanitize` is available, for example, by including {@link
22599 * ngSanitize} in your module's dependencies (not in core Angular). In order to use {@link ngSanitize}
22600 * in your module's dependencies, you need to include "angular-sanitize.js" in your application.
22602 * You may also bypass sanitization for values you know are safe. To do so, bind to
22603 * an explicitly trusted value via {@link ng.$sce#trustAsHtml $sce.trustAsHtml}. See the example
22604 * under {@link ng.$sce#show-me-an-example-using-sce- Strict Contextual Escaping (SCE)}.
22606 * Note: If a `$sanitize` service is unavailable and the bound value isn't explicitly trusted, you
22607 * will have an exception (instead of an exploit.)
22610 * @param {expression} ngBindHtml {@link guide/expression Expression} to evaluate.
22614 <example module="bindHtmlExample" deps="angular-sanitize.js">
22615 <file name="index.html">
22616 <div ng-controller="ExampleController">
22617 <p ng-bind-html="myHTML"></p>
22621 <file name="script.js">
22622 angular.module('bindHtmlExample', ['ngSanitize'])
22623 .controller('ExampleController', ['$scope', function($scope) {
22625 'I am an <code>HTML</code>string with ' +
22626 '<a href="#">links!</a> and other <em>stuff</em>';
22630 <file name="protractor.js" type="protractor">
22631 it('should check ng-bind-html', function() {
22632 expect(element(by.binding('myHTML')).getText()).toBe(
22633 'I am an HTMLstring with links! and other stuff');
22638 var ngBindHtmlDirective = ['$sce', '$parse', '$compile', function($sce, $parse, $compile) {
22641 compile: function ngBindHtmlCompile(tElement, tAttrs) {
22642 var ngBindHtmlGetter = $parse(tAttrs.ngBindHtml);
22643 var ngBindHtmlWatch = $parse(tAttrs.ngBindHtml, function getStringValue(value) {
22644 return (value || '').toString();
22646 $compile.$$addBindingClass(tElement);
22648 return function ngBindHtmlLink(scope, element, attr) {
22649 $compile.$$addBindingInfo(element, attr.ngBindHtml);
22651 scope.$watch(ngBindHtmlWatch, function ngBindHtmlWatchAction() {
22652 // we re-evaluate the expr because we want a TrustedValueHolderType
22653 // for $sce, not a string
22654 element.html($sce.getTrustedHtml(ngBindHtmlGetter(scope)) || '');
22666 * Evaluate the given expression when the user changes the input.
22667 * The expression is evaluated immediately, unlike the JavaScript onchange event
22668 * which only triggers at the end of a change (usually, when the user leaves the
22669 * form element or presses the return key).
22671 * The `ngChange` expression is only evaluated when a change in the input value causes
22672 * a new value to be committed to the model.
22674 * It will not be evaluated:
22675 * * if the value returned from the `$parsers` transformation pipeline has not changed
22676 * * if the input has continued to be invalid since the model will stay `null`
22677 * * if the model is changed programmatically and not by a change to the input value
22680 * Note, this directive requires `ngModel` to be present.
22683 * @param {expression} ngChange {@link guide/expression Expression} to evaluate upon change
22687 * <example name="ngChange-directive" module="changeExample">
22688 * <file name="index.html">
22690 * angular.module('changeExample', [])
22691 * .controller('ExampleController', ['$scope', function($scope) {
22692 * $scope.counter = 0;
22693 * $scope.change = function() {
22694 * $scope.counter++;
22698 * <div ng-controller="ExampleController">
22699 * <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" />
22700 * <input type="checkbox" ng-model="confirmed" id="ng-change-example2" />
22701 * <label for="ng-change-example2">Confirmed</label><br />
22702 * <tt>debug = {{confirmed}}</tt><br/>
22703 * <tt>counter = {{counter}}</tt><br/>
22706 * <file name="protractor.js" type="protractor">
22707 * var counter = element(by.binding('counter'));
22708 * var debug = element(by.binding('confirmed'));
22710 * it('should evaluate the expression if changing from view', function() {
22711 * expect(counter.getText()).toContain('0');
22713 * element(by.id('ng-change-example1')).click();
22715 * expect(counter.getText()).toContain('1');
22716 * expect(debug.getText()).toContain('true');
22719 * it('should not evaluate the expression if changing from model', function() {
22720 * element(by.id('ng-change-example2')).click();
22722 * expect(counter.getText()).toContain('0');
22723 * expect(debug.getText()).toContain('true');
22728 var ngChangeDirective = valueFn({
22730 require: 'ngModel',
22731 link: function(scope, element, attr, ctrl) {
22732 ctrl.$viewChangeListeners.push(function() {
22733 scope.$eval(attr.ngChange);
22738 function classDirective(name, selector) {
22739 name = 'ngClass' + name;
22740 return ['$animate', function($animate) {
22743 link: function(scope, element, attr) {
22746 scope.$watch(attr[name], ngClassWatchAction, true);
22748 attr.$observe('class', function(value) {
22749 ngClassWatchAction(scope.$eval(attr[name]));
22753 if (name !== 'ngClass') {
22754 scope.$watch('$index', function($index, old$index) {
22755 // jshint bitwise: false
22756 var mod = $index & 1;
22757 if (mod !== (old$index & 1)) {
22758 var classes = arrayClasses(scope.$eval(attr[name]));
22760 addClasses(classes) :
22761 removeClasses(classes);
22766 function addClasses(classes) {
22767 var newClasses = digestClassCounts(classes, 1);
22768 attr.$addClass(newClasses);
22771 function removeClasses(classes) {
22772 var newClasses = digestClassCounts(classes, -1);
22773 attr.$removeClass(newClasses);
22776 function digestClassCounts(classes, count) {
22777 // Use createMap() to prevent class assumptions involving property
22778 // names in Object.prototype
22779 var classCounts = element.data('$classCounts') || createMap();
22780 var classesToUpdate = [];
22781 forEach(classes, function(className) {
22782 if (count > 0 || classCounts[className]) {
22783 classCounts[className] = (classCounts[className] || 0) + count;
22784 if (classCounts[className] === +(count > 0)) {
22785 classesToUpdate.push(className);
22789 element.data('$classCounts', classCounts);
22790 return classesToUpdate.join(' ');
22793 function updateClasses(oldClasses, newClasses) {
22794 var toAdd = arrayDifference(newClasses, oldClasses);
22795 var toRemove = arrayDifference(oldClasses, newClasses);
22796 toAdd = digestClassCounts(toAdd, 1);
22797 toRemove = digestClassCounts(toRemove, -1);
22798 if (toAdd && toAdd.length) {
22799 $animate.addClass(element, toAdd);
22801 if (toRemove && toRemove.length) {
22802 $animate.removeClass(element, toRemove);
22806 function ngClassWatchAction(newVal) {
22807 if (selector === true || scope.$index % 2 === selector) {
22808 var newClasses = arrayClasses(newVal || []);
22810 addClasses(newClasses);
22811 } else if (!equals(newVal,oldVal)) {
22812 var oldClasses = arrayClasses(oldVal);
22813 updateClasses(oldClasses, newClasses);
22816 oldVal = shallowCopy(newVal);
22821 function arrayDifference(tokens1, tokens2) {
22825 for (var i = 0; i < tokens1.length; i++) {
22826 var token = tokens1[i];
22827 for (var j = 0; j < tokens2.length; j++) {
22828 if (token == tokens2[j]) continue outer;
22830 values.push(token);
22835 function arrayClasses(classVal) {
22837 if (isArray(classVal)) {
22838 forEach(classVal, function(v) {
22839 classes = classes.concat(arrayClasses(v));
22842 } else if (isString(classVal)) {
22843 return classVal.split(' ');
22844 } else if (isObject(classVal)) {
22845 forEach(classVal, function(v, k) {
22847 classes = classes.concat(k.split(' '));
22863 * The `ngClass` directive allows you to dynamically set CSS classes on an HTML element by databinding
22864 * an expression that represents all classes to be added.
22866 * The directive operates in three different ways, depending on which of three types the expression
22869 * 1. If the expression evaluates to a string, the string should be one or more space-delimited class
22872 * 2. If the expression evaluates to an object, then for each key-value pair of the
22873 * object with a truthy value the corresponding key is used as a class name.
22875 * 3. If the expression evaluates to an array, each element of the array should either be a string as in
22876 * type 1 or an object as in type 2. This means that you can mix strings and objects together in an array
22877 * to give you more control over what CSS classes appear. See the code below for an example of this.
22880 * The directive won't add duplicate classes if a particular class was already set.
22882 * When the expression changes, the previously added classes are removed and only then are the
22883 * new classes added.
22886 * **add** - happens just before the class is applied to the elements
22888 * **remove** - happens just before the class is removed from the element
22891 * @param {expression} ngClass {@link guide/expression Expression} to eval. The result
22892 * of the evaluation can be a string representing space delimited class
22893 * names, an array, or a map of class names to boolean values. In the case of a map, the
22894 * names of the properties whose values are truthy will be added as css classes to the
22897 * @example Example that demonstrates basic bindings via ngClass directive.
22899 <file name="index.html">
22900 <p ng-class="{strike: deleted, bold: important, 'has-error': error}">Map Syntax Example</p>
22902 <input type="checkbox" ng-model="deleted">
22903 deleted (apply "strike" class)
22906 <input type="checkbox" ng-model="important">
22907 important (apply "bold" class)
22910 <input type="checkbox" ng-model="error">
22911 error (apply "has-error" class)
22914 <p ng-class="style">Using String Syntax</p>
22915 <input type="text" ng-model="style"
22916 placeholder="Type: bold strike red" aria-label="Type: bold strike red">
22918 <p ng-class="[style1, style2, style3]">Using Array Syntax</p>
22919 <input ng-model="style1"
22920 placeholder="Type: bold, strike or red" aria-label="Type: bold, strike or red"><br>
22921 <input ng-model="style2"
22922 placeholder="Type: bold, strike or red" aria-label="Type: bold, strike or red 2"><br>
22923 <input ng-model="style3"
22924 placeholder="Type: bold, strike or red" aria-label="Type: bold, strike or red 3"><br>
22926 <p ng-class="[style4, {orange: warning}]">Using Array and Map Syntax</p>
22927 <input ng-model="style4" placeholder="Type: bold, strike" aria-label="Type: bold, strike"><br>
22928 <label><input type="checkbox" ng-model="warning"> warning (apply "orange" class)</label>
22930 <file name="style.css">
22932 text-decoration: line-through;
22942 background-color: yellow;
22948 <file name="protractor.js" type="protractor">
22949 var ps = element.all(by.css('p'));
22951 it('should let you toggle the class', function() {
22953 expect(ps.first().getAttribute('class')).not.toMatch(/bold/);
22954 expect(ps.first().getAttribute('class')).not.toMatch(/has-error/);
22956 element(by.model('important')).click();
22957 expect(ps.first().getAttribute('class')).toMatch(/bold/);
22959 element(by.model('error')).click();
22960 expect(ps.first().getAttribute('class')).toMatch(/has-error/);
22963 it('should let you toggle string example', function() {
22964 expect(ps.get(1).getAttribute('class')).toBe('');
22965 element(by.model('style')).clear();
22966 element(by.model('style')).sendKeys('red');
22967 expect(ps.get(1).getAttribute('class')).toBe('red');
22970 it('array example should have 3 classes', function() {
22971 expect(ps.get(2).getAttribute('class')).toBe('');
22972 element(by.model('style1')).sendKeys('bold');
22973 element(by.model('style2')).sendKeys('strike');
22974 element(by.model('style3')).sendKeys('red');
22975 expect(ps.get(2).getAttribute('class')).toBe('bold strike red');
22978 it('array with map example should have 2 classes', function() {
22979 expect(ps.last().getAttribute('class')).toBe('');
22980 element(by.model('style4')).sendKeys('bold');
22981 element(by.model('warning')).click();
22982 expect(ps.last().getAttribute('class')).toBe('bold orange');
22989 The example below demonstrates how to perform animations using ngClass.
22991 <example module="ngAnimate" deps="angular-animate.js" animations="true">
22992 <file name="index.html">
22993 <input id="setbtn" type="button" value="set" ng-click="myVar='my-class'">
22994 <input id="clearbtn" type="button" value="clear" ng-click="myVar=''">
22996 <span class="base-class" ng-class="myVar">Sample Text</span>
22998 <file name="style.css">
23000 transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
23003 .base-class.my-class {
23008 <file name="protractor.js" type="protractor">
23009 it('should check ng-class', function() {
23010 expect(element(by.css('.base-class')).getAttribute('class')).not.
23011 toMatch(/my-class/);
23013 element(by.id('setbtn')).click();
23015 expect(element(by.css('.base-class')).getAttribute('class')).
23016 toMatch(/my-class/);
23018 element(by.id('clearbtn')).click();
23020 expect(element(by.css('.base-class')).getAttribute('class')).not.
23021 toMatch(/my-class/);
23027 ## ngClass and pre-existing CSS3 Transitions/Animations
23028 The ngClass directive still supports CSS3 Transitions/Animations even if they do not follow the ngAnimate CSS naming structure.
23029 Upon animation ngAnimate will apply supplementary CSS classes to track the start and end of an animation, but this will not hinder
23030 any pre-existing CSS transitions already on the element. To get an idea of what happens during a class-based animation, be sure
23031 to view the step by step details of {@link $animate#addClass $animate.addClass} and
23032 {@link $animate#removeClass $animate.removeClass}.
23034 var ngClassDirective = classDirective('', true);
23042 * The `ngClassOdd` and `ngClassEven` directives work exactly as
23043 * {@link ng.directive:ngClass ngClass}, except they work in
23044 * conjunction with `ngRepeat` and take effect only on odd (even) rows.
23046 * This directive can be applied only within the scope of an
23047 * {@link ng.directive:ngRepeat ngRepeat}.
23050 * @param {expression} ngClassOdd {@link guide/expression Expression} to eval. The result
23051 * of the evaluation can be a string representing space delimited class names or an array.
23055 <file name="index.html">
23056 <ol ng-init="names=['John', 'Mary', 'Cate', 'Suz']">
23057 <li ng-repeat="name in names">
23058 <span ng-class-odd="'odd'" ng-class-even="'even'">
23064 <file name="style.css">
23072 <file name="protractor.js" type="protractor">
23073 it('should check ng-class-odd and ng-class-even', function() {
23074 expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')).
23076 expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')).
23082 var ngClassOddDirective = classDirective('Odd', 0);
23086 * @name ngClassEven
23090 * The `ngClassOdd` and `ngClassEven` directives work exactly as
23091 * {@link ng.directive:ngClass ngClass}, except they work in
23092 * conjunction with `ngRepeat` and take effect only on odd (even) rows.
23094 * This directive can be applied only within the scope of an
23095 * {@link ng.directive:ngRepeat ngRepeat}.
23098 * @param {expression} ngClassEven {@link guide/expression Expression} to eval. The
23099 * result of the evaluation can be a string representing space delimited class names or an array.
23103 <file name="index.html">
23104 <ol ng-init="names=['John', 'Mary', 'Cate', 'Suz']">
23105 <li ng-repeat="name in names">
23106 <span ng-class-odd="'odd'" ng-class-even="'even'">
23107 {{name}}
23112 <file name="style.css">
23120 <file name="protractor.js" type="protractor">
23121 it('should check ng-class-odd and ng-class-even', function() {
23122 expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')).
23124 expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')).
23130 var ngClassEvenDirective = classDirective('Even', 1);
23138 * The `ngCloak` directive is used to prevent the Angular html template from being briefly
23139 * displayed by the browser in its raw (uncompiled) form while your application is loading. Use this
23140 * directive to avoid the undesirable flicker effect caused by the html template display.
23142 * The directive can be applied to the `<body>` element, but the preferred usage is to apply
23143 * multiple `ngCloak` directives to small portions of the page to permit progressive rendering
23144 * of the browser view.
23146 * `ngCloak` works in cooperation with the following css rule embedded within `angular.js` and
23147 * `angular.min.js`.
23148 * For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
23151 * [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
23152 * display: none !important;
23156 * When this css rule is loaded by the browser, all html elements (including their children) that
23157 * are tagged with the `ngCloak` directive are hidden. When Angular encounters this directive
23158 * during the compilation of the template it deletes the `ngCloak` element attribute, making
23159 * the compiled element visible.
23161 * For the best result, the `angular.js` script must be loaded in the head section of the html
23162 * document; alternatively, the css rule above must be included in the external stylesheet of the
23169 <file name="index.html">
23170 <div id="template1" ng-cloak>{{ 'hello' }}</div>
23171 <div id="template2" class="ng-cloak">{{ 'world' }}</div>
23173 <file name="protractor.js" type="protractor">
23174 it('should remove the template directive and css class', function() {
23175 expect($('#template1').getAttribute('ng-cloak')).
23177 expect($('#template2').getAttribute('ng-cloak')).
23184 var ngCloakDirective = ngDirective({
23185 compile: function(element, attr) {
23186 attr.$set('ngCloak', undefined);
23187 element.removeClass('ng-cloak');
23193 * @name ngController
23196 * The `ngController` directive attaches a controller class to the view. This is a key aspect of how angular
23197 * supports the principles behind the Model-View-Controller design pattern.
23199 * MVC components in angular:
23201 * * Model — Models are the properties of a scope; scopes are attached to the DOM where scope properties
23202 * are accessed through bindings.
23203 * * View — The template (HTML with data bindings) that is rendered into the View.
23204 * * Controller — The `ngController` directive specifies a Controller class; the class contains business
23205 * logic behind the application to decorate the scope with functions and values
23207 * Note that you can also attach controllers to the DOM by declaring it in a route definition
23208 * via the {@link ngRoute.$route $route} service. A common mistake is to declare the controller
23209 * again using `ng-controller` in the template itself. This will cause the controller to be attached
23210 * and executed twice.
23215 * @param {expression} ngController Name of a constructor function registered with the current
23216 * {@link ng.$controllerProvider $controllerProvider} or an {@link guide/expression expression}
23217 * that on the current scope evaluates to a constructor function.
23219 * The controller instance can be published into a scope property by specifying
23220 * `ng-controller="as propertyName"`.
23222 * If the current `$controllerProvider` is configured to use globals (via
23223 * {@link ng.$controllerProvider#allowGlobals `$controllerProvider.allowGlobals()` }), this may
23224 * also be the name of a globally accessible constructor function (not recommended).
23227 * Here is a simple form for editing user contact information. Adding, removing, clearing, and
23228 * greeting are methods declared on the controller (see source tab). These methods can
23229 * easily be called from the angular markup. Any changes to the data are automatically reflected
23230 * in the View without the need for a manual update.
23232 * Two different declaration styles are included below:
23234 * * one binds methods and properties directly onto the controller using `this`:
23235 * `ng-controller="SettingsController1 as settings"`
23236 * * one injects `$scope` into the controller:
23237 * `ng-controller="SettingsController2"`
23239 * The second option is more common in the Angular community, and is generally used in boilerplates
23240 * and in this guide. However, there are advantages to binding properties directly to the controller
23241 * and avoiding scope.
23243 * * Using `controller as` makes it obvious which controller you are accessing in the template when
23244 * multiple controllers apply to an element.
23245 * * If you are writing your controllers as classes you have easier access to the properties and
23246 * methods, which will appear on the scope, from inside the controller code.
23247 * * Since there is always a `.` in the bindings, you don't have to worry about prototypal
23248 * inheritance masking primitives.
23250 * This example demonstrates the `controller as` syntax.
23252 * <example name="ngControllerAs" module="controllerAsExample">
23253 * <file name="index.html">
23254 * <div id="ctrl-as-exmpl" ng-controller="SettingsController1 as settings">
23255 * <label>Name: <input type="text" ng-model="settings.name"/></label>
23256 * <button ng-click="settings.greet()">greet</button><br/>
23259 * <li ng-repeat="contact in settings.contacts">
23260 * <select ng-model="contact.type" aria-label="Contact method" id="select_{{$index}}">
23261 * <option>phone</option>
23262 * <option>email</option>
23264 * <input type="text" ng-model="contact.value" aria-labelledby="select_{{$index}}" />
23265 * <button ng-click="settings.clearContact(contact)">clear</button>
23266 * <button ng-click="settings.removeContact(contact)" aria-label="Remove">X</button>
23268 * <li><button ng-click="settings.addContact()">add</button></li>
23272 * <file name="app.js">
23273 * angular.module('controllerAsExample', [])
23274 * .controller('SettingsController1', SettingsController1);
23276 * function SettingsController1() {
23277 * this.name = "John Smith";
23278 * this.contacts = [
23279 * {type: 'phone', value: '408 555 1212'},
23280 * {type: 'email', value: 'john.smith@example.org'} ];
23283 * SettingsController1.prototype.greet = function() {
23284 * alert(this.name);
23287 * SettingsController1.prototype.addContact = function() {
23288 * this.contacts.push({type: 'email', value: 'yourname@example.org'});
23291 * SettingsController1.prototype.removeContact = function(contactToRemove) {
23292 * var index = this.contacts.indexOf(contactToRemove);
23293 * this.contacts.splice(index, 1);
23296 * SettingsController1.prototype.clearContact = function(contact) {
23297 * contact.type = 'phone';
23298 * contact.value = '';
23301 * <file name="protractor.js" type="protractor">
23302 * it('should check controller as', function() {
23303 * var container = element(by.id('ctrl-as-exmpl'));
23304 * expect(container.element(by.model('settings.name'))
23305 * .getAttribute('value')).toBe('John Smith');
23307 * var firstRepeat =
23308 * container.element(by.repeater('contact in settings.contacts').row(0));
23309 * var secondRepeat =
23310 * container.element(by.repeater('contact in settings.contacts').row(1));
23312 * expect(firstRepeat.element(by.model('contact.value')).getAttribute('value'))
23313 * .toBe('408 555 1212');
23315 * expect(secondRepeat.element(by.model('contact.value')).getAttribute('value'))
23316 * .toBe('john.smith@example.org');
23318 * firstRepeat.element(by.buttonText('clear')).click();
23320 * expect(firstRepeat.element(by.model('contact.value')).getAttribute('value'))
23323 * container.element(by.buttonText('add')).click();
23325 * expect(container.element(by.repeater('contact in settings.contacts').row(2))
23326 * .element(by.model('contact.value'))
23327 * .getAttribute('value'))
23328 * .toBe('yourname@example.org');
23333 * This example demonstrates the "attach to `$scope`" style of controller.
23335 * <example name="ngController" module="controllerExample">
23336 * <file name="index.html">
23337 * <div id="ctrl-exmpl" ng-controller="SettingsController2">
23338 * <label>Name: <input type="text" ng-model="name"/></label>
23339 * <button ng-click="greet()">greet</button><br/>
23342 * <li ng-repeat="contact in contacts">
23343 * <select ng-model="contact.type" id="select_{{$index}}">
23344 * <option>phone</option>
23345 * <option>email</option>
23347 * <input type="text" ng-model="contact.value" aria-labelledby="select_{{$index}}" />
23348 * <button ng-click="clearContact(contact)">clear</button>
23349 * <button ng-click="removeContact(contact)">X</button>
23351 * <li>[ <button ng-click="addContact()">add</button> ]</li>
23355 * <file name="app.js">
23356 * angular.module('controllerExample', [])
23357 * .controller('SettingsController2', ['$scope', SettingsController2]);
23359 * function SettingsController2($scope) {
23360 * $scope.name = "John Smith";
23361 * $scope.contacts = [
23362 * {type:'phone', value:'408 555 1212'},
23363 * {type:'email', value:'john.smith@example.org'} ];
23365 * $scope.greet = function() {
23366 * alert($scope.name);
23369 * $scope.addContact = function() {
23370 * $scope.contacts.push({type:'email', value:'yourname@example.org'});
23373 * $scope.removeContact = function(contactToRemove) {
23374 * var index = $scope.contacts.indexOf(contactToRemove);
23375 * $scope.contacts.splice(index, 1);
23378 * $scope.clearContact = function(contact) {
23379 * contact.type = 'phone';
23380 * contact.value = '';
23384 * <file name="protractor.js" type="protractor">
23385 * it('should check controller', function() {
23386 * var container = element(by.id('ctrl-exmpl'));
23388 * expect(container.element(by.model('name'))
23389 * .getAttribute('value')).toBe('John Smith');
23391 * var firstRepeat =
23392 * container.element(by.repeater('contact in contacts').row(0));
23393 * var secondRepeat =
23394 * container.element(by.repeater('contact in contacts').row(1));
23396 * expect(firstRepeat.element(by.model('contact.value')).getAttribute('value'))
23397 * .toBe('408 555 1212');
23398 * expect(secondRepeat.element(by.model('contact.value')).getAttribute('value'))
23399 * .toBe('john.smith@example.org');
23401 * firstRepeat.element(by.buttonText('clear')).click();
23403 * expect(firstRepeat.element(by.model('contact.value')).getAttribute('value'))
23406 * container.element(by.buttonText('add')).click();
23408 * expect(container.element(by.repeater('contact in contacts').row(2))
23409 * .element(by.model('contact.value'))
23410 * .getAttribute('value'))
23411 * .toBe('yourname@example.org');
23417 var ngControllerDirective = [function() {
23433 * Angular has some features that can break certain
23434 * [CSP (Content Security Policy)](https://developer.mozilla.org/en/Security/CSP) rules.
23436 * If you intend to implement these rules then you must tell Angular not to use these features.
23438 * This is necessary when developing things like Google Chrome Extensions or Universal Windows Apps.
23441 * The following rules affect Angular:
23443 * * `unsafe-eval`: this rule forbids apps to use `eval` or `Function(string)` generated functions
23444 * (among other things). Angular makes use of this in the {@link $parse} service to provide a 30%
23445 * increase in the speed of evaluating Angular expressions.
23447 * * `unsafe-inline`: this rule forbids apps from inject custom styles into the document. Angular
23448 * makes use of this to include some CSS rules (e.g. {@link ngCloak} and {@link ngHide}).
23449 * To make these directives work when a CSP rule is blocking inline styles, you must link to the
23450 * `angular-csp.css` in your HTML manually.
23452 * If you do not provide `ngCsp` then Angular tries to autodetect if CSP is blocking unsafe-eval
23453 * and automatically deactivates this feature in the {@link $parse} service. This autodetection,
23454 * however, triggers a CSP error to be logged in the console:
23457 * Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of
23458 * script in the following Content Security Policy directive: "default-src 'self'". Note that
23459 * 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
23462 * This error is harmless but annoying. To prevent the error from showing up, put the `ngCsp`
23463 * directive on an element of the HTML document that appears before the `<script>` tag that loads
23464 * the `angular.js` file.
23466 * *Note: This directive is only available in the `ng-csp` and `data-ng-csp` attribute form.*
23468 * You can specify which of the CSP related Angular features should be deactivated by providing
23469 * a value for the `ng-csp` attribute. The options are as follows:
23471 * * no-inline-style: this stops Angular from injecting CSS styles into the DOM
23473 * * no-unsafe-eval: this stops Angular from optimising $parse with unsafe eval of strings
23475 * You can use these values in the following combinations:
23478 * * No declaration means that Angular will assume that you can do inline styles, but it will do
23479 * a runtime check for unsafe-eval. E.g. `<body>`. This is backwardly compatible with previous versions
23482 * * A simple `ng-csp` (or `data-ng-csp`) attribute will tell Angular to deactivate both inline
23483 * styles and unsafe eval. E.g. `<body ng-csp>`. This is backwardly compatible with previous versions
23486 * * Specifying only `no-unsafe-eval` tells Angular that we must not use eval, but that we can inject
23487 * inline styles. E.g. `<body ng-csp="no-unsafe-eval">`.
23489 * * Specifying only `no-inline-style` tells Angular that we must not inject styles, but that we can
23490 * run eval - no automcatic check for unsafe eval will occur. E.g. `<body ng-csp="no-inline-style">`
23492 * * Specifying both `no-unsafe-eval` and `no-inline-style` tells Angular that we must not inject
23493 * styles nor use eval, which is the same as an empty: ng-csp.
23494 * E.g.`<body ng-csp="no-inline-style;no-unsafe-eval">`
23497 * This example shows how to apply the `ngCsp` directive to the `html` tag.
23500 <html ng-app ng-csp>
23506 // Note: the suffix `.csp` in the example name triggers
23507 // csp mode in our http server!
23508 <example name="example.csp" module="cspExample" ng-csp="true">
23509 <file name="index.html">
23510 <div ng-controller="MainController as ctrl">
23512 <button ng-click="ctrl.inc()" id="inc">Increment</button>
23513 <span id="counter">
23519 <button ng-click="ctrl.evil()" id="evil">Evil</button>
23520 <span id="evilError">
23526 <file name="script.js">
23527 angular.module('cspExample', [])
23528 .controller('MainController', function() {
23530 this.inc = function() {
23533 this.evil = function() {
23534 // jshint evil:true
23538 this.evilError = e.message;
23543 <file name="protractor.js" type="protractor">
23544 var util, webdriver;
23546 var incBtn = element(by.id('inc'));
23547 var counter = element(by.id('counter'));
23548 var evilBtn = element(by.id('evil'));
23549 var evilError = element(by.id('evilError'));
23551 function getAndClearSevereErrors() {
23552 return browser.manage().logs().get('browser').then(function(browserLog) {
23553 return browserLog.filter(function(logEntry) {
23554 return logEntry.level.value > webdriver.logging.Level.WARNING.value;
23559 function clearErrors() {
23560 getAndClearSevereErrors();
23563 function expectNoErrors() {
23564 getAndClearSevereErrors().then(function(filteredLog) {
23565 expect(filteredLog.length).toEqual(0);
23566 if (filteredLog.length) {
23567 console.log('browser console errors: ' + util.inspect(filteredLog));
23572 function expectError(regex) {
23573 getAndClearSevereErrors().then(function(filteredLog) {
23575 filteredLog.forEach(function(log) {
23576 if (log.message.match(regex)) {
23581 throw new Error('expected an error that matches ' + regex);
23586 beforeEach(function() {
23587 util = require('util');
23588 webdriver = require('protractor/node_modules/selenium-webdriver');
23591 // For now, we only test on Chrome,
23592 // as Safari does not load the page with Protractor's injected scripts,
23593 // and Firefox webdriver always disables content security policy (#6358)
23594 if (browser.params.browser !== 'chrome') {
23598 it('should not report errors when the page is loaded', function() {
23599 // clear errors so we are not dependent on previous tests
23601 // Need to reload the page as the page is already loaded when
23603 browser.driver.getCurrentUrl().then(function(url) {
23609 it('should evaluate expressions', function() {
23610 expect(counter.getText()).toEqual('0');
23612 expect(counter.getText()).toEqual('1');
23616 it('should throw and report an error when using "eval"', function() {
23618 expect(evilError.getText()).toMatch(/Content Security Policy/);
23619 expectError(/Content Security Policy/);
23625 // ngCsp is not implemented as a proper directive any more, because we need it be processed while we
23626 // bootstrap the system (before $parse is instantiated), for this reason we just have
23627 // the csp() fn that looks for the `ng-csp` attribute anywhere in the current doc
23634 * The ngClick directive allows you to specify custom behavior when
23635 * an element is clicked.
23639 * @param {expression} ngClick {@link guide/expression Expression} to evaluate upon
23640 * click. ({@link guide/expression#-event- Event object is available as `$event`})
23644 <file name="index.html">
23645 <button ng-click="count = count + 1" ng-init="count=0">
23652 <file name="protractor.js" type="protractor">
23653 it('should check ng-click', function() {
23654 expect(element(by.binding('count')).getText()).toMatch('0');
23655 element(by.css('button')).click();
23656 expect(element(by.binding('count')).getText()).toMatch('1');
23662 * A collection of directives that allows creation of custom event handlers that are defined as
23663 * angular expressions and are compiled and executed within the current scope.
23665 var ngEventDirectives = {};
23667 // For events that might fire synchronously during DOM manipulation
23668 // we need to execute their event handlers asynchronously using $evalAsync,
23669 // so that they are not executed in an inconsistent state.
23670 var forceAsyncEvents = {
23675 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit focus blur copy cut paste'.split(' '),
23676 function(eventName) {
23677 var directiveName = directiveNormalize('ng-' + eventName);
23678 ngEventDirectives[directiveName] = ['$parse', '$rootScope', function($parse, $rootScope) {
23681 compile: function($element, attr) {
23682 // We expose the powerful $event object on the scope that provides access to the Window,
23683 // etc. that isn't protected by the fast paths in $parse. We explicitly request better
23684 // checks at the cost of speed since event handler expressions are not executed as
23685 // frequently as regular change detection.
23686 var fn = $parse(attr[directiveName], /* interceptorFn */ null, /* expensiveChecks */ true);
23687 return function ngEventHandler(scope, element) {
23688 element.on(eventName, function(event) {
23689 var callback = function() {
23690 fn(scope, {$event:event});
23692 if (forceAsyncEvents[eventName] && $rootScope.$$phase) {
23693 scope.$evalAsync(callback);
23695 scope.$apply(callback);
23710 * The `ngDblclick` directive allows you to specify custom behavior on a dblclick event.
23714 * @param {expression} ngDblclick {@link guide/expression Expression} to evaluate upon
23715 * a dblclick. (The Event object is available as `$event`)
23719 <file name="index.html">
23720 <button ng-dblclick="count = count + 1" ng-init="count=0">
23721 Increment (on double click)
23731 * @name ngMousedown
23734 * The ngMousedown directive allows you to specify custom behavior on mousedown event.
23738 * @param {expression} ngMousedown {@link guide/expression Expression} to evaluate upon
23739 * mousedown. ({@link guide/expression#-event- Event object is available as `$event`})
23743 <file name="index.html">
23744 <button ng-mousedown="count = count + 1" ng-init="count=0">
23745 Increment (on mouse down)
23758 * Specify custom behavior on mouseup event.
23762 * @param {expression} ngMouseup {@link guide/expression Expression} to evaluate upon
23763 * mouseup. ({@link guide/expression#-event- Event object is available as `$event`})
23767 <file name="index.html">
23768 <button ng-mouseup="count = count + 1" ng-init="count=0">
23769 Increment (on mouse up)
23778 * @name ngMouseover
23781 * Specify custom behavior on mouseover event.
23785 * @param {expression} ngMouseover {@link guide/expression Expression} to evaluate upon
23786 * mouseover. ({@link guide/expression#-event- Event object is available as `$event`})
23790 <file name="index.html">
23791 <button ng-mouseover="count = count + 1" ng-init="count=0">
23792 Increment (when mouse is over)
23802 * @name ngMouseenter
23805 * Specify custom behavior on mouseenter event.
23809 * @param {expression} ngMouseenter {@link guide/expression Expression} to evaluate upon
23810 * mouseenter. ({@link guide/expression#-event- Event object is available as `$event`})
23814 <file name="index.html">
23815 <button ng-mouseenter="count = count + 1" ng-init="count=0">
23816 Increment (when mouse enters)
23826 * @name ngMouseleave
23829 * Specify custom behavior on mouseleave event.
23833 * @param {expression} ngMouseleave {@link guide/expression Expression} to evaluate upon
23834 * mouseleave. ({@link guide/expression#-event- Event object is available as `$event`})
23838 <file name="index.html">
23839 <button ng-mouseleave="count = count + 1" ng-init="count=0">
23840 Increment (when mouse leaves)
23850 * @name ngMousemove
23853 * Specify custom behavior on mousemove event.
23857 * @param {expression} ngMousemove {@link guide/expression Expression} to evaluate upon
23858 * mousemove. ({@link guide/expression#-event- Event object is available as `$event`})
23862 <file name="index.html">
23863 <button ng-mousemove="count = count + 1" ng-init="count=0">
23864 Increment (when mouse moves)
23877 * Specify custom behavior on keydown event.
23881 * @param {expression} ngKeydown {@link guide/expression Expression} to evaluate upon
23882 * keydown. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
23886 <file name="index.html">
23887 <input ng-keydown="count = count + 1" ng-init="count=0">
23888 key down count: {{count}}
23899 * Specify custom behavior on keyup event.
23903 * @param {expression} ngKeyup {@link guide/expression Expression} to evaluate upon
23904 * keyup. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
23908 <file name="index.html">
23909 <p>Typing in the input box below updates the key count</p>
23910 <input ng-keyup="count = count + 1" ng-init="count=0"> key up count: {{count}}
23912 <p>Typing in the input box below updates the keycode</p>
23913 <input ng-keyup="event=$event">
23914 <p>event keyCode: {{ event.keyCode }}</p>
23915 <p>event altKey: {{ event.altKey }}</p>
23926 * Specify custom behavior on keypress event.
23929 * @param {expression} ngKeypress {@link guide/expression Expression} to evaluate upon
23930 * keypress. ({@link guide/expression#-event- Event object is available as `$event`}
23931 * and can be interrogated for keyCode, altKey, etc.)
23935 <file name="index.html">
23936 <input ng-keypress="count = count + 1" ng-init="count=0">
23937 key press count: {{count}}
23948 * Enables binding angular expressions to onsubmit events.
23950 * Additionally it prevents the default action (which for form means sending the request to the
23951 * server and reloading the current page), but only if the form does not contain `action`,
23952 * `data-action`, or `x-action` attributes.
23954 * <div class="alert alert-warning">
23955 * **Warning:** Be careful not to cause "double-submission" by using both the `ngClick` and
23956 * `ngSubmit` handlers together. See the
23957 * {@link form#submitting-a-form-and-preventing-the-default-action `form` directive documentation}
23958 * for a detailed discussion of when `ngSubmit` may be triggered.
23963 * @param {expression} ngSubmit {@link guide/expression Expression} to eval.
23964 * ({@link guide/expression#-event- Event object is available as `$event`})
23967 <example module="submitExample">
23968 <file name="index.html">
23970 angular.module('submitExample', [])
23971 .controller('ExampleController', ['$scope', function($scope) {
23973 $scope.text = 'hello';
23974 $scope.submit = function() {
23976 $scope.list.push(this.text);
23982 <form ng-submit="submit()" ng-controller="ExampleController">
23983 Enter text and hit enter:
23984 <input type="text" ng-model="text" name="text" />
23985 <input type="submit" id="submit" value="Submit" />
23986 <pre>list={{list}}</pre>
23989 <file name="protractor.js" type="protractor">
23990 it('should check ng-submit', function() {
23991 expect(element(by.binding('list')).getText()).toBe('list=[]');
23992 element(by.css('#submit')).click();
23993 expect(element(by.binding('list')).getText()).toContain('hello');
23994 expect(element(by.model('text')).getAttribute('value')).toBe('');
23996 it('should ignore empty strings', function() {
23997 expect(element(by.binding('list')).getText()).toBe('list=[]');
23998 element(by.css('#submit')).click();
23999 element(by.css('#submit')).click();
24000 expect(element(by.binding('list')).getText()).toContain('hello');
24011 * Specify custom behavior on focus event.
24013 * Note: As the `focus` event is executed synchronously when calling `input.focus()`
24014 * AngularJS executes the expression using `scope.$evalAsync` if the event is fired
24015 * during an `$apply` to ensure a consistent state.
24017 * @element window, input, select, textarea, a
24019 * @param {expression} ngFocus {@link guide/expression Expression} to evaluate upon
24020 * focus. ({@link guide/expression#-event- Event object is available as `$event`})
24023 * See {@link ng.directive:ngClick ngClick}
24031 * Specify custom behavior on blur event.
24033 * A [blur event](https://developer.mozilla.org/en-US/docs/Web/Events/blur) fires when
24034 * an element has lost focus.
24036 * Note: As the `blur` event is executed synchronously also during DOM manipulations
24037 * (e.g. removing a focussed input),
24038 * AngularJS executes the expression using `scope.$evalAsync` if the event is fired
24039 * during an `$apply` to ensure a consistent state.
24041 * @element window, input, select, textarea, a
24043 * @param {expression} ngBlur {@link guide/expression Expression} to evaluate upon
24044 * blur. ({@link guide/expression#-event- Event object is available as `$event`})
24047 * See {@link ng.directive:ngClick ngClick}
24055 * Specify custom behavior on copy event.
24057 * @element window, input, select, textarea, a
24059 * @param {expression} ngCopy {@link guide/expression Expression} to evaluate upon
24060 * copy. ({@link guide/expression#-event- Event object is available as `$event`})
24064 <file name="index.html">
24065 <input ng-copy="copied=true" ng-init="copied=false; value='copy me'" ng-model="value">
24076 * Specify custom behavior on cut event.
24078 * @element window, input, select, textarea, a
24080 * @param {expression} ngCut {@link guide/expression Expression} to evaluate upon
24081 * cut. ({@link guide/expression#-event- Event object is available as `$event`})
24085 <file name="index.html">
24086 <input ng-cut="cut=true" ng-init="cut=false; value='cut me'" ng-model="value">
24097 * Specify custom behavior on paste event.
24099 * @element window, input, select, textarea, a
24101 * @param {expression} ngPaste {@link guide/expression Expression} to evaluate upon
24102 * paste. ({@link guide/expression#-event- Event object is available as `$event`})
24106 <file name="index.html">
24107 <input ng-paste="paste=true" ng-init="paste=false" placeholder='paste here'>
24120 * The `ngIf` directive removes or recreates a portion of the DOM tree based on an
24121 * {expression}. If the expression assigned to `ngIf` evaluates to a false
24122 * value then the element is removed from the DOM, otherwise a clone of the
24123 * element is reinserted into the DOM.
24125 * `ngIf` differs from `ngShow` and `ngHide` in that `ngIf` completely removes and recreates the
24126 * element in the DOM rather than changing its visibility via the `display` css property. A common
24127 * case when this difference is significant is when using css selectors that rely on an element's
24128 * position within the DOM, such as the `:first-child` or `:last-child` pseudo-classes.
24130 * Note that when an element is removed using `ngIf` its scope is destroyed and a new scope
24131 * is created when the element is restored. The scope created within `ngIf` inherits from
24132 * its parent scope using
24133 * [prototypal inheritance](https://github.com/angular/angular.js/wiki/Understanding-Scopes#javascript-prototypal-inheritance).
24134 * An important implication of this is if `ngModel` is used within `ngIf` to bind to
24135 * a javascript primitive defined in the parent scope. In this case any modifications made to the
24136 * variable within the child scope will override (hide) the value in the parent scope.
24138 * Also, `ngIf` recreates elements using their compiled state. An example of this behavior
24139 * is if an element's class attribute is directly modified after it's compiled, using something like
24140 * jQuery's `.addClass()` method, and the element is later removed. When `ngIf` recreates the element
24141 * the added class will be lost because the original compiled state is used to regenerate the element.
24143 * Additionally, you can provide animations via the `ngAnimate` module to animate the `enter`
24144 * and `leave` effects.
24147 * enter - happens just after the `ngIf` contents change and a new DOM element is created and injected into the `ngIf` container
24148 * leave - happens just before the `ngIf` contents are removed from the DOM
24153 * @param {expression} ngIf If the {@link guide/expression expression} is falsy then
24154 * the element is removed from the DOM tree. If it is truthy a copy of the compiled
24155 * element is added to the DOM tree.
24158 <example module="ngAnimate" deps="angular-animate.js" animations="true">
24159 <file name="index.html">
24160 <label>Click me: <input type="checkbox" ng-model="checked" ng-init="checked=true" /></label><br/>
24162 <span ng-if="checked" class="animate-if">
24163 This is removed when the checkbox is unchecked.
24166 <file name="animations.css">
24169 border:1px solid black;
24173 .animate-if.ng-enter, .animate-if.ng-leave {
24174 transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
24177 .animate-if.ng-enter,
24178 .animate-if.ng-leave.ng-leave-active {
24182 .animate-if.ng-leave,
24183 .animate-if.ng-enter.ng-enter-active {
24189 var ngIfDirective = ['$animate', function($animate) {
24191 multiElement: true,
24192 transclude: 'element',
24197 link: function($scope, $element, $attr, ctrl, $transclude) {
24198 var block, childScope, previousElements;
24199 $scope.$watch($attr.ngIf, function ngIfWatchAction(value) {
24203 $transclude(function(clone, newScope) {
24204 childScope = newScope;
24205 clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
24206 // Note: We only need the first/last node of the cloned nodes.
24207 // However, we need to keep the reference to the jqlite wrapper as it might be changed later
24208 // by a directive with templateUrl when its template arrives.
24212 $animate.enter(clone, $element.parent(), $element);
24216 if (previousElements) {
24217 previousElements.remove();
24218 previousElements = null;
24221 childScope.$destroy();
24225 previousElements = getBlockNodes(block.clone);
24226 $animate.leave(previousElements).then(function() {
24227 previousElements = null;
24243 * Fetches, compiles and includes an external HTML fragment.
24245 * By default, the template URL is restricted to the same domain and protocol as the
24246 * application document. This is done by calling {@link $sce#getTrustedResourceUrl
24247 * $sce.getTrustedResourceUrl} on it. To load templates from other domains or protocols
24248 * you may either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist them} or
24249 * {@link $sce#trustAsResourceUrl wrap them} as trusted values. Refer to Angular's {@link
24250 * ng.$sce Strict Contextual Escaping}.
24252 * In addition, the browser's
24253 * [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest)
24254 * and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/)
24255 * policy may further restrict whether the template is successfully loaded.
24256 * For example, `ngInclude` won't work for cross-domain requests on all browsers and for `file://`
24257 * access on some browsers.
24260 * enter - animation is used to bring new content into the browser.
24261 * leave - animation is used to animate existing content away.
24263 * The enter and leave animation occur concurrently.
24268 * @param {string} ngInclude|src angular expression evaluating to URL. If the source is a string constant,
24269 * make sure you wrap it in **single** quotes, e.g. `src="'myPartialTemplate.html'"`.
24270 * @param {string=} onload Expression to evaluate when a new partial is loaded.
24271 * <div class="alert alert-warning">
24272 * **Note:** When using onload on SVG elements in IE11, the browser will try to call
24273 * a function with the name on the window element, which will usually throw a
24274 * "function is undefined" error. To fix this, you can instead use `data-onload` or a
24275 * different form that {@link guide/directive#normalization matches} `onload`.
24278 * @param {string=} autoscroll Whether `ngInclude` should call {@link ng.$anchorScroll
24279 * $anchorScroll} to scroll the viewport after the content is loaded.
24281 * - If the attribute is not set, disable scrolling.
24282 * - If the attribute is set without value, enable scrolling.
24283 * - Otherwise enable scrolling only if the expression evaluates to truthy value.
24286 <example module="includeExample" deps="angular-animate.js" animations="true">
24287 <file name="index.html">
24288 <div ng-controller="ExampleController">
24289 <select ng-model="template" ng-options="t.name for t in templates">
24290 <option value="">(blank)</option>
24292 url of the template: <code>{{template.url}}</code>
24294 <div class="slide-animate-container">
24295 <div class="slide-animate" ng-include="template.url"></div>
24299 <file name="script.js">
24300 angular.module('includeExample', ['ngAnimate'])
24301 .controller('ExampleController', ['$scope', function($scope) {
24303 [ { name: 'template1.html', url: 'template1.html'},
24304 { name: 'template2.html', url: 'template2.html'} ];
24305 $scope.template = $scope.templates[0];
24308 <file name="template1.html">
24309 Content of template1.html
24311 <file name="template2.html">
24312 Content of template2.html
24314 <file name="animations.css">
24315 .slide-animate-container {
24318 border:1px solid black;
24327 .slide-animate.ng-enter, .slide-animate.ng-leave {
24328 transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
24339 .slide-animate.ng-enter {
24342 .slide-animate.ng-enter.ng-enter-active {
24346 .slide-animate.ng-leave {
24349 .slide-animate.ng-leave.ng-leave-active {
24353 <file name="protractor.js" type="protractor">
24354 var templateSelect = element(by.model('template'));
24355 var includeElem = element(by.css('[ng-include]'));
24357 it('should load template1.html', function() {
24358 expect(includeElem.getText()).toMatch(/Content of template1.html/);
24361 it('should load template2.html', function() {
24362 if (browser.params.browser == 'firefox') {
24363 // Firefox can't handle using selects
24364 // See https://github.com/angular/protractor/issues/480
24367 templateSelect.click();
24368 templateSelect.all(by.css('option')).get(2).click();
24369 expect(includeElem.getText()).toMatch(/Content of template2.html/);
24372 it('should change to blank', function() {
24373 if (browser.params.browser == 'firefox') {
24374 // Firefox can't handle using selects
24377 templateSelect.click();
24378 templateSelect.all(by.css('option')).get(0).click();
24379 expect(includeElem.isPresent()).toBe(false);
24388 * @name ngInclude#$includeContentRequested
24389 * @eventType emit on the scope ngInclude was declared in
24391 * Emitted every time the ngInclude content is requested.
24393 * @param {Object} angularEvent Synthetic event object.
24394 * @param {String} src URL of content to load.
24400 * @name ngInclude#$includeContentLoaded
24401 * @eventType emit on the current ngInclude scope
24403 * Emitted every time the ngInclude content is reloaded.
24405 * @param {Object} angularEvent Synthetic event object.
24406 * @param {String} src URL of content to load.
24412 * @name ngInclude#$includeContentError
24413 * @eventType emit on the scope ngInclude was declared in
24415 * Emitted when a template HTTP request yields an erroneous response (status < 200 || status > 299)
24417 * @param {Object} angularEvent Synthetic event object.
24418 * @param {String} src URL of content to load.
24420 var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate',
24421 function($templateRequest, $anchorScroll, $animate) {
24426 transclude: 'element',
24427 controller: angular.noop,
24428 compile: function(element, attr) {
24429 var srcExp = attr.ngInclude || attr.src,
24430 onloadExp = attr.onload || '',
24431 autoScrollExp = attr.autoscroll;
24433 return function(scope, $element, $attr, ctrl, $transclude) {
24434 var changeCounter = 0,
24439 var cleanupLastIncludeContent = function() {
24440 if (previousElement) {
24441 previousElement.remove();
24442 previousElement = null;
24444 if (currentScope) {
24445 currentScope.$destroy();
24446 currentScope = null;
24448 if (currentElement) {
24449 $animate.leave(currentElement).then(function() {
24450 previousElement = null;
24452 previousElement = currentElement;
24453 currentElement = null;
24457 scope.$watch(srcExp, function ngIncludeWatchAction(src) {
24458 var afterAnimation = function() {
24459 if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
24463 var thisChangeId = ++changeCounter;
24466 //set the 2nd param to true to ignore the template request error so that the inner
24467 //contents and scope can be cleaned up.
24468 $templateRequest(src, true).then(function(response) {
24469 if (thisChangeId !== changeCounter) return;
24470 var newScope = scope.$new();
24471 ctrl.template = response;
24473 // Note: This will also link all children of ng-include that were contained in the original
24474 // html. If that content contains controllers, ... they could pollute/change the scope.
24475 // However, using ng-include on an element with additional content does not make sense...
24476 // Note: We can't remove them in the cloneAttchFn of $transclude as that
24477 // function is called before linking the content, which would apply child
24478 // directives to non existing elements.
24479 var clone = $transclude(newScope, function(clone) {
24480 cleanupLastIncludeContent();
24481 $animate.enter(clone, null, $element).then(afterAnimation);
24484 currentScope = newScope;
24485 currentElement = clone;
24487 currentScope.$emit('$includeContentLoaded', src);
24488 scope.$eval(onloadExp);
24490 if (thisChangeId === changeCounter) {
24491 cleanupLastIncludeContent();
24492 scope.$emit('$includeContentError', src);
24495 scope.$emit('$includeContentRequested', src);
24497 cleanupLastIncludeContent();
24498 ctrl.template = null;
24506 // This directive is called during the $transclude call of the first `ngInclude` directive.
24507 // It will replace and compile the content of the element with the loaded template.
24508 // We need this directive so that the element content is already filled when
24509 // the link function of another directive on the same element as ngInclude
24511 var ngIncludeFillContentDirective = ['$compile',
24512 function($compile) {
24516 require: 'ngInclude',
24517 link: function(scope, $element, $attr, ctrl) {
24518 if (/SVG/.test($element[0].toString())) {
24519 // WebKit: https://bugs.webkit.org/show_bug.cgi?id=135698 --- SVG elements do not
24520 // support innerHTML, so detect this here and try to generate the contents
24523 $compile(jqLiteBuildFragment(ctrl.template, document).childNodes)(scope,
24524 function namespaceAdaptedClone(clone) {
24525 $element.append(clone);
24526 }, {futureParentElement: $element});
24530 $element.html(ctrl.template);
24531 $compile($element.contents())(scope);
24542 * The `ngInit` directive allows you to evaluate an expression in the
24545 * <div class="alert alert-danger">
24546 * This directive can be abused to add unnecessary amounts of logic into your templates.
24547 * There are only a few appropriate uses of `ngInit`, such as for aliasing special properties of
24548 * {@link ng.directive:ngRepeat `ngRepeat`}, as seen in the demo below; and for injecting data via
24549 * server side scripting. Besides these few cases, you should use {@link guide/controller controllers}
24550 * rather than `ngInit` to initialize values on a scope.
24553 * <div class="alert alert-warning">
24554 * **Note**: If you have assignment in `ngInit` along with a {@link ng.$filter `filter`}, make
24555 * sure you have parentheses to ensure correct operator precedence:
24556 * <pre class="prettyprint">
24557 * `<div ng-init="test1 = ($index | toString)"></div>`
24564 * @param {expression} ngInit {@link guide/expression Expression} to eval.
24567 <example module="initExample">
24568 <file name="index.html">
24570 angular.module('initExample', [])
24571 .controller('ExampleController', ['$scope', function($scope) {
24572 $scope.list = [['a', 'b'], ['c', 'd']];
24575 <div ng-controller="ExampleController">
24576 <div ng-repeat="innerList in list" ng-init="outerIndex = $index">
24577 <div ng-repeat="value in innerList" ng-init="innerIndex = $index">
24578 <span class="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}};</span>
24583 <file name="protractor.js" type="protractor">
24584 it('should alias index positions', function() {
24585 var elements = element.all(by.css('.example-init'));
24586 expect(elements.get(0).getText()).toBe('list[ 0 ][ 0 ] = a;');
24587 expect(elements.get(1).getText()).toBe('list[ 0 ][ 1 ] = b;');
24588 expect(elements.get(2).getText()).toBe('list[ 1 ][ 0 ] = c;');
24589 expect(elements.get(3).getText()).toBe('list[ 1 ][ 1 ] = d;');
24594 var ngInitDirective = ngDirective({
24596 compile: function() {
24598 pre: function(scope, element, attrs) {
24599 scope.$eval(attrs.ngInit);
24610 * Text input that converts between a delimited string and an array of strings. The default
24611 * delimiter is a comma followed by a space - equivalent to `ng-list=", "`. You can specify a custom
24612 * delimiter as the value of the `ngList` attribute - for example, `ng-list=" | "`.
24614 * The behaviour of the directive is affected by the use of the `ngTrim` attribute.
24615 * * If `ngTrim` is set to `"false"` then whitespace around both the separator and each
24616 * list item is respected. This implies that the user of the directive is responsible for
24617 * dealing with whitespace but also allows you to use whitespace as a delimiter, such as a
24618 * tab or newline character.
24619 * * Otherwise whitespace around the delimiter is ignored when splitting (although it is respected
24620 * when joining the list items back together) and whitespace around each list item is stripped
24621 * before it is added to the model.
24623 * ### Example with Validation
24625 * <example name="ngList-directive" module="listExample">
24626 * <file name="app.js">
24627 * angular.module('listExample', [])
24628 * .controller('ExampleController', ['$scope', function($scope) {
24629 * $scope.names = ['morpheus', 'neo', 'trinity'];
24632 * <file name="index.html">
24633 * <form name="myForm" ng-controller="ExampleController">
24634 * <label>List: <input name="namesInput" ng-model="names" ng-list required></label>
24635 * <span role="alert">
24636 * <span class="error" ng-show="myForm.namesInput.$error.required">
24640 * <tt>names = {{names}}</tt><br/>
24641 * <tt>myForm.namesInput.$valid = {{myForm.namesInput.$valid}}</tt><br/>
24642 * <tt>myForm.namesInput.$error = {{myForm.namesInput.$error}}</tt><br/>
24643 * <tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
24644 * <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
24647 * <file name="protractor.js" type="protractor">
24648 * var listInput = element(by.model('names'));
24649 * var names = element(by.exactBinding('names'));
24650 * var valid = element(by.binding('myForm.namesInput.$valid'));
24651 * var error = element(by.css('span.error'));
24653 * it('should initialize to model', function() {
24654 * expect(names.getText()).toContain('["morpheus","neo","trinity"]');
24655 * expect(valid.getText()).toContain('true');
24656 * expect(error.getCssValue('display')).toBe('none');
24659 * it('should be invalid if empty', function() {
24660 * listInput.clear();
24661 * listInput.sendKeys('');
24663 * expect(names.getText()).toContain('');
24664 * expect(valid.getText()).toContain('false');
24665 * expect(error.getCssValue('display')).not.toBe('none');
24670 * ### Example - splitting on newline
24671 * <example name="ngList-directive-newlines">
24672 * <file name="index.html">
24673 * <textarea ng-model="list" ng-list=" " ng-trim="false"></textarea>
24674 * <pre>{{ list | json }}</pre>
24676 * <file name="protractor.js" type="protractor">
24677 * it("should split the text by newlines", function() {
24678 * var listInput = element(by.model('list'));
24679 * var output = element(by.binding('list | json'));
24680 * listInput.sendKeys('abc\ndef\nghi');
24681 * expect(output.getText()).toContain('[\n "abc",\n "def",\n "ghi"\n]');
24687 * @param {string=} ngList optional delimiter that should be used to split the value.
24689 var ngListDirective = function() {
24693 require: 'ngModel',
24694 link: function(scope, element, attr, ctrl) {
24695 // We want to control whitespace trimming so we use this convoluted approach
24696 // to access the ngList attribute, which doesn't pre-trim the attribute
24697 var ngList = element.attr(attr.$attr.ngList) || ', ';
24698 var trimValues = attr.ngTrim !== 'false';
24699 var separator = trimValues ? trim(ngList) : ngList;
24701 var parse = function(viewValue) {
24702 // If the viewValue is invalid (say required but empty) it will be `undefined`
24703 if (isUndefined(viewValue)) return;
24708 forEach(viewValue.split(separator), function(value) {
24709 if (value) list.push(trimValues ? trim(value) : value);
24716 ctrl.$parsers.push(parse);
24717 ctrl.$formatters.push(function(value) {
24718 if (isArray(value)) {
24719 return value.join(ngList);
24725 // Override the standard $isEmpty because an empty array means the input is empty.
24726 ctrl.$isEmpty = function(value) {
24727 return !value || !value.length;
24733 /* global VALID_CLASS: true,
24734 INVALID_CLASS: true,
24735 PRISTINE_CLASS: true,
24737 UNTOUCHED_CLASS: true,
24738 TOUCHED_CLASS: true,
24741 var VALID_CLASS = 'ng-valid',
24742 INVALID_CLASS = 'ng-invalid',
24743 PRISTINE_CLASS = 'ng-pristine',
24744 DIRTY_CLASS = 'ng-dirty',
24745 UNTOUCHED_CLASS = 'ng-untouched',
24746 TOUCHED_CLASS = 'ng-touched',
24747 PENDING_CLASS = 'ng-pending';
24749 var ngModelMinErr = minErr('ngModel');
24753 * @name ngModel.NgModelController
24755 * @property {*} $viewValue The actual value from the control's view. For `input` elements, this is a
24756 * String. See {@link ngModel.NgModelController#$setViewValue} for information about when the $viewValue
24758 * @property {*} $modelValue The value in the model that the control is bound to.
24759 * @property {Array.<Function>} $parsers Array of functions to execute, as a pipeline, whenever
24760 the control reads value from the DOM. The functions are called in array order, each passing
24761 its return value through to the next. The last return value is forwarded to the
24762 {@link ngModel.NgModelController#$validators `$validators`} collection.
24764 Parsers are used to sanitize / convert the {@link ngModel.NgModelController#$viewValue
24767 Returning `undefined` from a parser means a parse error occurred. In that case,
24768 no {@link ngModel.NgModelController#$validators `$validators`} will run and the `ngModel`
24769 will be set to `undefined` unless {@link ngModelOptions `ngModelOptions.allowInvalid`}
24770 is set to `true`. The parse error is stored in `ngModel.$error.parse`.
24773 * @property {Array.<Function>} $formatters Array of functions to execute, as a pipeline, whenever
24774 the model value changes. The functions are called in reverse array order, each passing the value through to the
24775 next. The last return value is used as the actual DOM value.
24776 Used to format / convert values for display in the control.
24778 * function formatter(value) {
24780 * return value.toUpperCase();
24783 * ngModel.$formatters.push(formatter);
24786 * @property {Object.<string, function>} $validators A collection of validators that are applied
24787 * whenever the model value changes. The key value within the object refers to the name of the
24788 * validator while the function refers to the validation operation. The validation operation is
24789 * provided with the model value as an argument and must return a true or false value depending
24790 * on the response of that validation.
24793 * ngModel.$validators.validCharacters = function(modelValue, viewValue) {
24794 * var value = modelValue || viewValue;
24795 * return /[0-9]+/.test(value) &&
24796 * /[a-z]+/.test(value) &&
24797 * /[A-Z]+/.test(value) &&
24798 * /\W+/.test(value);
24802 * @property {Object.<string, function>} $asyncValidators A collection of validations that are expected to
24803 * perform an asynchronous validation (e.g. a HTTP request). The validation function that is provided
24804 * is expected to return a promise when it is run during the model validation process. Once the promise
24805 * is delivered then the validation status will be set to true when fulfilled and false when rejected.
24806 * When the asynchronous validators are triggered, each of the validators will run in parallel and the model
24807 * value will only be updated once all validators have been fulfilled. As long as an asynchronous validator
24808 * is unfulfilled, its key will be added to the controllers `$pending` property. Also, all asynchronous validators
24809 * will only run once all synchronous validators have passed.
24811 * Please note that if $http is used then it is important that the server returns a success HTTP response code
24812 * in order to fulfill the validation and a status level of `4xx` in order to reject the validation.
24815 * ngModel.$asyncValidators.uniqueUsername = function(modelValue, viewValue) {
24816 * var value = modelValue || viewValue;
24818 * // Lookup user by username
24819 * return $http.get('/api/users/' + value).
24820 * then(function resolved() {
24821 * //username exists, this means validation fails
24822 * return $q.reject('exists');
24823 * }, function rejected() {
24824 * //username does not exist, therefore this validation passes
24830 * @property {Array.<Function>} $viewChangeListeners Array of functions to execute whenever the
24831 * view value has changed. It is called with no arguments, and its return value is ignored.
24832 * This can be used in place of additional $watches against the model value.
24834 * @property {Object} $error An object hash with all failing validator ids as keys.
24835 * @property {Object} $pending An object hash with all pending validator ids as keys.
24837 * @property {boolean} $untouched True if control has not lost focus yet.
24838 * @property {boolean} $touched True if control has lost focus.
24839 * @property {boolean} $pristine True if user has not interacted with the control yet.
24840 * @property {boolean} $dirty True if user has already interacted with the control.
24841 * @property {boolean} $valid True if there is no error.
24842 * @property {boolean} $invalid True if at least one error on the control.
24843 * @property {string} $name The name attribute of the control.
24847 * `NgModelController` provides API for the {@link ngModel `ngModel`} directive.
24848 * The controller contains services for data-binding, validation, CSS updates, and value formatting
24849 * and parsing. It purposefully does not contain any logic which deals with DOM rendering or
24850 * listening to DOM events.
24851 * Such DOM related logic should be provided by other directives which make use of
24852 * `NgModelController` for data-binding to control elements.
24853 * Angular provides this DOM logic for most {@link input `input`} elements.
24854 * At the end of this page you can find a {@link ngModel.NgModelController#custom-control-example
24855 * custom control example} that uses `ngModelController` to bind to `contenteditable` elements.
24858 * ### Custom Control Example
24859 * This example shows how to use `NgModelController` with a custom control to achieve
24860 * data-binding. Notice how different directives (`contenteditable`, `ng-model`, and `required`)
24861 * collaborate together to achieve the desired result.
24863 * `contenteditable` is an HTML5 attribute, which tells the browser to let the element
24864 * contents be edited in place by the user.
24866 * We are using the {@link ng.service:$sce $sce} service here and include the {@link ngSanitize $sanitize}
24867 * module to automatically remove "bad" content like inline event listener (e.g. `<span onclick="...">`).
24868 * However, as we are using `$sce` the model can still decide to provide unsafe content if it marks
24869 * that content using the `$sce` service.
24871 * <example name="NgModelController" module="customControl" deps="angular-sanitize.js">
24872 <file name="style.css">
24873 [contenteditable] {
24874 border: 1px solid black;
24875 background-color: white;
24880 border: 1px solid red;
24884 <file name="script.js">
24885 angular.module('customControl', ['ngSanitize']).
24886 directive('contenteditable', ['$sce', function($sce) {
24888 restrict: 'A', // only activate on element attribute
24889 require: '?ngModel', // get a hold of NgModelController
24890 link: function(scope, element, attrs, ngModel) {
24891 if (!ngModel) return; // do nothing if no ng-model
24893 // Specify how UI should be updated
24894 ngModel.$render = function() {
24895 element.html($sce.getTrustedHtml(ngModel.$viewValue || ''));
24898 // Listen for change events to enable binding
24899 element.on('blur keyup change', function() {
24900 scope.$evalAsync(read);
24902 read(); // initialize
24904 // Write data to the model
24906 var html = element.html();
24907 // When we clear the content editable the browser leaves a <br> behind
24908 // If strip-br attribute is provided then we strip this out
24909 if ( attrs.stripBr && html == '<br>' ) {
24912 ngModel.$setViewValue(html);
24918 <file name="index.html">
24919 <form name="myForm">
24920 <div contenteditable
24921 name="myWidget" ng-model="userContent"
24923 required>Change me!</div>
24924 <span ng-show="myForm.myWidget.$error.required">Required!</span>
24926 <textarea ng-model="userContent" aria-label="Dynamic textarea"></textarea>
24929 <file name="protractor.js" type="protractor">
24930 it('should data-bind and become invalid', function() {
24931 if (browser.params.browser == 'safari' || browser.params.browser == 'firefox') {
24932 // SafariDriver can't handle contenteditable
24933 // and Firefox driver can't clear contenteditables very well
24936 var contentEditable = element(by.css('[contenteditable]'));
24937 var content = 'Change me!';
24939 expect(contentEditable.getText()).toEqual(content);
24941 contentEditable.clear();
24942 contentEditable.sendKeys(protractor.Key.BACK_SPACE);
24943 expect(contentEditable.getText()).toEqual('');
24944 expect(contentEditable.getAttribute('class')).toMatch(/ng-invalid-required/);
24951 var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate', '$timeout', '$rootScope', '$q', '$interpolate',
24952 function($scope, $exceptionHandler, $attr, $element, $parse, $animate, $timeout, $rootScope, $q, $interpolate) {
24953 this.$viewValue = Number.NaN;
24954 this.$modelValue = Number.NaN;
24955 this.$$rawModelValue = undefined; // stores the parsed modelValue / model set from scope regardless of validity.
24956 this.$validators = {};
24957 this.$asyncValidators = {};
24958 this.$parsers = [];
24959 this.$formatters = [];
24960 this.$viewChangeListeners = [];
24961 this.$untouched = true;
24962 this.$touched = false;
24963 this.$pristine = true;
24964 this.$dirty = false;
24965 this.$valid = true;
24966 this.$invalid = false;
24967 this.$error = {}; // keep invalid keys here
24968 this.$$success = {}; // keep valid keys here
24969 this.$pending = undefined; // keep pending keys here
24970 this.$name = $interpolate($attr.name || '', false)($scope);
24971 this.$$parentForm = nullFormCtrl;
24973 var parsedNgModel = $parse($attr.ngModel),
24974 parsedNgModelAssign = parsedNgModel.assign,
24975 ngModelGet = parsedNgModel,
24976 ngModelSet = parsedNgModelAssign,
24977 pendingDebounce = null,
24981 this.$$setOptions = function(options) {
24982 ctrl.$options = options;
24983 if (options && options.getterSetter) {
24984 var invokeModelGetter = $parse($attr.ngModel + '()'),
24985 invokeModelSetter = $parse($attr.ngModel + '($$$p)');
24987 ngModelGet = function($scope) {
24988 var modelValue = parsedNgModel($scope);
24989 if (isFunction(modelValue)) {
24990 modelValue = invokeModelGetter($scope);
24994 ngModelSet = function($scope, newValue) {
24995 if (isFunction(parsedNgModel($scope))) {
24996 invokeModelSetter($scope, {$$$p: ctrl.$modelValue});
24998 parsedNgModelAssign($scope, ctrl.$modelValue);
25001 } else if (!parsedNgModel.assign) {
25002 throw ngModelMinErr('nonassign', "Expression '{0}' is non-assignable. Element: {1}",
25003 $attr.ngModel, startingTag($element));
25009 * @name ngModel.NgModelController#$render
25012 * Called when the view needs to be updated. It is expected that the user of the ng-model
25013 * directive will implement this method.
25015 * The `$render()` method is invoked in the following situations:
25017 * * `$rollbackViewValue()` is called. If we are rolling back the view value to the last
25018 * committed value then `$render()` is called to update the input control.
25019 * * The value referenced by `ng-model` is changed programmatically and both the `$modelValue` and
25020 * the `$viewValue` are different from last time.
25022 * Since `ng-model` does not do a deep watch, `$render()` is only invoked if the values of
25023 * `$modelValue` and `$viewValue` are actually different from their previous value. If `$modelValue`
25024 * or `$viewValue` are objects (rather than a string or number) then `$render()` will not be
25025 * invoked if you only change a property on the objects.
25027 this.$render = noop;
25031 * @name ngModel.NgModelController#$isEmpty
25034 * This is called when we need to determine if the value of an input is empty.
25036 * For instance, the required directive does this to work out if the input has data or not.
25038 * The default `$isEmpty` function checks whether the value is `undefined`, `''`, `null` or `NaN`.
25040 * You can override this for input directives whose concept of being empty is different from the
25041 * default. The `checkboxInputType` directive does this because in its case a value of `false`
25044 * @param {*} value The value of the input to check for emptiness.
25045 * @returns {boolean} True if `value` is "empty".
25047 this.$isEmpty = function(value) {
25048 return isUndefined(value) || value === '' || value === null || value !== value;
25051 var currentValidationRunId = 0;
25055 * @name ngModel.NgModelController#$setValidity
25058 * Change the validity state, and notify the form.
25060 * This method can be called within $parsers/$formatters or a custom validation implementation.
25061 * However, in most cases it should be sufficient to use the `ngModel.$validators` and
25062 * `ngModel.$asyncValidators` collections which will call `$setValidity` automatically.
25064 * @param {string} validationErrorKey Name of the validator. The `validationErrorKey` will be assigned
25065 * to either `$error[validationErrorKey]` or `$pending[validationErrorKey]`
25066 * (for unfulfilled `$asyncValidators`), so that it is available for data-binding.
25067 * The `validationErrorKey` should be in camelCase and will get converted into dash-case
25068 * for class name. Example: `myError` will result in `ng-valid-my-error` and `ng-invalid-my-error`
25069 * class and can be bound to as `{{someForm.someControl.$error.myError}}` .
25070 * @param {boolean} isValid Whether the current state is valid (true), invalid (false), pending (undefined),
25071 * or skipped (null). Pending is used for unfulfilled `$asyncValidators`.
25072 * Skipped is used by Angular when validators do not run because of parse errors and
25073 * when `$asyncValidators` do not run because any of the `$validators` failed.
25075 addSetValidityMethod({
25077 $element: $element,
25078 set: function(object, property) {
25079 object[property] = true;
25081 unset: function(object, property) {
25082 delete object[property];
25089 * @name ngModel.NgModelController#$setPristine
25092 * Sets the control to its pristine state.
25094 * This method can be called to remove the `ng-dirty` class and set the control to its pristine
25095 * state (`ng-pristine` class). A model is considered to be pristine when the control
25096 * has not been changed from when first compiled.
25098 this.$setPristine = function() {
25099 ctrl.$dirty = false;
25100 ctrl.$pristine = true;
25101 $animate.removeClass($element, DIRTY_CLASS);
25102 $animate.addClass($element, PRISTINE_CLASS);
25107 * @name ngModel.NgModelController#$setDirty
25110 * Sets the control to its dirty state.
25112 * This method can be called to remove the `ng-pristine` class and set the control to its dirty
25113 * state (`ng-dirty` class). A model is considered to be dirty when the control has been changed
25114 * from when first compiled.
25116 this.$setDirty = function() {
25117 ctrl.$dirty = true;
25118 ctrl.$pristine = false;
25119 $animate.removeClass($element, PRISTINE_CLASS);
25120 $animate.addClass($element, DIRTY_CLASS);
25121 ctrl.$$parentForm.$setDirty();
25126 * @name ngModel.NgModelController#$setUntouched
25129 * Sets the control to its untouched state.
25131 * This method can be called to remove the `ng-touched` class and set the control to its
25132 * untouched state (`ng-untouched` class). Upon compilation, a model is set as untouched
25133 * by default, however this function can be used to restore that state if the model has
25134 * already been touched by the user.
25136 this.$setUntouched = function() {
25137 ctrl.$touched = false;
25138 ctrl.$untouched = true;
25139 $animate.setClass($element, UNTOUCHED_CLASS, TOUCHED_CLASS);
25144 * @name ngModel.NgModelController#$setTouched
25147 * Sets the control to its touched state.
25149 * This method can be called to remove the `ng-untouched` class and set the control to its
25150 * touched state (`ng-touched` class). A model is considered to be touched when the user has
25151 * first focused the control element and then shifted focus away from the control (blur event).
25153 this.$setTouched = function() {
25154 ctrl.$touched = true;
25155 ctrl.$untouched = false;
25156 $animate.setClass($element, TOUCHED_CLASS, UNTOUCHED_CLASS);
25161 * @name ngModel.NgModelController#$rollbackViewValue
25164 * Cancel an update and reset the input element's value to prevent an update to the `$modelValue`,
25165 * which may be caused by a pending debounced event or because the input is waiting for a some
25168 * If you have an input that uses `ng-model-options` to set up debounced events or events such
25169 * as blur you can have a situation where there is a period when the `$viewValue`
25170 * is out of synch with the ngModel's `$modelValue`.
25172 * In this case, you can run into difficulties if you try to update the ngModel's `$modelValue`
25173 * programmatically before these debounced/future events have resolved/occurred, because Angular's
25174 * dirty checking mechanism is not able to tell whether the model has actually changed or not.
25176 * The `$rollbackViewValue()` method should be called before programmatically changing the model of an
25177 * input which may have such events pending. This is important in order to make sure that the
25178 * input field will be updated with the new model value and any pending operations are cancelled.
25180 * <example name="ng-model-cancel-update" module="cancel-update-example">
25181 * <file name="app.js">
25182 * angular.module('cancel-update-example', [])
25184 * .controller('CancelUpdateController', ['$scope', function($scope) {
25185 * $scope.resetWithCancel = function(e) {
25186 * if (e.keyCode == 27) {
25187 * $scope.myForm.myInput1.$rollbackViewValue();
25188 * $scope.myValue = '';
25191 * $scope.resetWithoutCancel = function(e) {
25192 * if (e.keyCode == 27) {
25193 * $scope.myValue = '';
25198 * <file name="index.html">
25199 * <div ng-controller="CancelUpdateController">
25200 * <p>Try typing something in each input. See that the model only updates when you
25201 * blur off the input.
25203 * <p>Now see what happens if you start typing then press the Escape key</p>
25205 * <form name="myForm" ng-model-options="{ updateOn: 'blur' }">
25206 * <p id="inputDescription1">With $rollbackViewValue()</p>
25207 * <input name="myInput1" aria-describedby="inputDescription1" ng-model="myValue"
25208 * ng-keydown="resetWithCancel($event)"><br/>
25209 * myValue: "{{ myValue }}"
25211 * <p id="inputDescription2">Without $rollbackViewValue()</p>
25212 * <input name="myInput2" aria-describedby="inputDescription2" ng-model="myValue"
25213 * ng-keydown="resetWithoutCancel($event)"><br/>
25214 * myValue: "{{ myValue }}"
25220 this.$rollbackViewValue = function() {
25221 $timeout.cancel(pendingDebounce);
25222 ctrl.$viewValue = ctrl.$$lastCommittedViewValue;
25228 * @name ngModel.NgModelController#$validate
25231 * Runs each of the registered validators (first synchronous validators and then
25232 * asynchronous validators).
25233 * If the validity changes to invalid, the model will be set to `undefined`,
25234 * unless {@link ngModelOptions `ngModelOptions.allowInvalid`} is `true`.
25235 * If the validity changes to valid, it will set the model to the last available valid
25236 * `$modelValue`, i.e. either the last parsed value or the last value set from the scope.
25238 this.$validate = function() {
25239 // ignore $validate before model is initialized
25240 if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) {
25244 var viewValue = ctrl.$$lastCommittedViewValue;
25245 // Note: we use the $$rawModelValue as $modelValue might have been
25246 // set to undefined during a view -> model update that found validation
25247 // errors. We can't parse the view here, since that could change
25248 // the model although neither viewValue nor the model on the scope changed
25249 var modelValue = ctrl.$$rawModelValue;
25251 var prevValid = ctrl.$valid;
25252 var prevModelValue = ctrl.$modelValue;
25254 var allowInvalid = ctrl.$options && ctrl.$options.allowInvalid;
25256 ctrl.$$runValidators(modelValue, viewValue, function(allValid) {
25257 // If there was no change in validity, don't update the model
25258 // This prevents changing an invalid modelValue to undefined
25259 if (!allowInvalid && prevValid !== allValid) {
25260 // Note: Don't check ctrl.$valid here, as we could have
25261 // external validators (e.g. calculated on the server),
25262 // that just call $setValidity and need the model value
25263 // to calculate their validity.
25264 ctrl.$modelValue = allValid ? modelValue : undefined;
25266 if (ctrl.$modelValue !== prevModelValue) {
25267 ctrl.$$writeModelToScope();
25274 this.$$runValidators = function(modelValue, viewValue, doneCallback) {
25275 currentValidationRunId++;
25276 var localValidationRunId = currentValidationRunId;
25278 // check parser error
25279 if (!processParseErrors()) {
25280 validationDone(false);
25283 if (!processSyncValidators()) {
25284 validationDone(false);
25287 processAsyncValidators();
25289 function processParseErrors() {
25290 var errorKey = ctrl.$$parserName || 'parse';
25291 if (isUndefined(parserValid)) {
25292 setValidity(errorKey, null);
25294 if (!parserValid) {
25295 forEach(ctrl.$validators, function(v, name) {
25296 setValidity(name, null);
25298 forEach(ctrl.$asyncValidators, function(v, name) {
25299 setValidity(name, null);
25302 // Set the parse error last, to prevent unsetting it, should a $validators key == parserName
25303 setValidity(errorKey, parserValid);
25304 return parserValid;
25309 function processSyncValidators() {
25310 var syncValidatorsValid = true;
25311 forEach(ctrl.$validators, function(validator, name) {
25312 var result = validator(modelValue, viewValue);
25313 syncValidatorsValid = syncValidatorsValid && result;
25314 setValidity(name, result);
25316 if (!syncValidatorsValid) {
25317 forEach(ctrl.$asyncValidators, function(v, name) {
25318 setValidity(name, null);
25325 function processAsyncValidators() {
25326 var validatorPromises = [];
25327 var allValid = true;
25328 forEach(ctrl.$asyncValidators, function(validator, name) {
25329 var promise = validator(modelValue, viewValue);
25330 if (!isPromiseLike(promise)) {
25331 throw ngModelMinErr("$asyncValidators",
25332 "Expected asynchronous validator to return a promise but got '{0}' instead.", promise);
25334 setValidity(name, undefined);
25335 validatorPromises.push(promise.then(function() {
25336 setValidity(name, true);
25337 }, function(error) {
25339 setValidity(name, false);
25342 if (!validatorPromises.length) {
25343 validationDone(true);
25345 $q.all(validatorPromises).then(function() {
25346 validationDone(allValid);
25351 function setValidity(name, isValid) {
25352 if (localValidationRunId === currentValidationRunId) {
25353 ctrl.$setValidity(name, isValid);
25357 function validationDone(allValid) {
25358 if (localValidationRunId === currentValidationRunId) {
25360 doneCallback(allValid);
25367 * @name ngModel.NgModelController#$commitViewValue
25370 * Commit a pending update to the `$modelValue`.
25372 * Updates may be pending by a debounced event or because the input is waiting for a some future
25373 * event defined in `ng-model-options`. this method is rarely needed as `NgModelController`
25374 * usually handles calling this in response to input events.
25376 this.$commitViewValue = function() {
25377 var viewValue = ctrl.$viewValue;
25379 $timeout.cancel(pendingDebounce);
25381 // If the view value has not changed then we should just exit, except in the case where there is
25382 // a native validator on the element. In this case the validation state may have changed even though
25383 // the viewValue has stayed empty.
25384 if (ctrl.$$lastCommittedViewValue === viewValue && (viewValue !== '' || !ctrl.$$hasNativeValidators)) {
25387 ctrl.$$lastCommittedViewValue = viewValue;
25390 if (ctrl.$pristine) {
25393 this.$$parseAndValidate();
25396 this.$$parseAndValidate = function() {
25397 var viewValue = ctrl.$$lastCommittedViewValue;
25398 var modelValue = viewValue;
25399 parserValid = isUndefined(modelValue) ? undefined : true;
25402 for (var i = 0; i < ctrl.$parsers.length; i++) {
25403 modelValue = ctrl.$parsers[i](modelValue);
25404 if (isUndefined(modelValue)) {
25405 parserValid = false;
25410 if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) {
25411 // ctrl.$modelValue has not been touched yet...
25412 ctrl.$modelValue = ngModelGet($scope);
25414 var prevModelValue = ctrl.$modelValue;
25415 var allowInvalid = ctrl.$options && ctrl.$options.allowInvalid;
25416 ctrl.$$rawModelValue = modelValue;
25418 if (allowInvalid) {
25419 ctrl.$modelValue = modelValue;
25420 writeToModelIfNeeded();
25423 // Pass the $$lastCommittedViewValue here, because the cached viewValue might be out of date.
25424 // This can happen if e.g. $setViewValue is called from inside a parser
25425 ctrl.$$runValidators(modelValue, ctrl.$$lastCommittedViewValue, function(allValid) {
25426 if (!allowInvalid) {
25427 // Note: Don't check ctrl.$valid here, as we could have
25428 // external validators (e.g. calculated on the server),
25429 // that just call $setValidity and need the model value
25430 // to calculate their validity.
25431 ctrl.$modelValue = allValid ? modelValue : undefined;
25432 writeToModelIfNeeded();
25436 function writeToModelIfNeeded() {
25437 if (ctrl.$modelValue !== prevModelValue) {
25438 ctrl.$$writeModelToScope();
25443 this.$$writeModelToScope = function() {
25444 ngModelSet($scope, ctrl.$modelValue);
25445 forEach(ctrl.$viewChangeListeners, function(listener) {
25449 $exceptionHandler(e);
25456 * @name ngModel.NgModelController#$setViewValue
25459 * Update the view value.
25461 * This method should be called when a control wants to change the view value; typically,
25462 * this is done from within a DOM event handler. For example, the {@link ng.directive:input input}
25463 * directive calls it when the value of the input changes and {@link ng.directive:select select}
25464 * calls it when an option is selected.
25466 * When `$setViewValue` is called, the new `value` will be staged for committing through the `$parsers`
25467 * and `$validators` pipelines. If there are no special {@link ngModelOptions} specified then the staged
25468 * value sent directly for processing, finally to be applied to `$modelValue` and then the
25469 * **expression** specified in the `ng-model` attribute. Lastly, all the registered change listeners,
25470 * in the `$viewChangeListeners` list, are called.
25472 * In case the {@link ng.directive:ngModelOptions ngModelOptions} directive is used with `updateOn`
25473 * and the `default` trigger is not listed, all those actions will remain pending until one of the
25474 * `updateOn` events is triggered on the DOM element.
25475 * All these actions will be debounced if the {@link ng.directive:ngModelOptions ngModelOptions}
25476 * directive is used with a custom debounce for this particular event.
25477 * Note that a `$digest` is only triggered once the `updateOn` events are fired, or if `debounce`
25478 * is specified, once the timer runs out.
25480 * When used with standard inputs, the view value will always be a string (which is in some cases
25481 * parsed into another type, such as a `Date` object for `input[date]`.)
25482 * However, custom controls might also pass objects to this method. In this case, we should make
25483 * a copy of the object before passing it to `$setViewValue`. This is because `ngModel` does not
25484 * perform a deep watch of objects, it only looks for a change of identity. If you only change
25485 * the property of the object then ngModel will not realise that the object has changed and
25486 * will not invoke the `$parsers` and `$validators` pipelines. For this reason, you should
25487 * not change properties of the copy once it has been passed to `$setViewValue`.
25488 * Otherwise you may cause the model value on the scope to change incorrectly.
25490 * <div class="alert alert-info">
25491 * In any case, the value passed to the method should always reflect the current value
25492 * of the control. For example, if you are calling `$setViewValue` for an input element,
25493 * you should pass the input DOM value. Otherwise, the control and the scope model become
25494 * out of sync. It's also important to note that `$setViewValue` does not call `$render` or change
25495 * the control's DOM value in any way. If we want to change the control's DOM value
25496 * programmatically, we should update the `ngModel` scope expression. Its new value will be
25497 * picked up by the model controller, which will run it through the `$formatters`, `$render` it
25498 * to update the DOM, and finally call `$validate` on it.
25501 * @param {*} value value from the view.
25502 * @param {string} trigger Event that triggered the update.
25504 this.$setViewValue = function(value, trigger) {
25505 ctrl.$viewValue = value;
25506 if (!ctrl.$options || ctrl.$options.updateOnDefault) {
25507 ctrl.$$debounceViewValueCommit(trigger);
25511 this.$$debounceViewValueCommit = function(trigger) {
25512 var debounceDelay = 0,
25513 options = ctrl.$options,
25516 if (options && isDefined(options.debounce)) {
25517 debounce = options.debounce;
25518 if (isNumber(debounce)) {
25519 debounceDelay = debounce;
25520 } else if (isNumber(debounce[trigger])) {
25521 debounceDelay = debounce[trigger];
25522 } else if (isNumber(debounce['default'])) {
25523 debounceDelay = debounce['default'];
25527 $timeout.cancel(pendingDebounce);
25528 if (debounceDelay) {
25529 pendingDebounce = $timeout(function() {
25530 ctrl.$commitViewValue();
25532 } else if ($rootScope.$$phase) {
25533 ctrl.$commitViewValue();
25535 $scope.$apply(function() {
25536 ctrl.$commitViewValue();
25542 // Note: we cannot use a normal scope.$watch as we want to detect the following:
25543 // 1. scope value is 'a'
25544 // 2. user enters 'b'
25545 // 3. ng-change kicks in and reverts scope value to 'a'
25546 // -> scope value did not change since the last digest as
25547 // ng-change executes in apply phase
25548 // 4. view should be changed back to 'a'
25549 $scope.$watch(function ngModelWatch() {
25550 var modelValue = ngModelGet($scope);
25552 // if scope model value and ngModel value are out of sync
25553 // TODO(perf): why not move this to the action fn?
25554 if (modelValue !== ctrl.$modelValue &&
25555 // checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
25556 (ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
25558 ctrl.$modelValue = ctrl.$$rawModelValue = modelValue;
25559 parserValid = undefined;
25561 var formatters = ctrl.$formatters,
25562 idx = formatters.length;
25564 var viewValue = modelValue;
25566 viewValue = formatters[idx](viewValue);
25568 if (ctrl.$viewValue !== viewValue) {
25569 ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue;
25572 ctrl.$$runValidators(modelValue, viewValue, noop);
25589 * The `ngModel` directive binds an `input`,`select`, `textarea` (or custom form control) to a
25590 * property on the scope using {@link ngModel.NgModelController NgModelController},
25591 * which is created and exposed by this directive.
25593 * `ngModel` is responsible for:
25595 * - Binding the view into the model, which other directives such as `input`, `textarea` or `select`
25597 * - Providing validation behavior (i.e. required, number, email, url).
25598 * - Keeping the state of the control (valid/invalid, dirty/pristine, touched/untouched, validation errors).
25599 * - Setting related css classes on the element (`ng-valid`, `ng-invalid`, `ng-dirty`, `ng-pristine`, `ng-touched`, `ng-untouched`) including animations.
25600 * - Registering the control with its parent {@link ng.directive:form form}.
25602 * Note: `ngModel` will try to bind to the property given by evaluating the expression on the
25603 * current scope. If the property doesn't already exist on this scope, it will be created
25604 * implicitly and added to the scope.
25606 * For best practices on using `ngModel`, see:
25608 * - [Understanding Scopes](https://github.com/angular/angular.js/wiki/Understanding-Scopes)
25610 * For basic examples, how to use `ngModel`, see:
25612 * - {@link ng.directive:input input}
25613 * - {@link input[text] text}
25614 * - {@link input[checkbox] checkbox}
25615 * - {@link input[radio] radio}
25616 * - {@link input[number] number}
25617 * - {@link input[email] email}
25618 * - {@link input[url] url}
25619 * - {@link input[date] date}
25620 * - {@link input[datetime-local] datetime-local}
25621 * - {@link input[time] time}
25622 * - {@link input[month] month}
25623 * - {@link input[week] week}
25624 * - {@link ng.directive:select select}
25625 * - {@link ng.directive:textarea textarea}
25628 * The following CSS classes are added and removed on the associated input/select/textarea element
25629 * depending on the validity of the model.
25631 * - `ng-valid`: the model is valid
25632 * - `ng-invalid`: the model is invalid
25633 * - `ng-valid-[key]`: for each valid key added by `$setValidity`
25634 * - `ng-invalid-[key]`: for each invalid key added by `$setValidity`
25635 * - `ng-pristine`: the control hasn't been interacted with yet
25636 * - `ng-dirty`: the control has been interacted with
25637 * - `ng-touched`: the control has been blurred
25638 * - `ng-untouched`: the control hasn't been blurred
25639 * - `ng-pending`: any `$asyncValidators` are unfulfilled
25641 * Keep in mind that ngAnimate can detect each of these classes when added and removed.
25643 * ## Animation Hooks
25645 * Animations within models are triggered when any of the associated CSS classes are added and removed
25646 * on the input element which is attached to the model. These classes are: `.ng-pristine`, `.ng-dirty`,
25647 * `.ng-invalid` and `.ng-valid` as well as any other validations that are performed on the model itself.
25648 * The animations that are triggered within ngModel are similar to how they work in ngClass and
25649 * animations can be hooked into using CSS transitions, keyframes as well as JS animations.
25651 * The following example shows a simple way to utilize CSS transitions to style an input element
25652 * that has been rendered as invalid after it has been validated:
25655 * //be sure to include ngAnimate as a module to hook into more
25656 * //advanced animations
25658 * transition:0.5s linear all;
25659 * background: white;
25661 * .my-input.ng-invalid {
25668 * <example deps="angular-animate.js" animations="true" fixBase="true" module="inputExample">
25669 <file name="index.html">
25671 angular.module('inputExample', [])
25672 .controller('ExampleController', ['$scope', function($scope) {
25678 transition:all linear 0.5s;
25679 background: transparent;
25681 .my-input.ng-invalid {
25686 <p id="inputDescription">
25687 Update input to see transitions when valid/invalid.
25688 Integer is a valid value.
25690 <form name="testForm" ng-controller="ExampleController">
25691 <input ng-model="val" ng-pattern="/^\d+$/" name="anim" class="my-input"
25692 aria-describedby="inputDescription" />
25697 * ## Binding to a getter/setter
25699 * Sometimes it's helpful to bind `ngModel` to a getter/setter function. A getter/setter is a
25700 * function that returns a representation of the model when called with zero arguments, and sets
25701 * the internal state of a model when called with an argument. It's sometimes useful to use this
25702 * for models that have an internal representation that's different from what the model exposes
25705 * <div class="alert alert-success">
25706 * **Best Practice:** It's best to keep getters fast because Angular is likely to call them more
25707 * frequently than other parts of your code.
25710 * You use this behavior by adding `ng-model-options="{ getterSetter: true }"` to an element that
25711 * has `ng-model` attached to it. You can also add `ng-model-options="{ getterSetter: true }"` to
25712 * a `<form>`, which will enable this behavior for all `<input>`s within it. See
25713 * {@link ng.directive:ngModelOptions `ngModelOptions`} for more.
25715 * The following example shows how to use `ngModel` with a getter/setter:
25718 * <example name="ngModel-getter-setter" module="getterSetterExample">
25719 <file name="index.html">
25720 <div ng-controller="ExampleController">
25721 <form name="userForm">
25723 <input type="text" name="userName"
25724 ng-model="user.name"
25725 ng-model-options="{ getterSetter: true }" />
25728 <pre>user.name = <span ng-bind="user.name()"></span></pre>
25731 <file name="app.js">
25732 angular.module('getterSetterExample', [])
25733 .controller('ExampleController', ['$scope', function($scope) {
25734 var _name = 'Brian';
25736 name: function(newName) {
25737 // Note that newName can be undefined for two reasons:
25738 // 1. Because it is called as a getter and thus called with no arguments
25739 // 2. Because the property should actually be set to undefined. This happens e.g. if the
25740 // input is invalid
25741 return arguments.length ? (_name = newName) : _name;
25748 var ngModelDirective = ['$rootScope', function($rootScope) {
25751 require: ['ngModel', '^?form', '^?ngModelOptions'],
25752 controller: NgModelController,
25753 // Prelink needs to run before any input directive
25754 // so that we can set the NgModelOptions in NgModelController
25755 // before anyone else uses it.
25757 compile: function ngModelCompile(element) {
25758 // Setup initial state of the control
25759 element.addClass(PRISTINE_CLASS).addClass(UNTOUCHED_CLASS).addClass(VALID_CLASS);
25762 pre: function ngModelPreLink(scope, element, attr, ctrls) {
25763 var modelCtrl = ctrls[0],
25764 formCtrl = ctrls[1] || modelCtrl.$$parentForm;
25766 modelCtrl.$$setOptions(ctrls[2] && ctrls[2].$options);
25768 // notify others, especially parent forms
25769 formCtrl.$addControl(modelCtrl);
25771 attr.$observe('name', function(newValue) {
25772 if (modelCtrl.$name !== newValue) {
25773 modelCtrl.$$parentForm.$$renameControl(modelCtrl, newValue);
25777 scope.$on('$destroy', function() {
25778 modelCtrl.$$parentForm.$removeControl(modelCtrl);
25781 post: function ngModelPostLink(scope, element, attr, ctrls) {
25782 var modelCtrl = ctrls[0];
25783 if (modelCtrl.$options && modelCtrl.$options.updateOn) {
25784 element.on(modelCtrl.$options.updateOn, function(ev) {
25785 modelCtrl.$$debounceViewValueCommit(ev && ev.type);
25789 element.on('blur', function(ev) {
25790 if (modelCtrl.$touched) return;
25792 if ($rootScope.$$phase) {
25793 scope.$evalAsync(modelCtrl.$setTouched);
25795 scope.$apply(modelCtrl.$setTouched);
25804 var DEFAULT_REGEXP = /(\s+|^)default(\s+|$)/;
25808 * @name ngModelOptions
25811 * Allows tuning how model updates are done. Using `ngModelOptions` you can specify a custom list of
25812 * events that will trigger a model update and/or a debouncing delay so that the actual update only
25813 * takes place when a timer expires; this timer will be reset after another change takes place.
25815 * Given the nature of `ngModelOptions`, the value displayed inside input fields in the view might
25816 * be different from the value in the actual model. This means that if you update the model you
25817 * should also invoke {@link ngModel.NgModelController `$rollbackViewValue`} on the relevant input field in
25818 * order to make sure it is synchronized with the model and that any debounced action is canceled.
25820 * The easiest way to reference the control's {@link ngModel.NgModelController `$rollbackViewValue`}
25821 * method is by making sure the input is placed inside a form that has a `name` attribute. This is
25822 * important because `form` controllers are published to the related scope under the name in their
25823 * `name` attribute.
25825 * Any pending changes will take place immediately when an enclosing form is submitted via the
25826 * `submit` event. Note that `ngClick` events will occur before the model is updated. Use `ngSubmit`
25827 * to have access to the updated model.
25829 * `ngModelOptions` has an effect on the element it's declared on and its descendants.
25831 * @param {Object} ngModelOptions options to apply to the current model. Valid keys are:
25832 * - `updateOn`: string specifying which event should the input be bound to. You can set several
25833 * events using an space delimited list. There is a special event called `default` that
25834 * matches the default events belonging of the control.
25835 * - `debounce`: integer value which contains the debounce model update value in milliseconds. A
25836 * value of 0 triggers an immediate update. If an object is supplied instead, you can specify a
25837 * custom value for each event. For example:
25838 * `ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 500, 'blur': 0 } }"`
25839 * - `allowInvalid`: boolean value which indicates that the model can be set with values that did
25840 * not validate correctly instead of the default behavior of setting the model to undefined.
25841 * - `getterSetter`: boolean value which determines whether or not to treat functions bound to
25842 `ngModel` as getters/setters.
25843 * - `timezone`: Defines the timezone to be used to read/write the `Date` instance in the model for
25844 * `<input type="date">`, `<input type="time">`, ... . It understands UTC/GMT and the
25845 * continental US time zone abbreviations, but for general use, use a time zone offset, for
25846 * example, `'+0430'` (4 hours, 30 minutes east of the Greenwich meridian)
25847 * If not specified, the timezone of the browser will be used.
25851 The following example shows how to override immediate updates. Changes on the inputs within the
25852 form will update the model only when the control loses focus (blur event). If `escape` key is
25853 pressed while the input field is focused, the value is reset to the value in the current model.
25855 <example name="ngModelOptions-directive-blur" module="optionsExample">
25856 <file name="index.html">
25857 <div ng-controller="ExampleController">
25858 <form name="userForm">
25860 <input type="text" name="userName"
25861 ng-model="user.name"
25862 ng-model-options="{ updateOn: 'blur' }"
25863 ng-keyup="cancel($event)" />
25866 <input type="text" ng-model="user.data" />
25869 <pre>user.name = <span ng-bind="user.name"></span></pre>
25870 <pre>user.data = <span ng-bind="user.data"></span></pre>
25873 <file name="app.js">
25874 angular.module('optionsExample', [])
25875 .controller('ExampleController', ['$scope', function($scope) {
25876 $scope.user = { name: 'John', data: '' };
25878 $scope.cancel = function(e) {
25879 if (e.keyCode == 27) {
25880 $scope.userForm.userName.$rollbackViewValue();
25885 <file name="protractor.js" type="protractor">
25886 var model = element(by.binding('user.name'));
25887 var input = element(by.model('user.name'));
25888 var other = element(by.model('user.data'));
25890 it('should allow custom events', function() {
25891 input.sendKeys(' Doe');
25893 expect(model.getText()).toEqual('John');
25895 expect(model.getText()).toEqual('John Doe');
25898 it('should $rollbackViewValue when model changes', function() {
25899 input.sendKeys(' Doe');
25900 expect(input.getAttribute('value')).toEqual('John Doe');
25901 input.sendKeys(protractor.Key.ESCAPE);
25902 expect(input.getAttribute('value')).toEqual('John');
25904 expect(model.getText()).toEqual('John');
25909 This one shows how to debounce model changes. Model will be updated only 1 sec after last change.
25910 If the `Clear` button is pressed, any debounced action is canceled and the value becomes empty.
25912 <example name="ngModelOptions-directive-debounce" module="optionsExample">
25913 <file name="index.html">
25914 <div ng-controller="ExampleController">
25915 <form name="userForm">
25917 <input type="text" name="userName"
25918 ng-model="user.name"
25919 ng-model-options="{ debounce: 1000 }" />
25921 <button ng-click="userForm.userName.$rollbackViewValue(); user.name=''">Clear</button>
25924 <pre>user.name = <span ng-bind="user.name"></span></pre>
25927 <file name="app.js">
25928 angular.module('optionsExample', [])
25929 .controller('ExampleController', ['$scope', function($scope) {
25930 $scope.user = { name: 'Igor' };
25935 This one shows how to bind to getter/setters:
25937 <example name="ngModelOptions-directive-getter-setter" module="getterSetterExample">
25938 <file name="index.html">
25939 <div ng-controller="ExampleController">
25940 <form name="userForm">
25942 <input type="text" name="userName"
25943 ng-model="user.name"
25944 ng-model-options="{ getterSetter: true }" />
25947 <pre>user.name = <span ng-bind="user.name()"></span></pre>
25950 <file name="app.js">
25951 angular.module('getterSetterExample', [])
25952 .controller('ExampleController', ['$scope', function($scope) {
25953 var _name = 'Brian';
25955 name: function(newName) {
25956 // Note that newName can be undefined for two reasons:
25957 // 1. Because it is called as a getter and thus called with no arguments
25958 // 2. Because the property should actually be set to undefined. This happens e.g. if the
25959 // input is invalid
25960 return arguments.length ? (_name = newName) : _name;
25967 var ngModelOptionsDirective = function() {
25970 controller: ['$scope', '$attrs', function($scope, $attrs) {
25972 this.$options = copy($scope.$eval($attrs.ngModelOptions));
25973 // Allow adding/overriding bound events
25974 if (isDefined(this.$options.updateOn)) {
25975 this.$options.updateOnDefault = false;
25976 // extract "default" pseudo-event from list of events that can trigger a model update
25977 this.$options.updateOn = trim(this.$options.updateOn.replace(DEFAULT_REGEXP, function() {
25978 that.$options.updateOnDefault = true;
25982 this.$options.updateOnDefault = true;
25991 function addSetValidityMethod(context) {
25992 var ctrl = context.ctrl,
25993 $element = context.$element,
25996 unset = context.unset,
25997 $animate = context.$animate;
25999 classCache[INVALID_CLASS] = !(classCache[VALID_CLASS] = $element.hasClass(VALID_CLASS));
26001 ctrl.$setValidity = setValidity;
26003 function setValidity(validationErrorKey, state, controller) {
26004 if (isUndefined(state)) {
26005 createAndSet('$pending', validationErrorKey, controller);
26007 unsetAndCleanup('$pending', validationErrorKey, controller);
26009 if (!isBoolean(state)) {
26010 unset(ctrl.$error, validationErrorKey, controller);
26011 unset(ctrl.$$success, validationErrorKey, controller);
26014 unset(ctrl.$error, validationErrorKey, controller);
26015 set(ctrl.$$success, validationErrorKey, controller);
26017 set(ctrl.$error, validationErrorKey, controller);
26018 unset(ctrl.$$success, validationErrorKey, controller);
26021 if (ctrl.$pending) {
26022 cachedToggleClass(PENDING_CLASS, true);
26023 ctrl.$valid = ctrl.$invalid = undefined;
26024 toggleValidationCss('', null);
26026 cachedToggleClass(PENDING_CLASS, false);
26027 ctrl.$valid = isObjectEmpty(ctrl.$error);
26028 ctrl.$invalid = !ctrl.$valid;
26029 toggleValidationCss('', ctrl.$valid);
26032 // re-read the state as the set/unset methods could have
26033 // combined state in ctrl.$error[validationError] (used for forms),
26034 // where setting/unsetting only increments/decrements the value,
26035 // and does not replace it.
26037 if (ctrl.$pending && ctrl.$pending[validationErrorKey]) {
26038 combinedState = undefined;
26039 } else if (ctrl.$error[validationErrorKey]) {
26040 combinedState = false;
26041 } else if (ctrl.$$success[validationErrorKey]) {
26042 combinedState = true;
26044 combinedState = null;
26047 toggleValidationCss(validationErrorKey, combinedState);
26048 ctrl.$$parentForm.$setValidity(validationErrorKey, combinedState, ctrl);
26051 function createAndSet(name, value, controller) {
26055 set(ctrl[name], value, controller);
26058 function unsetAndCleanup(name, value, controller) {
26060 unset(ctrl[name], value, controller);
26062 if (isObjectEmpty(ctrl[name])) {
26063 ctrl[name] = undefined;
26067 function cachedToggleClass(className, switchValue) {
26068 if (switchValue && !classCache[className]) {
26069 $animate.addClass($element, className);
26070 classCache[className] = true;
26071 } else if (!switchValue && classCache[className]) {
26072 $animate.removeClass($element, className);
26073 classCache[className] = false;
26077 function toggleValidationCss(validationErrorKey, isValid) {
26078 validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : '';
26080 cachedToggleClass(VALID_CLASS + validationErrorKey, isValid === true);
26081 cachedToggleClass(INVALID_CLASS + validationErrorKey, isValid === false);
26085 function isObjectEmpty(obj) {
26087 for (var prop in obj) {
26088 if (obj.hasOwnProperty(prop)) {
26098 * @name ngNonBindable
26103 * The `ngNonBindable` directive tells Angular not to compile or bind the contents of the current
26104 * DOM element. This is useful if the element contains what appears to be Angular directives and
26105 * bindings but which should be ignored by Angular. This could be the case if you have a site that
26106 * displays snippets of code, for instance.
26111 * In this example there are two locations where a simple interpolation binding (`{{}}`) is present,
26112 * but the one wrapped in `ngNonBindable` is left alone.
26116 <file name="index.html">
26117 <div>Normal: {{1 + 2}}</div>
26118 <div ng-non-bindable>Ignored: {{1 + 2}}</div>
26120 <file name="protractor.js" type="protractor">
26121 it('should check ng-non-bindable', function() {
26122 expect(element(by.binding('1 + 2')).getText()).toContain('3');
26123 expect(element.all(by.css('div')).last().getText()).toMatch(/1 \+ 2/);
26128 var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 });
26130 /* global jqLiteRemove */
26132 var ngOptionsMinErr = minErr('ngOptions');
26141 * The `ngOptions` attribute can be used to dynamically generate a list of `<option>`
26142 * elements for the `<select>` element using the array or object obtained by evaluating the
26143 * `ngOptions` comprehension expression.
26145 * In many cases, `ngRepeat` can be used on `<option>` elements instead of `ngOptions` to achieve a
26146 * similar result. However, `ngOptions` provides some benefits such as reducing memory and
26147 * increasing speed by not creating a new scope for each repeated instance, as well as providing
26148 * more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
26149 * comprehension expression. `ngOptions` should be used when the `<select>` model needs to be bound
26150 * to a non-string value. This is because an option element can only be bound to string values at
26153 * When an item in the `<select>` menu is selected, the array element or object property
26154 * represented by the selected option will be bound to the model identified by the `ngModel`
26157 * Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
26158 * be nested into the `<select>` element. This element will then represent the `null` or "not selected"
26159 * option. See example below for demonstration.
26161 * ## Complex Models (objects or collections)
26163 * By default, `ngModel` watches the model by reference, not value. This is important to know when
26164 * binding the select to a model that is an object or a collection.
26166 * One issue occurs if you want to preselect an option. For example, if you set
26167 * the model to an object that is equal to an object in your collection, `ngOptions` won't be able to set the selection,
26168 * because the objects are not identical. So by default, you should always reference the item in your collection
26169 * for preselections, e.g.: `$scope.selected = $scope.collection[3]`.
26171 * Another solution is to use a `track by` clause, because then `ngOptions` will track the identity
26172 * of the item not by reference, but by the result of the `track by` expression. For example, if your
26173 * collection items have an id property, you would `track by item.id`.
26175 * A different issue with objects or collections is that ngModel won't detect if an object property or
26176 * a collection item changes. For that reason, `ngOptions` additionally watches the model using
26177 * `$watchCollection`, when the expression contains a `track by` clause or the the select has the `multiple` attribute.
26178 * This allows ngOptions to trigger a re-rendering of the options even if the actual object/collection
26179 * has not changed identity, but only a property on the object or an item in the collection changes.
26181 * Note that `$watchCollection` does a shallow comparison of the properties of the object (or the items in the collection
26182 * if the model is an array). This means that changing a property deeper than the first level inside the
26183 * object/collection will not trigger a re-rendering.
26185 * ## `select` **`as`**
26187 * Using `select` **`as`** will bind the result of the `select` expression to the model, but
26188 * the value of the `<select>` and `<option>` html elements will be either the index (for array data sources)
26189 * or property name (for object data sources) of the value within the collection. If a **`track by`** expression
26190 * is used, the result of that expression will be set as the value of the `option` and `select` elements.
26193 * ### `select` **`as`** and **`track by`**
26195 * <div class="alert alert-warning">
26196 * Be careful when using `select` **`as`** and **`track by`** in the same expression.
26199 * Given this array of items on the $scope:
26202 * $scope.items = [{
26205 * subItem: { name: 'aSubItem' }
26209 * subItem: { name: 'bSubItem' }
26216 * <select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>
26219 * $scope.selected = $scope.items[0];
26222 * but this will not work:
26225 * <select ng-options="item.subItem as item.label for item in items track by item.id" ng-model="selected"></select>
26228 * $scope.selected = $scope.items[0].subItem;
26231 * In both examples, the **`track by`** expression is applied successfully to each `item` in the
26232 * `items` array. Because the selected option has been set programmatically in the controller, the
26233 * **`track by`** expression is also applied to the `ngModel` value. In the first example, the
26234 * `ngModel` value is `items[0]` and the **`track by`** expression evaluates to `items[0].id` with
26235 * no issue. In the second example, the `ngModel` value is `items[0].subItem` and the **`track by`**
26236 * expression evaluates to `items[0].subItem.id` (which is undefined). As a result, the model value
26237 * is not matched against any `<option>` and the `<select>` appears as having no selected value.
26240 * @param {string} ngModel Assignable angular expression to data-bind to.
26241 * @param {string=} name Property name of the form under which the control is published.
26242 * @param {string=} required The control is considered valid only if value is entered.
26243 * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
26244 * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
26245 * `required` when you want to data-bind to the `required` attribute.
26246 * @param {comprehension_expression=} ngOptions in one of the following forms:
26248 * * for array data sources:
26249 * * `label` **`for`** `value` **`in`** `array`
26250 * * `select` **`as`** `label` **`for`** `value` **`in`** `array`
26251 * * `label` **`group by`** `group` **`for`** `value` **`in`** `array`
26252 * * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array`
26253 * * `label` **`group by`** `group` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
26254 * * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
26255 * * `label` **`for`** `value` **`in`** `array` | orderBy:`orderexpr` **`track by`** `trackexpr`
26256 * (for including a filter with `track by`)
26257 * * for object data sources:
26258 * * `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
26259 * * `select` **`as`** `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
26260 * * `label` **`group by`** `group` **`for (`**`key`**`,`** `value`**`) in`** `object`
26261 * * `label` **`disable when`** `disable` **`for (`**`key`**`,`** `value`**`) in`** `object`
26262 * * `select` **`as`** `label` **`group by`** `group`
26263 * **`for` `(`**`key`**`,`** `value`**`) in`** `object`
26264 * * `select` **`as`** `label` **`disable when`** `disable`
26265 * **`for` `(`**`key`**`,`** `value`**`) in`** `object`
26269 * * `array` / `object`: an expression which evaluates to an array / object to iterate over.
26270 * * `value`: local variable which will refer to each item in the `array` or each property value
26271 * of `object` during iteration.
26272 * * `key`: local variable which will refer to a property name in `object` during iteration.
26273 * * `label`: The result of this expression will be the label for `<option>` element. The
26274 * `expression` will most likely refer to the `value` variable (e.g. `value.propertyName`).
26275 * * `select`: The result of this expression will be bound to the model of the parent `<select>`
26276 * element. If not specified, `select` expression will default to `value`.
26277 * * `group`: The result of this expression will be used to group options using the `<optgroup>`
26279 * * `disable`: The result of this expression will be used to disable the rendered `<option>`
26280 * element. Return `true` to disable.
26281 * * `trackexpr`: Used when working with an array of objects. The result of this expression will be
26282 * used to identify the objects in the array. The `trackexpr` will most likely refer to the
26283 * `value` variable (e.g. `value.propertyName`). With this the selection is preserved
26284 * even when the options are recreated (e.g. reloaded from the server).
26287 <example module="selectExample">
26288 <file name="index.html">
26290 angular.module('selectExample', [])
26291 .controller('ExampleController', ['$scope', function($scope) {
26293 {name:'black', shade:'dark'},
26294 {name:'white', shade:'light', notAnOption: true},
26295 {name:'red', shade:'dark'},
26296 {name:'blue', shade:'dark', notAnOption: true},
26297 {name:'yellow', shade:'light', notAnOption: false}
26299 $scope.myColor = $scope.colors[2]; // red
26302 <div ng-controller="ExampleController">
26304 <li ng-repeat="color in colors">
26305 <label>Name: <input ng-model="color.name"></label>
26306 <label><input type="checkbox" ng-model="color.notAnOption"> Disabled?</label>
26307 <button ng-click="colors.splice($index, 1)" aria-label="Remove">X</button>
26310 <button ng-click="colors.push({})">add</button>
26314 <label>Color (null not allowed):
26315 <select ng-model="myColor" ng-options="color.name for color in colors"></select>
26317 <label>Color (null allowed):
26318 <span class="nullable">
26319 <select ng-model="myColor" ng-options="color.name for color in colors">
26320 <option value="">-- choose color --</option>
26322 </span></label><br/>
26324 <label>Color grouped by shade:
26325 <select ng-model="myColor" ng-options="color.name group by color.shade for color in colors">
26329 <label>Color grouped by shade, with some disabled:
26330 <select ng-model="myColor"
26331 ng-options="color.name group by color.shade disable when color.notAnOption for color in colors">
26337 Select <button ng-click="myColor = { name:'not in list', shade: 'other' }">bogus</button>.
26340 Currently selected: {{ {selected_color:myColor} }}
26341 <div style="border:solid 1px black; height:20px"
26342 ng-style="{'background-color':myColor.name}">
26346 <file name="protractor.js" type="protractor">
26347 it('should check ng-options', function() {
26348 expect(element(by.binding('{selected_color:myColor}')).getText()).toMatch('red');
26349 element.all(by.model('myColor')).first().click();
26350 element.all(by.css('select[ng-model="myColor"] option')).first().click();
26351 expect(element(by.binding('{selected_color:myColor}')).getText()).toMatch('black');
26352 element(by.css('.nullable select[ng-model="myColor"]')).click();
26353 element.all(by.css('.nullable select[ng-model="myColor"] option')).first().click();
26354 expect(element(by.binding('{selected_color:myColor}')).getText()).toMatch('null');
26360 // jshint maxlen: false
26361 // //00001111111111000000000002222222222000000000000000000000333333333300000000000000000000000004444444444400000000000005555555555555550000000006666666666666660000000777777777777777000000000000000888888888800000000000000000009999999999
26362 var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+disable\s+when\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/;
26363 // 1: value expression (valueFn)
26364 // 2: label expression (displayFn)
26365 // 3: group by expression (groupByFn)
26366 // 4: disable when expression (disableWhenFn)
26367 // 5: array item variable name
26368 // 6: object item key variable name
26369 // 7: object item value variable name
26370 // 8: collection expression
26371 // 9: track by expression
26372 // jshint maxlen: 100
26375 var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
26377 function parseOptionsExpression(optionsExp, selectElement, scope) {
26379 var match = optionsExp.match(NG_OPTIONS_REGEXP);
26381 throw ngOptionsMinErr('iexp',
26382 "Expected expression in form of " +
26383 "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
26384 " but got '{0}'. Element: {1}",
26385 optionsExp, startingTag(selectElement));
26388 // Extract the parts from the ngOptions expression
26390 // The variable name for the value of the item in the collection
26391 var valueName = match[5] || match[7];
26392 // The variable name for the key of the item in the collection
26393 var keyName = match[6];
26395 // An expression that generates the viewValue for an option if there is a label expression
26396 var selectAs = / as /.test(match[0]) && match[1];
26397 // An expression that is used to track the id of each object in the options collection
26398 var trackBy = match[9];
26399 // An expression that generates the viewValue for an option if there is no label expression
26400 var valueFn = $parse(match[2] ? match[1] : valueName);
26401 var selectAsFn = selectAs && $parse(selectAs);
26402 var viewValueFn = selectAsFn || valueFn;
26403 var trackByFn = trackBy && $parse(trackBy);
26405 // Get the value by which we are going to track the option
26406 // if we have a trackFn then use that (passing scope and locals)
26407 // otherwise just hash the given viewValue
26408 var getTrackByValueFn = trackBy ?
26409 function(value, locals) { return trackByFn(scope, locals); } :
26410 function getHashOfValue(value) { return hashKey(value); };
26411 var getTrackByValue = function(value, key) {
26412 return getTrackByValueFn(value, getLocals(value, key));
26415 var displayFn = $parse(match[2] || match[1]);
26416 var groupByFn = $parse(match[3] || '');
26417 var disableWhenFn = $parse(match[4] || '');
26418 var valuesFn = $parse(match[8]);
26421 var getLocals = keyName ? function(value, key) {
26422 locals[keyName] = key;
26423 locals[valueName] = value;
26425 } : function(value) {
26426 locals[valueName] = value;
26431 function Option(selectValue, viewValue, label, group, disabled) {
26432 this.selectValue = selectValue;
26433 this.viewValue = viewValue;
26434 this.label = label;
26435 this.group = group;
26436 this.disabled = disabled;
26439 function getOptionValuesKeys(optionValues) {
26440 var optionValuesKeys;
26442 if (!keyName && isArrayLike(optionValues)) {
26443 optionValuesKeys = optionValues;
26445 // if object, extract keys, in enumeration order, unsorted
26446 optionValuesKeys = [];
26447 for (var itemKey in optionValues) {
26448 if (optionValues.hasOwnProperty(itemKey) && itemKey.charAt(0) !== '$') {
26449 optionValuesKeys.push(itemKey);
26453 return optionValuesKeys;
26458 getTrackByValue: getTrackByValue,
26459 getWatchables: $parse(valuesFn, function(optionValues) {
26460 // Create a collection of things that we would like to watch (watchedArray)
26461 // so that they can all be watched using a single $watchCollection
26462 // that only runs the handler once if anything changes
26463 var watchedArray = [];
26464 optionValues = optionValues || [];
26466 var optionValuesKeys = getOptionValuesKeys(optionValues);
26467 var optionValuesLength = optionValuesKeys.length;
26468 for (var index = 0; index < optionValuesLength; index++) {
26469 var key = (optionValues === optionValuesKeys) ? index : optionValuesKeys[index];
26470 var value = optionValues[key];
26472 var locals = getLocals(optionValues[key], key);
26473 var selectValue = getTrackByValueFn(optionValues[key], locals);
26474 watchedArray.push(selectValue);
26476 // Only need to watch the displayFn if there is a specific label expression
26477 if (match[2] || match[1]) {
26478 var label = displayFn(scope, locals);
26479 watchedArray.push(label);
26482 // Only need to watch the disableWhenFn if there is a specific disable expression
26484 var disableWhen = disableWhenFn(scope, locals);
26485 watchedArray.push(disableWhen);
26488 return watchedArray;
26491 getOptions: function() {
26493 var optionItems = [];
26494 var selectValueMap = {};
26496 // The option values were already computed in the `getWatchables` fn,
26497 // which must have been called to trigger `getOptions`
26498 var optionValues = valuesFn(scope) || [];
26499 var optionValuesKeys = getOptionValuesKeys(optionValues);
26500 var optionValuesLength = optionValuesKeys.length;
26502 for (var index = 0; index < optionValuesLength; index++) {
26503 var key = (optionValues === optionValuesKeys) ? index : optionValuesKeys[index];
26504 var value = optionValues[key];
26505 var locals = getLocals(value, key);
26506 var viewValue = viewValueFn(scope, locals);
26507 var selectValue = getTrackByValueFn(viewValue, locals);
26508 var label = displayFn(scope, locals);
26509 var group = groupByFn(scope, locals);
26510 var disabled = disableWhenFn(scope, locals);
26511 var optionItem = new Option(selectValue, viewValue, label, group, disabled);
26513 optionItems.push(optionItem);
26514 selectValueMap[selectValue] = optionItem;
26518 items: optionItems,
26519 selectValueMap: selectValueMap,
26520 getOptionFromViewValue: function(value) {
26521 return selectValueMap[getTrackByValue(value)];
26523 getViewValueFromOption: function(option) {
26524 // If the viewValue could be an object that may be mutated by the application,
26525 // we need to make a copy and not return the reference to the value on the option.
26526 return trackBy ? angular.copy(option.viewValue) : option.viewValue;
26534 // we can't just jqLite('<option>') since jqLite is not smart enough
26535 // to create it in <select> and IE barfs otherwise.
26536 var optionTemplate = document.createElement('option'),
26537 optGroupTemplate = document.createElement('optgroup');
26540 function ngOptionsPostLink(scope, selectElement, attr, ctrls) {
26542 // if ngModel is not defined, we don't need to do anything
26543 var ngModelCtrl = ctrls[1];
26544 if (!ngModelCtrl) return;
26546 var selectCtrl = ctrls[0];
26547 var multiple = attr.multiple;
26549 // The emptyOption allows the application developer to provide their own custom "empty"
26550 // option when the viewValue does not match any of the option values.
26552 for (var i = 0, children = selectElement.children(), ii = children.length; i < ii; i++) {
26553 if (children[i].value === '') {
26554 emptyOption = children.eq(i);
26559 var providedEmptyOption = !!emptyOption;
26561 var unknownOption = jqLite(optionTemplate.cloneNode(false));
26562 unknownOption.val('?');
26565 var ngOptions = parseOptionsExpression(attr.ngOptions, selectElement, scope);
26568 var renderEmptyOption = function() {
26569 if (!providedEmptyOption) {
26570 selectElement.prepend(emptyOption);
26572 selectElement.val('');
26573 emptyOption.prop('selected', true); // needed for IE
26574 emptyOption.attr('selected', true);
26577 var removeEmptyOption = function() {
26578 if (!providedEmptyOption) {
26579 emptyOption.remove();
26584 var renderUnknownOption = function() {
26585 selectElement.prepend(unknownOption);
26586 selectElement.val('?');
26587 unknownOption.prop('selected', true); // needed for IE
26588 unknownOption.attr('selected', true);
26591 var removeUnknownOption = function() {
26592 unknownOption.remove();
26595 // Update the controller methods for multiple selectable options
26598 selectCtrl.writeValue = function writeNgOptionsValue(value) {
26599 var option = options.getOptionFromViewValue(value);
26601 if (option && !option.disabled) {
26602 if (selectElement[0].value !== option.selectValue) {
26603 removeUnknownOption();
26604 removeEmptyOption();
26606 selectElement[0].value = option.selectValue;
26607 option.element.selected = true;
26608 option.element.setAttribute('selected', 'selected');
26611 if (value === null || providedEmptyOption) {
26612 removeUnknownOption();
26613 renderEmptyOption();
26615 removeEmptyOption();
26616 renderUnknownOption();
26621 selectCtrl.readValue = function readNgOptionsValue() {
26623 var selectedOption = options.selectValueMap[selectElement.val()];
26625 if (selectedOption && !selectedOption.disabled) {
26626 removeEmptyOption();
26627 removeUnknownOption();
26628 return options.getViewValueFromOption(selectedOption);
26633 // If we are using `track by` then we must watch the tracked value on the model
26634 // since ngModel only watches for object identity change
26635 if (ngOptions.trackBy) {
26637 function() { return ngOptions.getTrackByValue(ngModelCtrl.$viewValue); },
26638 function() { ngModelCtrl.$render(); }
26644 ngModelCtrl.$isEmpty = function(value) {
26645 return !value || value.length === 0;
26649 selectCtrl.writeValue = function writeNgOptionsMultiple(value) {
26650 options.items.forEach(function(option) {
26651 option.element.selected = false;
26655 value.forEach(function(item) {
26656 var option = options.getOptionFromViewValue(item);
26657 if (option && !option.disabled) option.element.selected = true;
26663 selectCtrl.readValue = function readNgOptionsMultiple() {
26664 var selectedValues = selectElement.val() || [],
26667 forEach(selectedValues, function(value) {
26668 var option = options.selectValueMap[value];
26669 if (option && !option.disabled) selections.push(options.getViewValueFromOption(option));
26675 // If we are using `track by` then we must watch these tracked values on the model
26676 // since ngModel only watches for object identity change
26677 if (ngOptions.trackBy) {
26679 scope.$watchCollection(function() {
26680 if (isArray(ngModelCtrl.$viewValue)) {
26681 return ngModelCtrl.$viewValue.map(function(value) {
26682 return ngOptions.getTrackByValue(value);
26686 ngModelCtrl.$render();
26693 if (providedEmptyOption) {
26695 // we need to remove it before calling selectElement.empty() because otherwise IE will
26696 // remove the label from the element. wtf?
26697 emptyOption.remove();
26699 // compile the element since there might be bindings in it
26700 $compile(emptyOption)(scope);
26702 // remove the class, which is added automatically because we recompile the element and it
26703 // becomes the compilation root
26704 emptyOption.removeClass('ng-scope');
26706 emptyOption = jqLite(optionTemplate.cloneNode(false));
26709 // We need to do this here to ensure that the options object is defined
26710 // when we first hit it in writeNgOptionsValue
26713 // We will re-render the option elements if the option values or labels change
26714 scope.$watchCollection(ngOptions.getWatchables, updateOptions);
26716 // ------------------------------------------------------------------ //
26719 function updateOptionElement(option, element) {
26720 option.element = element;
26721 element.disabled = option.disabled;
26722 // NOTE: The label must be set before the value, otherwise IE10/11/EDGE create unresponsive
26723 // selects in certain circumstances when multiple selects are next to each other and display
26724 // the option list in listbox style, i.e. the select is [multiple], or specifies a [size].
26725 // See https://github.com/angular/angular.js/issues/11314 for more info.
26726 // This is unfortunately untestable with unit / e2e tests
26727 if (option.label !== element.label) {
26728 element.label = option.label;
26729 element.textContent = option.label;
26731 if (option.value !== element.value) element.value = option.selectValue;
26734 function addOrReuseElement(parent, current, type, templateElement) {
26736 // Check whether we can reuse the next element
26737 if (current && lowercase(current.nodeName) === type) {
26738 // The next element is the right type so reuse it
26741 // The next element is not the right type so create a new one
26742 element = templateElement.cloneNode(false);
26744 // There are no more elements so just append it to the select
26745 parent.appendChild(element);
26747 // The next element is not a group so insert the new one
26748 parent.insertBefore(element, current);
26755 function removeExcessElements(current) {
26758 next = current.nextSibling;
26759 jqLiteRemove(current);
26765 function skipEmptyAndUnknownOptions(current) {
26766 var emptyOption_ = emptyOption && emptyOption[0];
26767 var unknownOption_ = unknownOption && unknownOption[0];
26769 // We cannot rely on the extracted empty option being the same as the compiled empty option,
26770 // because the compiled empty option might have been replaced by a comment because
26771 // it had an "element" transclusion directive on it (such as ngIf)
26772 if (emptyOption_ || unknownOption_) {
26774 (current === emptyOption_ ||
26775 current === unknownOption_ ||
26776 current.nodeType === NODE_TYPE_COMMENT ||
26777 current.value === '')) {
26778 current = current.nextSibling;
26785 function updateOptions() {
26787 var previousValue = options && selectCtrl.readValue();
26789 options = ngOptions.getOptions();
26792 var currentElement = selectElement[0].firstChild;
26794 // Ensure that the empty option is always there if it was explicitly provided
26795 if (providedEmptyOption) {
26796 selectElement.prepend(emptyOption);
26799 currentElement = skipEmptyAndUnknownOptions(currentElement);
26801 options.items.forEach(function updateOption(option) {
26806 if (option.group) {
26808 // This option is to live in a group
26809 // See if we have already created this group
26810 group = groupMap[option.group];
26814 // We have not already created this group
26815 groupElement = addOrReuseElement(selectElement[0],
26819 // Move to the next element
26820 currentElement = groupElement.nextSibling;
26822 // Update the label on the group element
26823 groupElement.label = option.group;
26825 // Store it for use later
26826 group = groupMap[option.group] = {
26827 groupElement: groupElement,
26828 currentOptionElement: groupElement.firstChild
26833 // So now we have a group for this option we add the option to the group
26834 optionElement = addOrReuseElement(group.groupElement,
26835 group.currentOptionElement,
26838 updateOptionElement(option, optionElement);
26839 // Move to the next element
26840 group.currentOptionElement = optionElement.nextSibling;
26844 // This option is not in a group
26845 optionElement = addOrReuseElement(selectElement[0],
26849 updateOptionElement(option, optionElement);
26850 // Move to the next element
26851 currentElement = optionElement.nextSibling;
26856 // Now remove all excess options and group
26857 Object.keys(groupMap).forEach(function(key) {
26858 removeExcessElements(groupMap[key].currentOptionElement);
26860 removeExcessElements(currentElement);
26862 ngModelCtrl.$render();
26864 // Check to see if the value has changed due to the update to the options
26865 if (!ngModelCtrl.$isEmpty(previousValue)) {
26866 var nextValue = selectCtrl.readValue();
26867 if (ngOptions.trackBy ? !equals(previousValue, nextValue) : previousValue !== nextValue) {
26868 ngModelCtrl.$setViewValue(nextValue);
26869 ngModelCtrl.$render();
26879 require: ['select', '?ngModel'],
26881 pre: function ngOptionsPreLink(scope, selectElement, attr, ctrls) {
26882 // Deactivate the SelectController.register method to prevent
26883 // option directives from accidentally registering themselves
26884 // (and unwanted $destroy handlers etc.)
26885 ctrls[0].registerOption = noop;
26887 post: ngOptionsPostLink
26894 * @name ngPluralize
26898 * `ngPluralize` is a directive that displays messages according to en-US localization rules.
26899 * These rules are bundled with angular.js, but can be overridden
26900 * (see {@link guide/i18n Angular i18n} dev guide). You configure ngPluralize directive
26901 * by specifying the mappings between
26902 * [plural categories](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html)
26903 * and the strings to be displayed.
26905 * # Plural categories and explicit number rules
26907 * [plural categories](http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html)
26908 * in Angular's default en-US locale: "one" and "other".
26910 * While a plural category may match many numbers (for example, in en-US locale, "other" can match
26911 * any number that is not 1), an explicit number rule can only match one number. For example, the
26912 * explicit number rule for "3" matches the number 3. There are examples of plural categories
26913 * and explicit number rules throughout the rest of this documentation.
26915 * # Configuring ngPluralize
26916 * You configure ngPluralize by providing 2 attributes: `count` and `when`.
26917 * You can also provide an optional attribute, `offset`.
26919 * The value of the `count` attribute can be either a string or an {@link guide/expression
26920 * Angular expression}; these are evaluated on the current scope for its bound value.
26922 * The `when` attribute specifies the mappings between plural categories and the actual
26923 * string to be displayed. The value of the attribute should be a JSON object.
26925 * The following example shows how to configure ngPluralize:
26928 * <ng-pluralize count="personCount"
26929 when="{'0': 'Nobody is viewing.',
26930 * 'one': '1 person is viewing.',
26931 * 'other': '{} people are viewing.'}">
26935 * In the example, `"0: Nobody is viewing."` is an explicit number rule. If you did not
26936 * specify this rule, 0 would be matched to the "other" category and "0 people are viewing"
26937 * would be shown instead of "Nobody is viewing". You can specify an explicit number rule for
26938 * other numbers, for example 12, so that instead of showing "12 people are viewing", you can
26939 * show "a dozen people are viewing".
26941 * You can use a set of closed braces (`{}`) as a placeholder for the number that you want substituted
26942 * into pluralized strings. In the previous example, Angular will replace `{}` with
26943 * <span ng-non-bindable>`{{personCount}}`</span>. The closed braces `{}` is a placeholder
26944 * for <span ng-non-bindable>{{numberExpression}}</span>.
26946 * If no rule is defined for a category, then an empty string is displayed and a warning is generated.
26947 * Note that some locales define more categories than `one` and `other`. For example, fr-fr defines `few` and `many`.
26949 * # Configuring ngPluralize with offset
26950 * The `offset` attribute allows further customization of pluralized text, which can result in
26951 * a better user experience. For example, instead of the message "4 people are viewing this document",
26952 * you might display "John, Kate and 2 others are viewing this document".
26953 * The offset attribute allows you to offset a number by any desired value.
26954 * Let's take a look at an example:
26957 * <ng-pluralize count="personCount" offset=2
26958 * when="{'0': 'Nobody is viewing.',
26959 * '1': '{{person1}} is viewing.',
26960 * '2': '{{person1}} and {{person2}} are viewing.',
26961 * 'one': '{{person1}}, {{person2}} and one other person are viewing.',
26962 * 'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
26966 * Notice that we are still using two plural categories(one, other), but we added
26967 * three explicit number rules 0, 1 and 2.
26968 * When one person, perhaps John, views the document, "John is viewing" will be shown.
26969 * When three people view the document, no explicit number rule is found, so
26970 * an offset of 2 is taken off 3, and Angular uses 1 to decide the plural category.
26971 * In this case, plural category 'one' is matched and "John, Mary and one other person are viewing"
26974 * Note that when you specify offsets, you must provide explicit number rules for
26975 * numbers from 0 up to and including the offset. If you use an offset of 3, for example,
26976 * you must provide explicit number rules for 0, 1, 2 and 3. You must also provide plural strings for
26977 * plural categories "one" and "other".
26979 * @param {string|expression} count The variable to be bound to.
26980 * @param {string} when The mapping between plural category to its corresponding strings.
26981 * @param {number=} offset Offset to deduct from the total number.
26984 <example module="pluralizeExample">
26985 <file name="index.html">
26987 angular.module('pluralizeExample', [])
26988 .controller('ExampleController', ['$scope', function($scope) {
26989 $scope.person1 = 'Igor';
26990 $scope.person2 = 'Misko';
26991 $scope.personCount = 1;
26994 <div ng-controller="ExampleController">
26995 <label>Person 1:<input type="text" ng-model="person1" value="Igor" /></label><br/>
26996 <label>Person 2:<input type="text" ng-model="person2" value="Misko" /></label><br/>
26997 <label>Number of People:<input type="text" ng-model="personCount" value="1" /></label><br/>
26999 <!--- Example with simple pluralization rules for en locale --->
27001 <ng-pluralize count="personCount"
27002 when="{'0': 'Nobody is viewing.',
27003 'one': '1 person is viewing.',
27004 'other': '{} people are viewing.'}">
27005 </ng-pluralize><br>
27007 <!--- Example with offset --->
27009 <ng-pluralize count="personCount" offset=2
27010 when="{'0': 'Nobody is viewing.',
27011 '1': '{{person1}} is viewing.',
27012 '2': '{{person1}} and {{person2}} are viewing.',
27013 'one': '{{person1}}, {{person2}} and one other person are viewing.',
27014 'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
27018 <file name="protractor.js" type="protractor">
27019 it('should show correct pluralized string', function() {
27020 var withoutOffset = element.all(by.css('ng-pluralize')).get(0);
27021 var withOffset = element.all(by.css('ng-pluralize')).get(1);
27022 var countInput = element(by.model('personCount'));
27024 expect(withoutOffset.getText()).toEqual('1 person is viewing.');
27025 expect(withOffset.getText()).toEqual('Igor is viewing.');
27027 countInput.clear();
27028 countInput.sendKeys('0');
27030 expect(withoutOffset.getText()).toEqual('Nobody is viewing.');
27031 expect(withOffset.getText()).toEqual('Nobody is viewing.');
27033 countInput.clear();
27034 countInput.sendKeys('2');
27036 expect(withoutOffset.getText()).toEqual('2 people are viewing.');
27037 expect(withOffset.getText()).toEqual('Igor and Misko are viewing.');
27039 countInput.clear();
27040 countInput.sendKeys('3');
27042 expect(withoutOffset.getText()).toEqual('3 people are viewing.');
27043 expect(withOffset.getText()).toEqual('Igor, Misko and one other person are viewing.');
27045 countInput.clear();
27046 countInput.sendKeys('4');
27048 expect(withoutOffset.getText()).toEqual('4 people are viewing.');
27049 expect(withOffset.getText()).toEqual('Igor, Misko and 2 other people are viewing.');
27051 it('should show data-bound names', function() {
27052 var withOffset = element.all(by.css('ng-pluralize')).get(1);
27053 var personCount = element(by.model('personCount'));
27054 var person1 = element(by.model('person1'));
27055 var person2 = element(by.model('person2'));
27056 personCount.clear();
27057 personCount.sendKeys('4');
27059 person1.sendKeys('Di');
27061 person2.sendKeys('Vojta');
27062 expect(withOffset.getText()).toEqual('Di, Vojta and 2 other people are viewing.');
27067 var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale, $interpolate, $log) {
27069 IS_WHEN = /^when(Minus)?(.+)$/;
27072 link: function(scope, element, attr) {
27073 var numberExp = attr.count,
27074 whenExp = attr.$attr.when && element.attr(attr.$attr.when), // we have {{}} in attrs
27075 offset = attr.offset || 0,
27076 whens = scope.$eval(whenExp) || {},
27078 startSymbol = $interpolate.startSymbol(),
27079 endSymbol = $interpolate.endSymbol(),
27080 braceReplacement = startSymbol + numberExp + '-' + offset + endSymbol,
27081 watchRemover = angular.noop,
27084 forEach(attr, function(expression, attributeName) {
27085 var tmpMatch = IS_WHEN.exec(attributeName);
27087 var whenKey = (tmpMatch[1] ? '-' : '') + lowercase(tmpMatch[2]);
27088 whens[whenKey] = element.attr(attr.$attr[attributeName]);
27091 forEach(whens, function(expression, key) {
27092 whensExpFns[key] = $interpolate(expression.replace(BRACE, braceReplacement));
27096 scope.$watch(numberExp, function ngPluralizeWatchAction(newVal) {
27097 var count = parseFloat(newVal);
27098 var countIsNaN = isNaN(count);
27100 if (!countIsNaN && !(count in whens)) {
27101 // If an explicit number rule such as 1, 2, 3... is defined, just use it.
27102 // Otherwise, check it against pluralization rules in $locale service.
27103 count = $locale.pluralCat(count - offset);
27106 // If both `count` and `lastCount` are NaN, we don't need to re-register a watch.
27107 // In JS `NaN !== NaN`, so we have to exlicitly check.
27108 if ((count !== lastCount) && !(countIsNaN && isNumber(lastCount) && isNaN(lastCount))) {
27110 var whenExpFn = whensExpFns[count];
27111 if (isUndefined(whenExpFn)) {
27112 if (newVal != null) {
27113 $log.debug("ngPluralize: no rule defined for '" + count + "' in " + whenExp);
27115 watchRemover = noop;
27116 updateElementText();
27118 watchRemover = scope.$watch(whenExpFn, updateElementText);
27124 function updateElementText(newText) {
27125 element.text(newText || '');
27137 * The `ngRepeat` directive instantiates a template once per item from a collection. Each template
27138 * instance gets its own scope, where the given loop variable is set to the current collection item,
27139 * and `$index` is set to the item index or key.
27141 * Special properties are exposed on the local scope of each template instance, including:
27143 * | Variable | Type | Details |
27144 * |-----------|-----------------|-----------------------------------------------------------------------------|
27145 * | `$index` | {@type number} | iterator offset of the repeated element (0..length-1) |
27146 * | `$first` | {@type boolean} | true if the repeated element is first in the iterator. |
27147 * | `$middle` | {@type boolean} | true if the repeated element is between the first and last in the iterator. |
27148 * | `$last` | {@type boolean} | true if the repeated element is last in the iterator. |
27149 * | `$even` | {@type boolean} | true if the iterator position `$index` is even (otherwise false). |
27150 * | `$odd` | {@type boolean} | true if the iterator position `$index` is odd (otherwise false). |
27152 * <div class="alert alert-info">
27153 * Creating aliases for these properties is possible with {@link ng.directive:ngInit `ngInit`}.
27154 * This may be useful when, for instance, nesting ngRepeats.
27158 * # Iterating over object properties
27160 * It is possible to get `ngRepeat` to iterate over the properties of an object using the following
27164 * <div ng-repeat="(key, value) in myObj"> ... </div>
27167 * You need to be aware that the JavaScript specification does not define the order of keys
27168 * returned for an object. (To mitigate this in Angular 1.3 the `ngRepeat` directive
27169 * used to sort the keys alphabetically.)
27171 * Version 1.4 removed the alphabetic sorting. We now rely on the order returned by the browser
27172 * when running `for key in myObj`. It seems that browsers generally follow the strategy of providing
27173 * keys in the order in which they were defined, although there are exceptions when keys are deleted
27174 * and reinstated. See the [MDN page on `delete` for more info](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#Cross-browser_notes).
27176 * If this is not desired, the recommended workaround is to convert your object into an array
27177 * that is sorted into the order that you prefer before providing it to `ngRepeat`. You could
27178 * do this with a filter such as [toArrayFilter](http://ngmodules.org/modules/angular-toArrayFilter)
27179 * or implement a `$watch` on the object yourself.
27182 * # Tracking and Duplicates
27184 * `ngRepeat` uses {@link $rootScope.Scope#$watchCollection $watchCollection} to detect changes in
27185 * the collection. When a change happens, ngRepeat then makes the corresponding changes to the DOM:
27187 * * When an item is added, a new instance of the template is added to the DOM.
27188 * * When an item is removed, its template instance is removed from the DOM.
27189 * * When items are reordered, their respective templates are reordered in the DOM.
27191 * To minimize creation of DOM elements, `ngRepeat` uses a function
27192 * to "keep track" of all items in the collection and their corresponding DOM elements.
27193 * For example, if an item is added to the collection, ngRepeat will know that all other items
27194 * already have DOM elements, and will not re-render them.
27196 * The default tracking function (which tracks items by their identity) does not allow
27197 * duplicate items in arrays. This is because when there are duplicates, it is not possible
27198 * to maintain a one-to-one mapping between collection items and DOM elements.
27200 * If you do need to repeat duplicate items, you can substitute the default tracking behavior
27201 * with your own using the `track by` expression.
27203 * For example, you may track items by the index of each item in the collection, using the
27204 * special scope property `$index`:
27206 * <div ng-repeat="n in [42, 42, 43, 43] track by $index">
27211 * You may also use arbitrary expressions in `track by`, including references to custom functions
27214 * <div ng-repeat="n in [42, 42, 43, 43] track by myTrackingFunction(n)">
27219 * <div class="alert alert-success">
27220 * If you are working with objects that have an identifier property, you should track
27221 * by the identifier instead of the whole object. Should you reload your data later, `ngRepeat`
27222 * will not have to rebuild the DOM elements for items it has already rendered, even if the
27223 * JavaScript objects in the collection have been substituted for new ones. For large collections,
27224 * this signifincantly improves rendering performance. If you don't have a unique identifier,
27225 * `track by $index` can also provide a performance boost.
27228 * <div ng-repeat="model in collection track by model.id">
27233 * When no `track by` expression is provided, it is equivalent to tracking by the built-in
27234 * `$id` function, which tracks items by their identity:
27236 * <div ng-repeat="obj in collection track by $id(obj)">
27241 * <div class="alert alert-warning">
27242 * **Note:** `track by` must always be the last expression:
27245 * <div ng-repeat="model in collection | orderBy: 'id' as filtered_result track by model.id">
27250 * # Special repeat start and end points
27251 * To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
27252 * the range of the repeater by defining explicit start and end points by using **ng-repeat-start** and **ng-repeat-end** respectively.
27253 * The **ng-repeat-start** directive works the same as **ng-repeat**, but will repeat all the HTML code (including the tag it's defined on)
27254 * up to and including the ending HTML tag where **ng-repeat-end** is placed.
27256 * The example below makes use of this feature:
27258 * <header ng-repeat-start="item in items">
27259 * Header {{ item }}
27261 * <div class="body">
27264 * <footer ng-repeat-end>
27265 * Footer {{ item }}
27269 * And with an input of {@type ['A','B']} for the items variable in the example above, the output will evaluate to:
27274 * <div class="body">
27283 * <div class="body">
27291 * The custom start and end points for ngRepeat also support all other HTML directive syntax flavors provided in AngularJS (such
27292 * as **data-ng-repeat-start**, **x-ng-repeat-start** and **ng:repeat-start**).
27295 * **.enter** - when a new item is added to the list or when an item is revealed after a filter
27297 * **.leave** - when an item is removed from the list or when an item is filtered out
27299 * **.move** - when an adjacent item is filtered out causing a reorder or when the item contents are reordered
27304 * @param {repeat_expression} ngRepeat The expression indicating how to enumerate a collection. These
27305 * formats are currently supported:
27307 * * `variable in expression` – where variable is the user defined loop variable and `expression`
27308 * is a scope expression giving the collection to enumerate.
27310 * For example: `album in artist.albums`.
27312 * * `(key, value) in expression` – where `key` and `value` can be any user defined identifiers,
27313 * and `expression` is the scope expression giving the collection to enumerate.
27315 * For example: `(name, age) in {'adam':10, 'amalie':12}`.
27317 * * `variable in expression track by tracking_expression` – You can also provide an optional tracking expression
27318 * which can be used to associate the objects in the collection with the DOM elements. If no tracking expression
27319 * is specified, ng-repeat associates elements by identity. It is an error to have
27320 * more than one tracking expression value resolve to the same key. (This would mean that two distinct objects are
27321 * mapped to the same DOM element, which is not possible.)
27323 * Note that the tracking expression must come last, after any filters, and the alias expression.
27325 * For example: `item in items` is equivalent to `item in items track by $id(item)`. This implies that the DOM elements
27326 * will be associated by item identity in the array.
27328 * For example: `item in items track by $id(item)`. A built in `$id()` function can be used to assign a unique
27329 * `$$hashKey` property to each item in the array. This property is then used as a key to associated DOM elements
27330 * with the corresponding item in the array by identity. Moving the same object in array would move the DOM
27331 * element in the same way in the DOM.
27333 * For example: `item in items track by item.id` is a typical pattern when the items come from the database. In this
27334 * case the object identity does not matter. Two objects are considered equivalent as long as their `id`
27335 * property is same.
27337 * For example: `item in items | filter:searchText track by item.id` is a pattern that might be used to apply a filter
27338 * to items in conjunction with a tracking expression.
27340 * * `variable in expression as alias_expression` – You can also provide an optional alias expression which will then store the
27341 * intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message
27342 * when a filter is active on the repeater, but the filtered result set is empty.
27344 * For example: `item in items | filter:x as results` will store the fragment of the repeated items as `results`, but only after
27345 * the items have been processed through the filter.
27347 * Please note that `as [variable name] is not an operator but rather a part of ngRepeat micro-syntax so it can be used only at the end
27348 * (and not as operator, inside an expression).
27350 * For example: `item in items | filter : x | orderBy : order | limitTo : limit as results` .
27353 * This example initializes the scope to a list of names and
27354 * then uses `ngRepeat` to display every person:
27355 <example module="ngAnimate" deps="angular-animate.js" animations="true">
27356 <file name="index.html">
27357 <div ng-init="friends = [
27358 {name:'John', age:25, gender:'boy'},
27359 {name:'Jessie', age:30, gender:'girl'},
27360 {name:'Johanna', age:28, gender:'girl'},
27361 {name:'Joy', age:15, gender:'girl'},
27362 {name:'Mary', age:28, gender:'girl'},
27363 {name:'Peter', age:95, gender:'boy'},
27364 {name:'Sebastian', age:50, gender:'boy'},
27365 {name:'Erika', age:27, gender:'girl'},
27366 {name:'Patrick', age:40, gender:'boy'},
27367 {name:'Samantha', age:60, gender:'girl'}
27369 I have {{friends.length}} friends. They are:
27370 <input type="search" ng-model="q" placeholder="filter friends..." aria-label="filter friends" />
27371 <ul class="example-animate-container">
27372 <li class="animate-repeat" ng-repeat="friend in friends | filter:q as results">
27373 [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
27375 <li class="animate-repeat" ng-if="results.length == 0">
27376 <strong>No results found...</strong>
27381 <file name="animations.css">
27382 .example-animate-container {
27384 border:1px solid black;
27393 box-sizing:border-box;
27396 .animate-repeat.ng-move,
27397 .animate-repeat.ng-enter,
27398 .animate-repeat.ng-leave {
27399 transition:all linear 0.5s;
27402 .animate-repeat.ng-leave.ng-leave-active,
27403 .animate-repeat.ng-move,
27404 .animate-repeat.ng-enter {
27409 .animate-repeat.ng-leave,
27410 .animate-repeat.ng-move.ng-move-active,
27411 .animate-repeat.ng-enter.ng-enter-active {
27416 <file name="protractor.js" type="protractor">
27417 var friends = element.all(by.repeater('friend in friends'));
27419 it('should render initial data set', function() {
27420 expect(friends.count()).toBe(10);
27421 expect(friends.get(0).getText()).toEqual('[1] John who is 25 years old.');
27422 expect(friends.get(1).getText()).toEqual('[2] Jessie who is 30 years old.');
27423 expect(friends.last().getText()).toEqual('[10] Samantha who is 60 years old.');
27424 expect(element(by.binding('friends.length')).getText())
27425 .toMatch("I have 10 friends. They are:");
27428 it('should update repeater when filter predicate changes', function() {
27429 expect(friends.count()).toBe(10);
27431 element(by.model('q')).sendKeys('ma');
27433 expect(friends.count()).toBe(2);
27434 expect(friends.get(0).getText()).toEqual('[1] Mary who is 28 years old.');
27435 expect(friends.last().getText()).toEqual('[2] Samantha who is 60 years old.');
27440 var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
27441 var NG_REMOVED = '$$NG_REMOVED';
27442 var ngRepeatMinErr = minErr('ngRepeat');
27444 var updateScope = function(scope, index, valueIdentifier, value, keyIdentifier, key, arrayLength) {
27445 // TODO(perf): generate setters to shave off ~40ms or 1-1.5%
27446 scope[valueIdentifier] = value;
27447 if (keyIdentifier) scope[keyIdentifier] = key;
27448 scope.$index = index;
27449 scope.$first = (index === 0);
27450 scope.$last = (index === (arrayLength - 1));
27451 scope.$middle = !(scope.$first || scope.$last);
27452 // jshint bitwise: false
27453 scope.$odd = !(scope.$even = (index&1) === 0);
27454 // jshint bitwise: true
27457 var getBlockStart = function(block) {
27458 return block.clone[0];
27461 var getBlockEnd = function(block) {
27462 return block.clone[block.clone.length - 1];
27468 multiElement: true,
27469 transclude: 'element',
27473 compile: function ngRepeatCompile($element, $attr) {
27474 var expression = $attr.ngRepeat;
27475 var ngRepeatEndComment = document.createComment(' end ngRepeat: ' + expression + ' ');
27477 var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
27480 throw ngRepeatMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",
27484 var lhs = match[1];
27485 var rhs = match[2];
27486 var aliasAs = match[3];
27487 var trackByExp = match[4];
27489 match = lhs.match(/^(?:(\s*[\$\w]+)|\(\s*([\$\w]+)\s*,\s*([\$\w]+)\s*\))$/);
27492 throw ngRepeatMinErr('iidexp', "'_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got '{0}'.",
27495 var valueIdentifier = match[3] || match[1];
27496 var keyIdentifier = match[2];
27498 if (aliasAs && (!/^[$a-zA-Z_][$a-zA-Z0-9_]*$/.test(aliasAs) ||
27499 /^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent|\$root|\$id)$/.test(aliasAs))) {
27500 throw ngRepeatMinErr('badident', "alias '{0}' is invalid --- must be a valid JS identifier which is not a reserved name.",
27504 var trackByExpGetter, trackByIdExpFn, trackByIdArrayFn, trackByIdObjFn;
27505 var hashFnLocals = {$id: hashKey};
27508 trackByExpGetter = $parse(trackByExp);
27510 trackByIdArrayFn = function(key, value) {
27511 return hashKey(value);
27513 trackByIdObjFn = function(key) {
27518 return function ngRepeatLink($scope, $element, $attr, ctrl, $transclude) {
27520 if (trackByExpGetter) {
27521 trackByIdExpFn = function(key, value, index) {
27522 // assign key, value, and $index to the locals so that they can be used in hash functions
27523 if (keyIdentifier) hashFnLocals[keyIdentifier] = key;
27524 hashFnLocals[valueIdentifier] = value;
27525 hashFnLocals.$index = index;
27526 return trackByExpGetter($scope, hashFnLocals);
27530 // Store a list of elements from previous run. This is a hash where key is the item from the
27531 // iterator, and the value is objects with following properties.
27532 // - scope: bound scope
27533 // - element: previous element.
27534 // - index: position
27536 // We are using no-proto object so that we don't need to guard against inherited props via
27538 var lastBlockMap = createMap();
27541 $scope.$watchCollection(rhs, function ngRepeatAction(collection) {
27543 previousNode = $element[0], // node that cloned nodes should be inserted after
27544 // initialized to the comment node anchor
27546 // Same as lastBlockMap but it has the current state. It will become the
27547 // lastBlockMap on the next iteration.
27548 nextBlockMap = createMap(),
27550 key, value, // key/value of iteration
27554 block, // last object information {scope, element, id}
27559 $scope[aliasAs] = collection;
27562 if (isArrayLike(collection)) {
27563 collectionKeys = collection;
27564 trackByIdFn = trackByIdExpFn || trackByIdArrayFn;
27566 trackByIdFn = trackByIdExpFn || trackByIdObjFn;
27567 // if object, extract keys, in enumeration order, unsorted
27568 collectionKeys = [];
27569 for (var itemKey in collection) {
27570 if (hasOwnProperty.call(collection, itemKey) && itemKey.charAt(0) !== '$') {
27571 collectionKeys.push(itemKey);
27576 collectionLength = collectionKeys.length;
27577 nextBlockOrder = new Array(collectionLength);
27579 // locate existing items
27580 for (index = 0; index < collectionLength; index++) {
27581 key = (collection === collectionKeys) ? index : collectionKeys[index];
27582 value = collection[key];
27583 trackById = trackByIdFn(key, value, index);
27584 if (lastBlockMap[trackById]) {
27585 // found previously seen block
27586 block = lastBlockMap[trackById];
27587 delete lastBlockMap[trackById];
27588 nextBlockMap[trackById] = block;
27589 nextBlockOrder[index] = block;
27590 } else if (nextBlockMap[trackById]) {
27591 // if collision detected. restore lastBlockMap and throw an error
27592 forEach(nextBlockOrder, function(block) {
27593 if (block && block.scope) lastBlockMap[block.id] = block;
27595 throw ngRepeatMinErr('dupes',
27596 "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}, Duplicate value: {2}",
27597 expression, trackById, value);
27599 // new never before seen block
27600 nextBlockOrder[index] = {id: trackById, scope: undefined, clone: undefined};
27601 nextBlockMap[trackById] = true;
27605 // remove leftover items
27606 for (var blockKey in lastBlockMap) {
27607 block = lastBlockMap[blockKey];
27608 elementsToRemove = getBlockNodes(block.clone);
27609 $animate.leave(elementsToRemove);
27610 if (elementsToRemove[0].parentNode) {
27611 // if the element was not removed yet because of pending animation, mark it as deleted
27612 // so that we can ignore it later
27613 for (index = 0, length = elementsToRemove.length; index < length; index++) {
27614 elementsToRemove[index][NG_REMOVED] = true;
27617 block.scope.$destroy();
27620 // we are not using forEach for perf reasons (trying to avoid #call)
27621 for (index = 0; index < collectionLength; index++) {
27622 key = (collection === collectionKeys) ? index : collectionKeys[index];
27623 value = collection[key];
27624 block = nextBlockOrder[index];
27627 // if we have already seen this object, then we need to reuse the
27628 // associated scope/element
27630 nextNode = previousNode;
27632 // skip nodes that are already pending removal via leave animation
27634 nextNode = nextNode.nextSibling;
27635 } while (nextNode && nextNode[NG_REMOVED]);
27637 if (getBlockStart(block) != nextNode) {
27638 // existing item which got moved
27639 $animate.move(getBlockNodes(block.clone), null, jqLite(previousNode));
27641 previousNode = getBlockEnd(block);
27642 updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
27644 // new item which we don't know about
27645 $transclude(function ngRepeatTransclude(clone, scope) {
27646 block.scope = scope;
27647 // http://jsperf.com/clone-vs-createcomment
27648 var endNode = ngRepeatEndComment.cloneNode(false);
27649 clone[clone.length++] = endNode;
27651 // TODO(perf): support naked previousNode in `enter` to avoid creation of jqLite wrapper?
27652 $animate.enter(clone, null, jqLite(previousNode));
27653 previousNode = endNode;
27654 // Note: We only need the first/last node of the cloned nodes.
27655 // However, we need to keep the reference to the jqlite wrapper as it might be changed later
27656 // by a directive with templateUrl when its template arrives.
27657 block.clone = clone;
27658 nextBlockMap[block.id] = block;
27659 updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
27663 lastBlockMap = nextBlockMap;
27670 var NG_HIDE_CLASS = 'ng-hide';
27671 var NG_HIDE_IN_PROGRESS_CLASS = 'ng-hide-animate';
27678 * The `ngShow` directive shows or hides the given HTML element based on the expression
27679 * provided to the `ngShow` attribute. The element is shown or hidden by removing or adding
27680 * the `.ng-hide` CSS class onto the element. The `.ng-hide` CSS class is predefined
27681 * in AngularJS and sets the display style to none (using an !important flag).
27682 * For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
27685 * <!-- when $scope.myValue is truthy (element is visible) -->
27686 * <div ng-show="myValue"></div>
27688 * <!-- when $scope.myValue is falsy (element is hidden) -->
27689 * <div ng-show="myValue" class="ng-hide"></div>
27692 * When the `ngShow` expression evaluates to a falsy value then the `.ng-hide` CSS class is added to the class
27693 * attribute on the element causing it to become hidden. When truthy, the `.ng-hide` CSS class is removed
27694 * from the element causing the element not to appear hidden.
27696 * ## Why is !important used?
27698 * You may be wondering why !important is used for the `.ng-hide` CSS class. This is because the `.ng-hide` selector
27699 * can be easily overridden by heavier selectors. For example, something as simple
27700 * as changing the display style on a HTML list item would make hidden elements appear visible.
27701 * This also becomes a bigger issue when dealing with CSS frameworks.
27703 * By using !important, the show and hide behavior will work as expected despite any clash between CSS selector
27704 * specificity (when !important isn't used with any conflicting styles). If a developer chooses to override the
27705 * styling to change how to hide an element then it is just a matter of using !important in their own CSS code.
27707 * ### Overriding `.ng-hide`
27709 * By default, the `.ng-hide` class will style the element with `display: none!important`. If you wish to change
27710 * the hide behavior with ngShow/ngHide then this can be achieved by restating the styles for the `.ng-hide`
27711 * class CSS. Note that the selector that needs to be used is actually `.ng-hide:not(.ng-hide-animate)` to cope
27712 * with extra animation classes that can be added.
27715 * .ng-hide:not(.ng-hide-animate) {
27716 * /* this is just another form of hiding an element */
27717 * display: block!important;
27718 * position: absolute;
27724 * By default you don't need to override in CSS anything and the animations will work around the display style.
27726 * ## A note about animations with `ngShow`
27728 * Animations in ngShow/ngHide work with the show and hide events that are triggered when the directive expression
27729 * is true and false. This system works like the animation system present with ngClass except that
27730 * you must also include the !important flag to override the display property
27731 * so that you can perform an animation when the element is hidden during the time of the animation.
27735 * //a working example can be found at the bottom of this page
27737 * .my-element.ng-hide-add, .my-element.ng-hide-remove {
27738 * /* this is required as of 1.3x to properly
27739 * apply all styling in a show/hide animation */
27740 * transition: 0s linear all;
27743 * .my-element.ng-hide-add-active,
27744 * .my-element.ng-hide-remove-active {
27745 * /* the transition is defined in the active class */
27746 * transition: 1s linear all;
27749 * .my-element.ng-hide-add { ... }
27750 * .my-element.ng-hide-add.ng-hide-add-active { ... }
27751 * .my-element.ng-hide-remove { ... }
27752 * .my-element.ng-hide-remove.ng-hide-remove-active { ... }
27755 * Keep in mind that, as of AngularJS version 1.3.0-beta.11, there is no need to change the display
27756 * property to block during animation states--ngAnimate will handle the style toggling automatically for you.
27759 * addClass: `.ng-hide` - happens after the `ngShow` expression evaluates to a truthy value and the just before contents are set to visible
27760 * removeClass: `.ng-hide` - happens after the `ngShow` expression evaluates to a non truthy value and just before the contents are set to hidden
27763 * @param {expression} ngShow If the {@link guide/expression expression} is truthy
27764 * then the element is shown or hidden respectively.
27767 <example module="ngAnimate" deps="angular-animate.js" animations="true">
27768 <file name="index.html">
27769 Click me: <input type="checkbox" ng-model="checked" aria-label="Toggle ngHide"><br/>
27772 <div class="check-element animate-show" ng-show="checked">
27773 <span class="glyphicon glyphicon-thumbs-up"></span> I show up when your checkbox is checked.
27778 <div class="check-element animate-show" ng-hide="checked">
27779 <span class="glyphicon glyphicon-thumbs-down"></span> I hide when your checkbox is checked.
27783 <file name="glyphicons.css">
27784 @import url(../../components/bootstrap-3.1.1/css/bootstrap.css);
27786 <file name="animations.css">
27791 border: 1px solid black;
27795 .animate-show.ng-hide-add, .animate-show.ng-hide-remove {
27796 transition: all linear 0.5s;
27799 .animate-show.ng-hide {
27807 border: 1px solid black;
27811 <file name="protractor.js" type="protractor">
27812 var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
27813 var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));
27815 it('should check ng-show / ng-hide', function() {
27816 expect(thumbsUp.isDisplayed()).toBeFalsy();
27817 expect(thumbsDown.isDisplayed()).toBeTruthy();
27819 element(by.model('checked')).click();
27821 expect(thumbsUp.isDisplayed()).toBeTruthy();
27822 expect(thumbsDown.isDisplayed()).toBeFalsy();
27827 var ngShowDirective = ['$animate', function($animate) {
27830 multiElement: true,
27831 link: function(scope, element, attr) {
27832 scope.$watch(attr.ngShow, function ngShowWatchAction(value) {
27833 // we're adding a temporary, animation-specific class for ng-hide since this way
27834 // we can control when the element is actually displayed on screen without having
27835 // to have a global/greedy CSS selector that breaks when other animations are run.
27836 // Read: https://github.com/angular/angular.js/issues/9103#issuecomment-58335845
27837 $animate[value ? 'removeClass' : 'addClass'](element, NG_HIDE_CLASS, {
27838 tempClasses: NG_HIDE_IN_PROGRESS_CLASS
27852 * The `ngHide` directive shows or hides the given HTML element based on the expression
27853 * provided to the `ngHide` attribute. The element is shown or hidden by removing or adding
27854 * the `ng-hide` CSS class onto the element. The `.ng-hide` CSS class is predefined
27855 * in AngularJS and sets the display style to none (using an !important flag).
27856 * For CSP mode please add `angular-csp.css` to your html file (see {@link ng.directive:ngCsp ngCsp}).
27859 * <!-- when $scope.myValue is truthy (element is hidden) -->
27860 * <div ng-hide="myValue" class="ng-hide"></div>
27862 * <!-- when $scope.myValue is falsy (element is visible) -->
27863 * <div ng-hide="myValue"></div>
27866 * When the `ngHide` expression evaluates to a truthy value then the `.ng-hide` CSS class is added to the class
27867 * attribute on the element causing it to become hidden. When falsy, the `.ng-hide` CSS class is removed
27868 * from the element causing the element not to appear hidden.
27870 * ## Why is !important used?
27872 * You may be wondering why !important is used for the `.ng-hide` CSS class. This is because the `.ng-hide` selector
27873 * can be easily overridden by heavier selectors. For example, something as simple
27874 * as changing the display style on a HTML list item would make hidden elements appear visible.
27875 * This also becomes a bigger issue when dealing with CSS frameworks.
27877 * By using !important, the show and hide behavior will work as expected despite any clash between CSS selector
27878 * specificity (when !important isn't used with any conflicting styles). If a developer chooses to override the
27879 * styling to change how to hide an element then it is just a matter of using !important in their own CSS code.
27881 * ### Overriding `.ng-hide`
27883 * By default, the `.ng-hide` class will style the element with `display: none!important`. If you wish to change
27884 * the hide behavior with ngShow/ngHide then this can be achieved by restating the styles for the `.ng-hide`
27889 * /* this is just another form of hiding an element */
27890 * display: block!important;
27891 * position: absolute;
27897 * By default you don't need to override in CSS anything and the animations will work around the display style.
27899 * ## A note about animations with `ngHide`
27901 * Animations in ngShow/ngHide work with the show and hide events that are triggered when the directive expression
27902 * is true and false. This system works like the animation system present with ngClass, except that the `.ng-hide`
27903 * CSS class is added and removed for you instead of your own CSS class.
27907 * //a working example can be found at the bottom of this page
27909 * .my-element.ng-hide-add, .my-element.ng-hide-remove {
27910 * transition: 0.5s linear all;
27913 * .my-element.ng-hide-add { ... }
27914 * .my-element.ng-hide-add.ng-hide-add-active { ... }
27915 * .my-element.ng-hide-remove { ... }
27916 * .my-element.ng-hide-remove.ng-hide-remove-active { ... }
27919 * Keep in mind that, as of AngularJS version 1.3.0-beta.11, there is no need to change the display
27920 * property to block during animation states--ngAnimate will handle the style toggling automatically for you.
27923 * removeClass: `.ng-hide` - happens after the `ngHide` expression evaluates to a truthy value and just before the contents are set to hidden
27924 * addClass: `.ng-hide` - happens after the `ngHide` expression evaluates to a non truthy value and just before the contents are set to visible
27927 * @param {expression} ngHide If the {@link guide/expression expression} is truthy then
27928 * the element is shown or hidden respectively.
27931 <example module="ngAnimate" deps="angular-animate.js" animations="true">
27932 <file name="index.html">
27933 Click me: <input type="checkbox" ng-model="checked" aria-label="Toggle ngShow"><br/>
27936 <div class="check-element animate-hide" ng-show="checked">
27937 <span class="glyphicon glyphicon-thumbs-up"></span> I show up when your checkbox is checked.
27942 <div class="check-element animate-hide" ng-hide="checked">
27943 <span class="glyphicon glyphicon-thumbs-down"></span> I hide when your checkbox is checked.
27947 <file name="glyphicons.css">
27948 @import url(../../components/bootstrap-3.1.1/css/bootstrap.css);
27950 <file name="animations.css">
27952 transition: all linear 0.5s;
27956 border: 1px solid black;
27960 .animate-hide.ng-hide {
27968 border: 1px solid black;
27972 <file name="protractor.js" type="protractor">
27973 var thumbsUp = element(by.css('span.glyphicon-thumbs-up'));
27974 var thumbsDown = element(by.css('span.glyphicon-thumbs-down'));
27976 it('should check ng-show / ng-hide', function() {
27977 expect(thumbsUp.isDisplayed()).toBeFalsy();
27978 expect(thumbsDown.isDisplayed()).toBeTruthy();
27980 element(by.model('checked')).click();
27982 expect(thumbsUp.isDisplayed()).toBeTruthy();
27983 expect(thumbsDown.isDisplayed()).toBeFalsy();
27988 var ngHideDirective = ['$animate', function($animate) {
27991 multiElement: true,
27992 link: function(scope, element, attr) {
27993 scope.$watch(attr.ngHide, function ngHideWatchAction(value) {
27994 // The comment inside of the ngShowDirective explains why we add and
27995 // remove a temporary class for the show/hide animation
27996 $animate[value ? 'addClass' : 'removeClass'](element,NG_HIDE_CLASS, {
27997 tempClasses: NG_HIDE_IN_PROGRESS_CLASS
28010 * The `ngStyle` directive allows you to set CSS style on an HTML element conditionally.
28013 * @param {expression} ngStyle
28015 * {@link guide/expression Expression} which evals to an
28016 * object whose keys are CSS style names and values are corresponding values for those CSS
28019 * Since some CSS style names are not valid keys for an object, they must be quoted.
28020 * See the 'background-color' style in the example below.
28024 <file name="index.html">
28025 <input type="button" value="set color" ng-click="myStyle={color:'red'}">
28026 <input type="button" value="set background" ng-click="myStyle={'background-color':'blue'}">
28027 <input type="button" value="clear" ng-click="myStyle={}">
28029 <span ng-style="myStyle">Sample Text</span>
28030 <pre>myStyle={{myStyle}}</pre>
28032 <file name="style.css">
28037 <file name="protractor.js" type="protractor">
28038 var colorSpan = element(by.css('span'));
28040 it('should check ng-style', function() {
28041 expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)');
28042 element(by.css('input[value=\'set color\']')).click();
28043 expect(colorSpan.getCssValue('color')).toBe('rgba(255, 0, 0, 1)');
28044 element(by.css('input[value=clear]')).click();
28045 expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)');
28050 var ngStyleDirective = ngDirective(function(scope, element, attr) {
28051 scope.$watch(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) {
28052 if (oldStyles && (newStyles !== oldStyles)) {
28053 forEach(oldStyles, function(val, style) { element.css(style, '');});
28055 if (newStyles) element.css(newStyles);
28065 * The `ngSwitch` directive is used to conditionally swap DOM structure on your template based on a scope expression.
28066 * Elements within `ngSwitch` but without `ngSwitchWhen` or `ngSwitchDefault` directives will be preserved at the location
28067 * as specified in the template.
28069 * The directive itself works similar to ngInclude, however, instead of downloading template code (or loading it
28070 * from the template cache), `ngSwitch` simply chooses one of the nested elements and makes it visible based on which element
28071 * matches the value obtained from the evaluated expression. In other words, you define a container element
28072 * (where you place the directive), place an expression on the **`on="..."` attribute**
28073 * (or the **`ng-switch="..."` attribute**), define any inner elements inside of the directive and place
28074 * a when attribute per element. The when attribute is used to inform ngSwitch which element to display when the on
28075 * expression is evaluated. If a matching expression is not found via a when attribute then an element with the default
28076 * attribute is displayed.
28078 * <div class="alert alert-info">
28079 * Be aware that the attribute values to match against cannot be expressions. They are interpreted
28080 * as literal string values to match against.
28081 * For example, **`ng-switch-when="someVal"`** will match against the string `"someVal"` not against the
28082 * value of the expression `$scope.someVal`.
28086 * enter - happens after the ngSwitch contents change and the matched child element is placed inside the container
28087 * leave - happens just after the ngSwitch contents change and just before the former contents are removed from the DOM
28092 * <ANY ng-switch="expression">
28093 * <ANY ng-switch-when="matchValue1">...</ANY>
28094 * <ANY ng-switch-when="matchValue2">...</ANY>
28095 * <ANY ng-switch-default>...</ANY>
28102 * @param {*} ngSwitch|on expression to match against <code>ng-switch-when</code>.
28103 * On child elements add:
28105 * * `ngSwitchWhen`: the case statement to match against. If match then this
28106 * case will be displayed. If the same match appears multiple times, all the
28107 * elements will be displayed.
28108 * * `ngSwitchDefault`: the default case when no other case match. If there
28109 * are multiple default cases, all of them will be displayed when no other
28114 <example module="switchExample" deps="angular-animate.js" animations="true">
28115 <file name="index.html">
28116 <div ng-controller="ExampleController">
28117 <select ng-model="selection" ng-options="item for item in items">
28119 <code>selection={{selection}}</code>
28121 <div class="animate-switch-container"
28122 ng-switch on="selection">
28123 <div class="animate-switch" ng-switch-when="settings">Settings Div</div>
28124 <div class="animate-switch" ng-switch-when="home">Home Span</div>
28125 <div class="animate-switch" ng-switch-default>default</div>
28129 <file name="script.js">
28130 angular.module('switchExample', ['ngAnimate'])
28131 .controller('ExampleController', ['$scope', function($scope) {
28132 $scope.items = ['settings', 'home', 'other'];
28133 $scope.selection = $scope.items[0];
28136 <file name="animations.css">
28137 .animate-switch-container {
28140 border:1px solid black;
28149 .animate-switch.ng-animate {
28150 transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
28159 .animate-switch.ng-leave.ng-leave-active,
28160 .animate-switch.ng-enter {
28163 .animate-switch.ng-leave,
28164 .animate-switch.ng-enter.ng-enter-active {
28168 <file name="protractor.js" type="protractor">
28169 var switchElem = element(by.css('[ng-switch]'));
28170 var select = element(by.model('selection'));
28172 it('should start in settings', function() {
28173 expect(switchElem.getText()).toMatch(/Settings Div/);
28175 it('should change to home', function() {
28176 select.all(by.css('option')).get(1).click();
28177 expect(switchElem.getText()).toMatch(/Home Span/);
28179 it('should select default', function() {
28180 select.all(by.css('option')).get(2).click();
28181 expect(switchElem.getText()).toMatch(/default/);
28186 var ngSwitchDirective = ['$animate', function($animate) {
28188 require: 'ngSwitch',
28190 // asks for $scope to fool the BC controller module
28191 controller: ['$scope', function ngSwitchController() {
28194 link: function(scope, element, attr, ngSwitchController) {
28195 var watchExpr = attr.ngSwitch || attr.on,
28196 selectedTranscludes = [],
28197 selectedElements = [],
28198 previousLeaveAnimations = [],
28199 selectedScopes = [];
28201 var spliceFactory = function(array, index) {
28202 return function() { array.splice(index, 1); };
28205 scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
28207 for (i = 0, ii = previousLeaveAnimations.length; i < ii; ++i) {
28208 $animate.cancel(previousLeaveAnimations[i]);
28210 previousLeaveAnimations.length = 0;
28212 for (i = 0, ii = selectedScopes.length; i < ii; ++i) {
28213 var selected = getBlockNodes(selectedElements[i].clone);
28214 selectedScopes[i].$destroy();
28215 var promise = previousLeaveAnimations[i] = $animate.leave(selected);
28216 promise.then(spliceFactory(previousLeaveAnimations, i));
28219 selectedElements.length = 0;
28220 selectedScopes.length = 0;
28222 if ((selectedTranscludes = ngSwitchController.cases['!' + value] || ngSwitchController.cases['?'])) {
28223 forEach(selectedTranscludes, function(selectedTransclude) {
28224 selectedTransclude.transclude(function(caseElement, selectedScope) {
28225 selectedScopes.push(selectedScope);
28226 var anchor = selectedTransclude.element;
28227 caseElement[caseElement.length++] = document.createComment(' end ngSwitchWhen: ');
28228 var block = { clone: caseElement };
28230 selectedElements.push(block);
28231 $animate.enter(caseElement, anchor.parent(), anchor);
28240 var ngSwitchWhenDirective = ngDirective({
28241 transclude: 'element',
28243 require: '^ngSwitch',
28244 multiElement: true,
28245 link: function(scope, element, attrs, ctrl, $transclude) {
28246 ctrl.cases['!' + attrs.ngSwitchWhen] = (ctrl.cases['!' + attrs.ngSwitchWhen] || []);
28247 ctrl.cases['!' + attrs.ngSwitchWhen].push({ transclude: $transclude, element: element });
28251 var ngSwitchDefaultDirective = ngDirective({
28252 transclude: 'element',
28254 require: '^ngSwitch',
28255 multiElement: true,
28256 link: function(scope, element, attr, ctrl, $transclude) {
28257 ctrl.cases['?'] = (ctrl.cases['?'] || []);
28258 ctrl.cases['?'].push({ transclude: $transclude, element: element });
28264 * @name ngTransclude
28268 * Directive that marks the insertion point for the transcluded DOM of the nearest parent directive that uses transclusion.
28270 * Any existing content of the element that this directive is placed on will be removed before the transcluded content is inserted.
28275 <example module="transcludeExample">
28276 <file name="index.html">
28278 angular.module('transcludeExample', [])
28279 .directive('pane', function(){
28283 scope: { title:'@' },
28284 template: '<div style="border: 1px solid black;">' +
28285 '<div style="background-color: gray">{{title}}</div>' +
28286 '<ng-transclude></ng-transclude>' +
28290 .controller('ExampleController', ['$scope', function($scope) {
28291 $scope.title = 'Lorem Ipsum';
28292 $scope.text = 'Neque porro quisquam est qui dolorem ipsum quia dolor...';
28295 <div ng-controller="ExampleController">
28296 <input ng-model="title" aria-label="title"> <br/>
28297 <textarea ng-model="text" aria-label="text"></textarea> <br/>
28298 <pane title="{{title}}">{{text}}</pane>
28301 <file name="protractor.js" type="protractor">
28302 it('should have transcluded', function() {
28303 var titleElement = element(by.model('title'));
28304 titleElement.clear();
28305 titleElement.sendKeys('TITLE');
28306 var textElement = element(by.model('text'));
28307 textElement.clear();
28308 textElement.sendKeys('TEXT');
28309 expect(element(by.binding('title')).getText()).toEqual('TITLE');
28310 expect(element(by.binding('text')).getText()).toEqual('TEXT');
28316 var ngTranscludeDirective = ngDirective({
28318 link: function($scope, $element, $attrs, controller, $transclude) {
28319 if (!$transclude) {
28320 throw minErr('ngTransclude')('orphan',
28321 'Illegal use of ngTransclude directive in the template! ' +
28322 'No parent directive that requires a transclusion found. ' +
28324 startingTag($element));
28327 $transclude(function(clone) {
28329 $element.append(clone);
28340 * Load the content of a `<script>` element into {@link ng.$templateCache `$templateCache`}, so that the
28341 * template can be used by {@link ng.directive:ngInclude `ngInclude`},
28342 * {@link ngRoute.directive:ngView `ngView`}, or {@link guide/directive directives}. The type of the
28343 * `<script>` element must be specified as `text/ng-template`, and a cache name for the template must be
28344 * assigned through the element's `id`, which can then be used as a directive's `templateUrl`.
28346 * @param {string} type Must be set to `'text/ng-template'`.
28347 * @param {string} id Cache name of the template.
28351 <file name="index.html">
28352 <script type="text/ng-template" id="/tpl.html">
28353 Content of the template.
28356 <a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
28357 <div id="tpl-content" ng-include src="currentTpl"></div>
28359 <file name="protractor.js" type="protractor">
28360 it('should load template defined inside script tag', function() {
28361 element(by.css('#tpl-link')).click();
28362 expect(element(by.css('#tpl-content')).getText()).toMatch(/Content of the template/);
28367 var scriptDirective = ['$templateCache', function($templateCache) {
28371 compile: function(element, attr) {
28372 if (attr.type == 'text/ng-template') {
28373 var templateUrl = attr.id,
28374 text = element[0].text;
28376 $templateCache.put(templateUrl, text);
28382 var noopNgModelController = { $setViewValue: noop, $render: noop };
28384 function chromeHack(optionElement) {
28385 // Workaround for https://code.google.com/p/chromium/issues/detail?id=381459
28386 // Adding an <option selected="selected"> element to a <select required="required"> should
28387 // automatically select the new element
28388 if (optionElement[0].hasAttribute('selected')) {
28389 optionElement[0].selected = true;
28395 * @name select.SelectController
28397 * The controller for the `<select>` directive. This provides support for reading
28398 * and writing the selected value(s) of the control and also coordinates dynamically
28399 * added `<option>` elements, perhaps by an `ngRepeat` directive.
28401 var SelectController =
28402 ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
28405 optionsMap = new HashMap();
28407 // If the ngModel doesn't get provided then provide a dummy noop version to prevent errors
28408 self.ngModelCtrl = noopNgModelController;
28410 // The "unknown" option is one that is prepended to the list if the viewValue
28411 // does not match any of the options. When it is rendered the value of the unknown
28412 // option is '? XXX ?' where XXX is the hashKey of the value that is not known.
28414 // We can't just jqLite('<option>') since jqLite is not smart enough
28415 // to create it in <select> and IE barfs otherwise.
28416 self.unknownOption = jqLite(document.createElement('option'));
28417 self.renderUnknownOption = function(val) {
28418 var unknownVal = '? ' + hashKey(val) + ' ?';
28419 self.unknownOption.val(unknownVal);
28420 $element.prepend(self.unknownOption);
28421 $element.val(unknownVal);
28424 $scope.$on('$destroy', function() {
28425 // disable unknown option so that we don't do work when the whole select is being destroyed
28426 self.renderUnknownOption = noop;
28429 self.removeUnknownOption = function() {
28430 if (self.unknownOption.parent()) self.unknownOption.remove();
28434 // Read the value of the select control, the implementation of this changes depending
28435 // upon whether the select can have multiple values and whether ngOptions is at work.
28436 self.readValue = function readSingleValue() {
28437 self.removeUnknownOption();
28438 return $element.val();
28442 // Write the value to the select control, the implementation of this changes depending
28443 // upon whether the select can have multiple values and whether ngOptions is at work.
28444 self.writeValue = function writeSingleValue(value) {
28445 if (self.hasOption(value)) {
28446 self.removeUnknownOption();
28447 $element.val(value);
28448 if (value === '') self.emptyOption.prop('selected', true); // to make IE9 happy
28450 if (value == null && self.emptyOption) {
28451 self.removeUnknownOption();
28454 self.renderUnknownOption(value);
28460 // Tell the select control that an option, with the given value, has been added
28461 self.addOption = function(value, element) {
28462 assertNotHasOwnProperty(value, '"option value"');
28463 if (value === '') {
28464 self.emptyOption = element;
28466 var count = optionsMap.get(value) || 0;
28467 optionsMap.put(value, count + 1);
28468 self.ngModelCtrl.$render();
28469 chromeHack(element);
28472 // Tell the select control that an option, with the given value, has been removed
28473 self.removeOption = function(value) {
28474 var count = optionsMap.get(value);
28477 optionsMap.remove(value);
28478 if (value === '') {
28479 self.emptyOption = undefined;
28482 optionsMap.put(value, count - 1);
28487 // Check whether the select control has an option matching the given value
28488 self.hasOption = function(value) {
28489 return !!optionsMap.get(value);
28493 self.registerOption = function(optionScope, optionElement, optionAttrs, interpolateValueFn, interpolateTextFn) {
28495 if (interpolateValueFn) {
28496 // The value attribute is interpolated
28498 optionAttrs.$observe('value', function valueAttributeObserveAction(newVal) {
28499 if (isDefined(oldVal)) {
28500 self.removeOption(oldVal);
28503 self.addOption(newVal, optionElement);
28505 } else if (interpolateTextFn) {
28506 // The text content is interpolated
28507 optionScope.$watch(interpolateTextFn, function interpolateWatchAction(newVal, oldVal) {
28508 optionAttrs.$set('value', newVal);
28509 if (oldVal !== newVal) {
28510 self.removeOption(oldVal);
28512 self.addOption(newVal, optionElement);
28515 // The value attribute is static
28516 self.addOption(optionAttrs.value, optionElement);
28519 optionElement.on('$destroy', function() {
28520 self.removeOption(optionAttrs.value);
28521 self.ngModelCtrl.$render();
28532 * HTML `SELECT` element with angular data-binding.
28534 * The `select` directive is used together with {@link ngModel `ngModel`} to provide data-binding
28535 * between the scope and the `<select>` control (including setting default values).
28536 * Ìt also handles dynamic `<option>` elements, which can be added using the {@link ngRepeat `ngRepeat}` or
28537 * {@link ngOptions `ngOptions`} directives.
28539 * When an item in the `<select>` menu is selected, the value of the selected option will be bound
28540 * to the model identified by the `ngModel` directive. With static or repeated options, this is
28541 * the content of the `value` attribute or the textContent of the `<option>`, if the value attribute is missing.
28542 * If you want dynamic value attributes, you can use interpolation inside the value attribute.
28544 * <div class="alert alert-warning">
28545 * Note that the value of a `select` directive used without `ngOptions` is always a string.
28546 * When the model needs to be bound to a non-string value, you must either explictly convert it
28547 * using a directive (see example below) or use `ngOptions` to specify the set of options.
28548 * This is because an option element can only be bound to string values at present.
28551 * If the viewValue of `ngModel` does not match any of the options, then the control
28552 * will automatically add an "unknown" option, which it then removes when the mismatch is resolved.
28554 * Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
28555 * be nested into the `<select>` element. This element will then represent the `null` or "not selected"
28556 * option. See example below for demonstration.
28558 * <div class="alert alert-info">
28559 * In many cases, `ngRepeat` can be used on `<option>` elements instead of {@link ng.directive:ngOptions
28560 * ngOptions} to achieve a similar result. However, `ngOptions` provides some benefits, such as
28561 * more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
28562 * comprehension expression, and additionally in reducing memory and increasing speed by not creating
28563 * a new scope for each repeated instance.
28567 * @param {string} ngModel Assignable angular expression to data-bind to.
28568 * @param {string=} name Property name of the form under which the control is published.
28569 * @param {string=} multiple Allows multiple options to be selected. The selected values will be
28570 * bound to the model as an array.
28571 * @param {string=} required Sets `required` validation error key if the value is not entered.
28572 * @param {string=} ngRequired Adds required attribute and required validation constraint to
28573 * the element when the ngRequired expression evaluates to true. Use ngRequired instead of required
28574 * when you want to data-bind to the required attribute.
28575 * @param {string=} ngChange Angular expression to be executed when selected option(s) changes due to user
28576 * interaction with the select element.
28577 * @param {string=} ngOptions sets the options that the select is populated with and defines what is
28578 * set on the model on selection. See {@link ngOptions `ngOptions`}.
28581 * ### Simple `select` elements with static options
28583 * <example name="static-select" module="staticSelect">
28584 * <file name="index.html">
28585 * <div ng-controller="ExampleController">
28586 * <form name="myForm">
28587 * <label for="singleSelect"> Single select: </label><br>
28588 * <select name="singleSelect" ng-model="data.singleSelect">
28589 * <option value="option-1">Option 1</option>
28590 * <option value="option-2">Option 2</option>
28593 * <label for="singleSelect"> Single select with "not selected" option and dynamic option values: </label><br>
28594 * <select name="singleSelect" id="singleSelect" ng-model="data.singleSelect">
28595 * <option value="">---Please select---</option> <!-- not selected / blank option -->
28596 * <option value="{{data.option1}}">Option 1</option> <!-- interpolation -->
28597 * <option value="option-2">Option 2</option>
28599 * <button ng-click="forceUnknownOption()">Force unknown option</button><br>
28600 * <tt>singleSelect = {{data.singleSelect}}</tt>
28603 * <label for="multipleSelect"> Multiple select: </label><br>
28604 * <select name="multipleSelect" id="multipleSelect" ng-model="data.multipleSelect" multiple>
28605 * <option value="option-1">Option 1</option>
28606 * <option value="option-2">Option 2</option>
28607 * <option value="option-3">Option 3</option>
28609 * <tt>multipleSelect = {{data.multipleSelect}}</tt><br/>
28613 * <file name="app.js">
28614 * angular.module('staticSelect', [])
28615 * .controller('ExampleController', ['$scope', function($scope) {
28617 * singleSelect: null,
28618 * multipleSelect: [],
28619 * option1: 'option-1',
28622 * $scope.forceUnknownOption = function() {
28623 * $scope.data.singleSelect = 'nonsense';
28629 * ### Using `ngRepeat` to generate `select` options
28630 * <example name="ngrepeat-select" module="ngrepeatSelect">
28631 * <file name="index.html">
28632 * <div ng-controller="ExampleController">
28633 * <form name="myForm">
28634 * <label for="repeatSelect"> Repeat select: </label>
28635 * <select name="repeatSelect" id="repeatSelect" ng-model="data.repeatSelect">
28636 * <option ng-repeat="option in data.availableOptions" value="{{option.id}}">{{option.name}}</option>
28640 * <tt>repeatSelect = {{data.repeatSelect}}</tt><br/>
28643 * <file name="app.js">
28644 * angular.module('ngrepeatSelect', [])
28645 * .controller('ExampleController', ['$scope', function($scope) {
28647 * repeatSelect: null,
28648 * availableOptions: [
28649 * {id: '1', name: 'Option A'},
28650 * {id: '2', name: 'Option B'},
28651 * {id: '3', name: 'Option C'}
28659 * ### Using `select` with `ngOptions` and setting a default value
28660 * See the {@link ngOptions ngOptions documentation} for more `ngOptions` usage examples.
28662 * <example name="select-with-default-values" module="defaultValueSelect">
28663 * <file name="index.html">
28664 * <div ng-controller="ExampleController">
28665 * <form name="myForm">
28666 * <label for="mySelect">Make a choice:</label>
28667 * <select name="mySelect" id="mySelect"
28668 * ng-options="option.name for option in data.availableOptions track by option.id"
28669 * ng-model="data.selectedOption"></select>
28672 * <tt>option = {{data.selectedOption}}</tt><br/>
28675 * <file name="app.js">
28676 * angular.module('defaultValueSelect', [])
28677 * .controller('ExampleController', ['$scope', function($scope) {
28679 * availableOptions: [
28680 * {id: '1', name: 'Option A'},
28681 * {id: '2', name: 'Option B'},
28682 * {id: '3', name: 'Option C'}
28684 * selectedOption: {id: '3', name: 'Option C'} //This sets the default value of the select in the ui
28691 * ### Binding `select` to a non-string value via `ngModel` parsing / formatting
28693 * <example name="select-with-non-string-options" module="nonStringSelect">
28694 * <file name="index.html">
28695 * <select ng-model="model.id" convert-to-number>
28696 * <option value="0">Zero</option>
28697 * <option value="1">One</option>
28698 * <option value="2">Two</option>
28702 * <file name="app.js">
28703 * angular.module('nonStringSelect', [])
28704 * .run(function($rootScope) {
28705 * $rootScope.model = { id: 2 };
28707 * .directive('convertToNumber', function() {
28709 * require: 'ngModel',
28710 * link: function(scope, element, attrs, ngModel) {
28711 * ngModel.$parsers.push(function(val) {
28712 * return parseInt(val, 10);
28714 * ngModel.$formatters.push(function(val) {
28721 * <file name="protractor.js" type="protractor">
28722 * it('should initialize to model', function() {
28723 * var select = element(by.css('select'));
28724 * expect(element(by.model('model.id')).$('option:checked').getText()).toEqual('Two');
28730 var selectDirective = function() {
28734 require: ['select', '?ngModel'],
28735 controller: SelectController,
28742 function selectPreLink(scope, element, attr, ctrls) {
28744 // if ngModel is not defined, we don't need to do anything
28745 var ngModelCtrl = ctrls[1];
28746 if (!ngModelCtrl) return;
28748 var selectCtrl = ctrls[0];
28750 selectCtrl.ngModelCtrl = ngModelCtrl;
28752 // We delegate rendering to the `writeValue` method, which can be changed
28753 // if the select can have multiple selected values or if the options are being
28754 // generated by `ngOptions`
28755 ngModelCtrl.$render = function() {
28756 selectCtrl.writeValue(ngModelCtrl.$viewValue);
28759 // When the selected item(s) changes we delegate getting the value of the select control
28760 // to the `readValue` method, which can be changed if the select can have multiple
28761 // selected values or if the options are being generated by `ngOptions`
28762 element.on('change', function() {
28763 scope.$apply(function() {
28764 ngModelCtrl.$setViewValue(selectCtrl.readValue());
28768 // If the select allows multiple values then we need to modify how we read and write
28769 // values from and to the control; also what it means for the value to be empty and
28770 // we have to add an extra watch since ngModel doesn't work well with arrays - it
28771 // doesn't trigger rendering if only an item in the array changes.
28772 if (attr.multiple) {
28774 // Read value now needs to check each option to see if it is selected
28775 selectCtrl.readValue = function readMultipleValue() {
28777 forEach(element.find('option'), function(option) {
28778 if (option.selected) {
28779 array.push(option.value);
28785 // Write value now needs to set the selected property of each matching option
28786 selectCtrl.writeValue = function writeMultipleValue(value) {
28787 var items = new HashMap(value);
28788 forEach(element.find('option'), function(option) {
28789 option.selected = isDefined(items.get(option.value));
28793 // we have to do it on each watch since ngModel watches reference, but
28794 // we need to work of an array, so we need to see if anything was inserted/removed
28795 var lastView, lastViewRef = NaN;
28796 scope.$watch(function selectMultipleWatch() {
28797 if (lastViewRef === ngModelCtrl.$viewValue && !equals(lastView, ngModelCtrl.$viewValue)) {
28798 lastView = shallowCopy(ngModelCtrl.$viewValue);
28799 ngModelCtrl.$render();
28801 lastViewRef = ngModelCtrl.$viewValue;
28804 // If we are a multiple select then value is now a collection
28805 // so the meaning of $isEmpty changes
28806 ngModelCtrl.$isEmpty = function(value) {
28807 return !value || value.length === 0;
28815 // The option directive is purely designed to communicate the existence (or lack of)
28816 // of dynamically created (and destroyed) option elements to their containing select
28817 // directive via its controller.
28818 var optionDirective = ['$interpolate', function($interpolate) {
28822 compile: function(element, attr) {
28824 if (isDefined(attr.value)) {
28825 // If the value attribute is defined, check if it contains an interpolation
28826 var interpolateValueFn = $interpolate(attr.value, true);
28828 // If the value attribute is not defined then we fall back to the
28829 // text content of the option element, which may be interpolated
28830 var interpolateTextFn = $interpolate(element.text(), true);
28831 if (!interpolateTextFn) {
28832 attr.$set('value', element.text());
28836 return function(scope, element, attr) {
28838 // This is an optimization over using ^^ since we don't want to have to search
28839 // all the way to the root of the DOM for every single option element
28840 var selectCtrlName = '$selectController',
28841 parent = element.parent(),
28842 selectCtrl = parent.data(selectCtrlName) ||
28843 parent.parent().data(selectCtrlName); // in case we are in optgroup
28846 selectCtrl.registerOption(scope, element, attr, interpolateValueFn, interpolateTextFn);
28853 var styleDirective = valueFn({
28858 var requiredDirective = function() {
28861 require: '?ngModel',
28862 link: function(scope, elm, attr, ctrl) {
28864 attr.required = true; // force truthy in case we are on non input element
28866 ctrl.$validators.required = function(modelValue, viewValue) {
28867 return !attr.required || !ctrl.$isEmpty(viewValue);
28870 attr.$observe('required', function() {
28878 var patternDirective = function() {
28881 require: '?ngModel',
28882 link: function(scope, elm, attr, ctrl) {
28885 var regexp, patternExp = attr.ngPattern || attr.pattern;
28886 attr.$observe('pattern', function(regex) {
28887 if (isString(regex) && regex.length > 0) {
28888 regex = new RegExp('^' + regex + '$');
28891 if (regex && !regex.test) {
28892 throw minErr('ngPattern')('noregexp',
28893 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp,
28894 regex, startingTag(elm));
28897 regexp = regex || undefined;
28901 ctrl.$validators.pattern = function(modelValue, viewValue) {
28902 // HTML5 pattern constraint validates the input value, so we validate the viewValue
28903 return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue);
28910 var maxlengthDirective = function() {
28913 require: '?ngModel',
28914 link: function(scope, elm, attr, ctrl) {
28917 var maxlength = -1;
28918 attr.$observe('maxlength', function(value) {
28919 var intVal = toInt(value);
28920 maxlength = isNaN(intVal) ? -1 : intVal;
28923 ctrl.$validators.maxlength = function(modelValue, viewValue) {
28924 return (maxlength < 0) || ctrl.$isEmpty(viewValue) || (viewValue.length <= maxlength);
28930 var minlengthDirective = function() {
28933 require: '?ngModel',
28934 link: function(scope, elm, attr, ctrl) {
28938 attr.$observe('minlength', function(value) {
28939 minlength = toInt(value) || 0;
28942 ctrl.$validators.minlength = function(modelValue, viewValue) {
28943 return ctrl.$isEmpty(viewValue) || viewValue.length >= minlength;
28949 if (window.angular.bootstrap) {
28950 //AngularJS is already loaded, so we can return here...
28951 console.log('WARNING: Tried to load angular more than once.');
28955 //try to bind to jquery now so that one can write jqLite(document).ready()
28956 //but we will rebind on bootstrap again.
28959 publishExternalAPI(angular);
28961 angular.module("ngLocale", [], ["$provide", function($provide) {
28962 var PLURAL_CATEGORY = {ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"};
28963 function getDecimals(n) {
28965 var i = n.indexOf('.');
28966 return (i == -1) ? 0 : n.length - i - 1;
28969 function getVF(n, opt_precision) {
28970 var v = opt_precision;
28972 if (undefined === v) {
28973 v = Math.min(getDecimals(n), 3);
28976 var base = Math.pow(10, v);
28977 var f = ((n * base) | 0) % base;
28978 return {v: v, f: f};
28981 $provide.value("$locale", {
28982 "DATETIME_FORMATS": {
29004 "FIRSTDAYOFWEEK": 6,
29046 "fullDate": "EEEE, MMMM d, y",
29047 "longDate": "MMMM d, y",
29048 "medium": "MMM d, y h:mm:ss a",
29049 "mediumDate": "MMM d, y",
29050 "mediumTime": "h:mm:ss a",
29051 "short": "M/d/yy h:mm a",
29052 "shortDate": "M/d/yy",
29053 "shortTime": "h:mm a"
29055 "NUMBER_FORMATS": {
29056 "CURRENCY_SYM": "$",
29057 "DECIMAL_SEP": ".",
29077 "negPre": "-\u00a4",
29079 "posPre": "\u00a4",
29085 "pluralCat": function(n, opt_precision) { var i = n | 0; var vf = getVF(n, opt_precision); if (i == 1 && vf.v == 0) { return PLURAL_CATEGORY.ONE; } return PLURAL_CATEGORY.OTHER;}
29089 jqLite(document).ready(function() {
29090 angularInit(document, bootstrap);
29093 })(window, document);
29095 !window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\\:form{display:block;}.ng-animate-shim{visibility:hidden;}.ng-anchor{position:absolute;}</style>');
29099 /***/ function(module, exports) {
29102 * State-based routing for AngularJS
29104 * @link http://angular-ui.github.com/
29105 * @license MIT License, http://www.opensource.org/licenses/MIT
29108 /* commonjs package manager support (eg componentjs) */
29109 if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){
29110 module.exports = 'ui.router';
29113 (function (window, angular, undefined) {
29114 /*jshint globalstrict:true*/
29115 /*global angular:false*/
29118 var isDefined = angular.isDefined,
29119 isFunction = angular.isFunction,
29120 isString = angular.isString,
29121 isObject = angular.isObject,
29122 isArray = angular.isArray,
29123 forEach = angular.forEach,
29124 extend = angular.extend,
29125 copy = angular.copy;
29127 function inherit(parent, extra) {
29128 return extend(new (extend(function() {}, { prototype: parent }))(), extra);
29131 function merge(dst) {
29132 forEach(arguments, function(obj) {
29134 forEach(obj, function(value, key) {
29135 if (!dst.hasOwnProperty(key)) dst[key] = value;
29143 * Finds the common ancestor path between two states.
29145 * @param {Object} first The first state.
29146 * @param {Object} second The second state.
29147 * @return {Array} Returns an array of state names in descending order, not including the root.
29149 function ancestors(first, second) {
29152 for (var n in first.path) {
29153 if (first.path[n] !== second.path[n]) break;
29154 path.push(first.path[n]);
29160 * IE8-safe wrapper for `Object.keys()`.
29162 * @param {Object} object A JavaScript object.
29163 * @return {Array} Returns the keys of the object as an array.
29165 function objectKeys(object) {
29167 return Object.keys(object);
29171 forEach(object, function(val, key) {
29178 * IE8-safe wrapper for `Array.prototype.indexOf()`.
29180 * @param {Array} array A JavaScript array.
29181 * @param {*} value A value to search the array for.
29182 * @return {Number} Returns the array index value of `value`, or `-1` if not present.
29184 function indexOf(array, value) {
29185 if (Array.prototype.indexOf) {
29186 return array.indexOf(value, Number(arguments[2]) || 0);
29188 var len = array.length >>> 0, from = Number(arguments[2]) || 0;
29189 from = (from < 0) ? Math.ceil(from) : Math.floor(from);
29191 if (from < 0) from += len;
29193 for (; from < len; from++) {
29194 if (from in array && array[from] === value) return from;
29200 * Merges a set of parameters with all parameters inherited between the common parents of the
29201 * current state and a given destination state.
29203 * @param {Object} currentParams The value of the current state parameters ($stateParams).
29204 * @param {Object} newParams The set of parameters which will be composited with inherited params.
29205 * @param {Object} $current Internal definition of object representing the current state.
29206 * @param {Object} $to Internal definition of object representing state to transition to.
29208 function inheritParams(currentParams, newParams, $current, $to) {
29209 var parents = ancestors($current, $to), parentParams, inherited = {}, inheritList = [];
29211 for (var i in parents) {
29212 if (!parents[i].params) continue;
29213 parentParams = objectKeys(parents[i].params);
29214 if (!parentParams.length) continue;
29216 for (var j in parentParams) {
29217 if (indexOf(inheritList, parentParams[j]) >= 0) continue;
29218 inheritList.push(parentParams[j]);
29219 inherited[parentParams[j]] = currentParams[parentParams[j]];
29222 return extend({}, inherited, newParams);
29226 * Performs a non-strict comparison of the subset of two objects, defined by a list of keys.
29228 * @param {Object} a The first object.
29229 * @param {Object} b The second object.
29230 * @param {Array} keys The list of keys within each object to compare. If the list is empty or not specified,
29231 * it defaults to the list of keys in `a`.
29232 * @return {Boolean} Returns `true` if the keys match, otherwise `false`.
29234 function equalForKeys(a, b, keys) {
29237 for (var n in a) keys.push(n); // Used instead of Object.keys() for IE8 compatibility
29240 for (var i=0; i<keys.length; i++) {
29242 if (a[k] != b[k]) return false; // Not '===', values aren't necessarily normalized
29248 * Returns the subset of an object, based on a list of keys.
29250 * @param {Array} keys
29251 * @param {Object} values
29252 * @return {Boolean} Returns a subset of `values`.
29254 function filterByKeys(keys, values) {
29257 forEach(keys, function (name) {
29258 filtered[name] = values[name];
29264 // when you know that your index values will be unique, or you want last-one-in to win
29265 function indexBy(array, propName) {
29267 forEach(array, function(item) {
29268 result[item[propName]] = item;
29273 // extracted from underscore.js
29274 // Return a copy of the object only containing the whitelisted properties.
29275 function pick(obj) {
29277 var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
29278 forEach(keys, function(key) {
29279 if (key in obj) copy[key] = obj[key];
29284 // extracted from underscore.js
29285 // Return a copy of the object omitting the blacklisted properties.
29286 function omit(obj) {
29288 var keys = Array.prototype.concat.apply(Array.prototype, Array.prototype.slice.call(arguments, 1));
29289 for (var key in obj) {
29290 if (indexOf(keys, key) == -1) copy[key] = obj[key];
29295 function pluck(collection, key) {
29296 var result = isArray(collection) ? [] : {};
29298 forEach(collection, function(val, i) {
29299 result[i] = isFunction(key) ? key(val) : val[key];
29304 function filter(collection, callback) {
29305 var array = isArray(collection);
29306 var result = array ? [] : {};
29307 forEach(collection, function(val, i) {
29308 if (callback(val, i)) {
29309 result[array ? result.length : i] = val;
29315 function map(collection, callback) {
29316 var result = isArray(collection) ? [] : {};
29318 forEach(collection, function(val, i) {
29319 result[i] = callback(val, i);
29326 * @name ui.router.util
29329 * # ui.router.util sub-module
29331 * This module is a dependency of other sub-modules. Do not include this module as a dependency
29332 * in your angular app (use {@link ui.router} module instead).
29335 angular.module('ui.router.util', ['ng']);
29339 * @name ui.router.router
29341 * @requires ui.router.util
29344 * # ui.router.router sub-module
29346 * This module is a dependency of other sub-modules. Do not include this module as a dependency
29347 * in your angular app (use {@link ui.router} module instead).
29349 angular.module('ui.router.router', ['ui.router.util']);
29353 * @name ui.router.state
29355 * @requires ui.router.router
29356 * @requires ui.router.util
29359 * # ui.router.state sub-module
29361 * This module is a dependency of the main ui.router module. Do not include this module as a dependency
29362 * in your angular app (use {@link ui.router} module instead).
29365 angular.module('ui.router.state', ['ui.router.router', 'ui.router.util']);
29371 * @requires ui.router.state
29376 * ## The main module for ui.router
29377 * There are several sub-modules included with the ui.router module, however only this module is needed
29378 * as a dependency within your angular app. The other modules are for organization purposes.
29381 * * ui.router - the main "umbrella" module
29382 * * ui.router.router -
29384 * *You'll need to include **only** this module as the dependency within your angular app.*
29388 * <html ng-app="myApp">
29390 * <script src="js/angular.js"></script>
29391 * <!-- Include the ui-router script -->
29392 * <script src="js/angular-ui-router.min.js"></script>
29394 * // ...and add 'ui.router' as a dependency
29395 * var myApp = angular.module('myApp', ['ui.router']);
29403 angular.module('ui.router', ['ui.router.state']);
29405 angular.module('ui.router.compat', ['ui.router']);
29409 * @name ui.router.util.$resolve
29412 * @requires $injector
29415 * Manages resolution of (acyclic) graphs of promises.
29417 $Resolve.$inject = ['$q', '$injector'];
29418 function $Resolve( $q, $injector) {
29420 var VISIT_IN_PROGRESS = 1,
29423 NO_DEPENDENCIES = [],
29424 NO_LOCALS = NOTHING,
29425 NO_PARENT = extend($q.when(NOTHING), { $$promises: NOTHING, $$values: NOTHING });
29430 * @name ui.router.util.$resolve#study
29431 * @methodOf ui.router.util.$resolve
29434 * Studies a set of invocables that are likely to be used multiple times.
29436 * $resolve.study(invocables)(locals, parent, self)
29440 * $resolve.resolve(invocables, locals, parent, self)
29442 * but the former is more efficient (in fact `resolve` just calls `study`
29445 * @param {object} invocables Invocable objects
29446 * @return {function} a function to pass in locals, parent and self
29448 this.study = function (invocables) {
29449 if (!isObject(invocables)) throw new Error("'invocables' must be an object");
29450 var invocableKeys = objectKeys(invocables || {});
29452 // Perform a topological sort of invocables to build an ordered plan
29453 var plan = [], cycle = [], visited = {};
29454 function visit(value, key) {
29455 if (visited[key] === VISIT_DONE) return;
29458 if (visited[key] === VISIT_IN_PROGRESS) {
29459 cycle.splice(0, indexOf(cycle, key));
29460 throw new Error("Cyclic dependency: " + cycle.join(" -> "));
29462 visited[key] = VISIT_IN_PROGRESS;
29464 if (isString(value)) {
29465 plan.push(key, [ function() { return $injector.get(value); }], NO_DEPENDENCIES);
29467 var params = $injector.annotate(value);
29468 forEach(params, function (param) {
29469 if (param !== key && invocables.hasOwnProperty(param)) visit(invocables[param], param);
29471 plan.push(key, value, params);
29475 visited[key] = VISIT_DONE;
29477 forEach(invocables, visit);
29478 invocables = cycle = visited = null; // plan is all that's required
29480 function isResolve(value) {
29481 return isObject(value) && value.then && value.$$promises;
29484 return function (locals, parent, self) {
29485 if (isResolve(locals) && self === undefined) {
29486 self = parent; parent = locals; locals = null;
29488 if (!locals) locals = NO_LOCALS;
29489 else if (!isObject(locals)) {
29490 throw new Error("'locals' must be an object");
29492 if (!parent) parent = NO_PARENT;
29493 else if (!isResolve(parent)) {
29494 throw new Error("'parent' must be a promise returned by $resolve.resolve()");
29497 // To complete the overall resolution, we have to wait for the parent
29498 // promise and for the promise for each invokable in our plan.
29499 var resolution = $q.defer(),
29500 result = resolution.promise,
29501 promises = result.$$promises = {},
29502 values = extend({}, locals),
29503 wait = 1 + plan.length/3,
29507 // Merge parent values we haven't got yet and publish our own $$values
29509 if (!merged) merge(values, parent.$$values);
29510 result.$$values = values;
29511 result.$$promises = result.$$promises || true; // keep for isResolve()
29512 delete result.$$inheritedValues;
29513 resolution.resolve(values);
29517 function fail(reason) {
29518 result.$$failure = reason;
29519 resolution.reject(reason);
29522 // Short-circuit if parent has already failed
29523 if (isDefined(parent.$$failure)) {
29524 fail(parent.$$failure);
29528 if (parent.$$inheritedValues) {
29529 merge(values, omit(parent.$$inheritedValues, invocableKeys));
29532 // Merge parent values if the parent has already resolved, or merge
29533 // parent promises and wait if the parent resolve is still in progress.
29534 extend(promises, parent.$$promises);
29535 if (parent.$$values) {
29536 merged = merge(values, omit(parent.$$values, invocableKeys));
29537 result.$$inheritedValues = omit(parent.$$values, invocableKeys);
29540 if (parent.$$inheritedValues) {
29541 result.$$inheritedValues = omit(parent.$$inheritedValues, invocableKeys);
29543 parent.then(done, fail);
29546 // Process each invocable in the plan, but ignore any where a local of the same name exists.
29547 for (var i=0, ii=plan.length; i<ii; i+=3) {
29548 if (locals.hasOwnProperty(plan[i])) done();
29549 else invoke(plan[i], plan[i+1], plan[i+2]);
29552 function invoke(key, invocable, params) {
29553 // Create a deferred for this invocation. Failures will propagate to the resolution as well.
29554 var invocation = $q.defer(), waitParams = 0;
29555 function onfailure(reason) {
29556 invocation.reject(reason);
29559 // Wait for any parameter that we have a promise for (either from parent or from this
29560 // resolve; in that case study() will have made sure it's ordered before us in the plan).
29561 forEach(params, function (dep) {
29562 if (promises.hasOwnProperty(dep) && !locals.hasOwnProperty(dep)) {
29564 promises[dep].then(function (result) {
29565 values[dep] = result;
29566 if (!(--waitParams)) proceed();
29570 if (!waitParams) proceed();
29571 function proceed() {
29572 if (isDefined(result.$$failure)) return;
29574 invocation.resolve($injector.invoke(invocable, self, values));
29575 invocation.promise.then(function (result) {
29576 values[key] = result;
29583 // Publish promise synchronously; invocations further down in the plan may depend on it.
29584 promises[key] = invocation.promise;
29593 * @name ui.router.util.$resolve#resolve
29594 * @methodOf ui.router.util.$resolve
29597 * Resolves a set of invocables. An invocable is a function to be invoked via
29598 * `$injector.invoke()`, and can have an arbitrary number of dependencies.
29599 * An invocable can either return a value directly,
29600 * or a `$q` promise. If a promise is returned it will be resolved and the
29601 * resulting value will be used instead. Dependencies of invocables are resolved
29602 * (in this order of precedence)
29604 * - from the specified `locals`
29605 * - from another invocable that is part of this `$resolve` call
29606 * - from an invocable that is inherited from a `parent` call to `$resolve`
29608 * - from any ancestor `$resolve` of that parent).
29610 * The return value of `$resolve` is a promise for an object that contains
29611 * (in this order of precedence)
29613 * - any `locals` (if specified)
29614 * - the resolved return values of all injectables
29615 * - any values inherited from a `parent` call to `$resolve` (if specified)
29617 * The promise will resolve after the `parent` promise (if any) and all promises
29618 * returned by injectables have been resolved. If any invocable
29619 * (or `$injector.invoke`) throws an exception, or if a promise returned by an
29620 * invocable is rejected, the `$resolve` promise is immediately rejected with the
29621 * same error. A rejection of a `parent` promise (if specified) will likewise be
29622 * propagated immediately. Once the `$resolve` promise has been rejected, no
29623 * further invocables will be called.
29625 * Cyclic dependencies between invocables are not permitted and will caues `$resolve`
29626 * to throw an error. As a special case, an injectable can depend on a parameter
29627 * with the same name as the injectable, which will be fulfilled from the `parent`
29628 * injectable of the same name. This allows inherited values to be decorated.
29629 * Note that in this case any other injectable in the same `$resolve` with the same
29630 * dependency would see the decorated value, not the inherited value.
29632 * Note that missing dependencies -- unlike cyclic dependencies -- will cause an
29633 * (asynchronous) rejection of the `$resolve` promise rather than a (synchronous)
29636 * Invocables are invoked eagerly as soon as all dependencies are available.
29637 * This is true even for dependencies inherited from a `parent` call to `$resolve`.
29639 * As a special case, an invocable can be a string, in which case it is taken to
29640 * be a service name to be passed to `$injector.get()`. This is supported primarily
29641 * for backwards-compatibility with the `resolve` property of `$routeProvider`
29644 * @param {object} invocables functions to invoke or
29645 * `$injector` services to fetch.
29646 * @param {object} locals values to make available to the injectables
29647 * @param {object} parent a promise returned by another call to `$resolve`.
29648 * @param {object} self the `this` for the invoked methods
29649 * @return {object} Promise for an object that contains the resolved return value
29650 * of all invocables, as well as any inherited and local values.
29652 this.resolve = function (invocables, locals, parent, self) {
29653 return this.study(invocables)(locals, parent, self);
29657 angular.module('ui.router.util').service('$resolve', $Resolve);
29662 * @name ui.router.util.$templateFactory
29665 * @requires $templateCache
29666 * @requires $injector
29669 * Service. Manages loading of templates.
29671 $TemplateFactory.$inject = ['$http', '$templateCache', '$injector'];
29672 function $TemplateFactory( $http, $templateCache, $injector) {
29676 * @name ui.router.util.$templateFactory#fromConfig
29677 * @methodOf ui.router.util.$templateFactory
29680 * Creates a template from a configuration object.
29682 * @param {object} config Configuration object for which to load a template.
29683 * The following properties are search in the specified order, and the first one
29684 * that is defined is used to create the template:
29686 * @param {string|object} config.template html string template or function to
29687 * load via {@link ui.router.util.$templateFactory#fromString fromString}.
29688 * @param {string|object} config.templateUrl url to load or a function returning
29689 * the url to load via {@link ui.router.util.$templateFactory#fromUrl fromUrl}.
29690 * @param {Function} config.templateProvider function to invoke via
29691 * {@link ui.router.util.$templateFactory#fromProvider fromProvider}.
29692 * @param {object} params Parameters to pass to the template function.
29693 * @param {object} locals Locals to pass to `invoke` if the template is loaded
29694 * via a `templateProvider`. Defaults to `{ params: params }`.
29696 * @return {string|object} The template html as a string, or a promise for
29697 * that string,or `null` if no template is configured.
29699 this.fromConfig = function (config, params, locals) {
29701 isDefined(config.template) ? this.fromString(config.template, params) :
29702 isDefined(config.templateUrl) ? this.fromUrl(config.templateUrl, params) :
29703 isDefined(config.templateProvider) ? this.fromProvider(config.templateProvider, params, locals) :
29710 * @name ui.router.util.$templateFactory#fromString
29711 * @methodOf ui.router.util.$templateFactory
29714 * Creates a template from a string or a function returning a string.
29716 * @param {string|object} template html template as a string or function that
29717 * returns an html template as a string.
29718 * @param {object} params Parameters to pass to the template function.
29720 * @return {string|object} The template html as a string, or a promise for that
29723 this.fromString = function (template, params) {
29724 return isFunction(template) ? template(params) : template;
29729 * @name ui.router.util.$templateFactory#fromUrl
29730 * @methodOf ui.router.util.$templateFactory
29733 * Loads a template from the a URL via `$http` and `$templateCache`.
29735 * @param {string|Function} url url of the template to load, or a function
29736 * that returns a url.
29737 * @param {Object} params Parameters to pass to the url function.
29738 * @return {string|Promise.<string>} The template html as a string, or a promise
29741 this.fromUrl = function (url, params) {
29742 if (isFunction(url)) url = url(params);
29743 if (url == null) return null;
29745 .get(url, { cache: $templateCache, headers: { Accept: 'text/html' }})
29746 .then(function(response) { return response.data; });
29751 * @name ui.router.util.$templateFactory#fromProvider
29752 * @methodOf ui.router.util.$templateFactory
29755 * Creates a template by invoking an injectable provider function.
29757 * @param {Function} provider Function to invoke via `$injector.invoke`
29758 * @param {Object} params Parameters for the template.
29759 * @param {Object} locals Locals to pass to `invoke`. Defaults to
29760 * `{ params: params }`.
29761 * @return {string|Promise.<string>} The template html as a string, or a promise
29764 this.fromProvider = function (provider, params, locals) {
29765 return $injector.invoke(provider, null, locals || { params: params });
29769 angular.module('ui.router.util').service('$templateFactory', $TemplateFactory);
29771 var $$UMFP; // reference to $UrlMatcherFactoryProvider
29775 * @name ui.router.util.type:UrlMatcher
29778 * Matches URLs against patterns and extracts named parameters from the path or the search
29779 * part of the URL. A URL pattern consists of a path pattern, optionally followed by '?' and a list
29780 * of search parameters. Multiple search parameter names are separated by '&'. Search parameters
29781 * do not influence whether or not a URL is matched, but their values are passed through into
29782 * the matched parameters returned by {@link ui.router.util.type:UrlMatcher#methods_exec exec}.
29784 * Path parameter placeholders can be specified using simple colon/catch-all syntax or curly brace
29785 * syntax, which optionally allows a regular expression for the parameter to be specified:
29787 * * `':'` name - colon placeholder
29788 * * `'*'` name - catch-all placeholder
29789 * * `'{' name '}'` - curly placeholder
29790 * * `'{' name ':' regexp|type '}'` - curly placeholder with regexp or type name. Should the
29791 * regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash.
29793 * Parameter names may contain only word characters (latin letters, digits, and underscore) and
29794 * must be unique within the pattern (across both path and search parameters). For colon
29795 * placeholders or curly placeholders without an explicit regexp, a path parameter matches any
29796 * number of characters other than '/'. For catch-all placeholders the path parameter matches
29797 * any number of characters.
29801 * * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for
29802 * trailing slashes, and patterns have to match the entire path, not just a prefix.
29803 * * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or
29804 * '/user/bob/details'. The second path segment will be captured as the parameter 'id'.
29805 * * `'/user/{id}'` - Same as the previous example, but using curly brace syntax.
29806 * * `'/user/{id:[^/]*}'` - Same as the previous example.
29807 * * `'/user/{id:[0-9a-fA-F]{1,8}}'` - Similar to the previous example, but only matches if the id
29808 * parameter consists of 1 to 8 hex digits.
29809 * * `'/files/{path:.*}'` - Matches any URL starting with '/files/' and captures the rest of the
29810 * path into the parameter 'path'.
29811 * * `'/files/*path'` - ditto.
29812 * * `'/calendar/{start:date}'` - Matches "/calendar/2014-11-12" (because the pattern defined
29813 * in the built-in `date` Type matches `2014-11-12`) and provides a Date object in $stateParams.start
29815 * @param {string} pattern The pattern to compile into a matcher.
29816 * @param {Object} config A configuration object hash:
29817 * @param {Object=} parentMatcher Used to concatenate the pattern/config onto
29818 * an existing UrlMatcher
29820 * * `caseInsensitive` - `true` if URL matching should be case insensitive, otherwise `false`, the default value (for backward compatibility) is `false`.
29821 * * `strict` - `false` if matching against a URL with a trailing slash should be treated as equivalent to a URL without a trailing slash, the default value is `true`.
29823 * @property {string} prefix A static prefix of this pattern. The matcher guarantees that any
29824 * URL matching this matcher (i.e. any string for which {@link ui.router.util.type:UrlMatcher#methods_exec exec()} returns
29825 * non-null) will start with this prefix.
29827 * @property {string} source The pattern that was passed into the constructor
29829 * @property {string} sourcePath The path portion of the source property
29831 * @property {string} sourceSearch The search portion of the source property
29833 * @property {string} regex The constructed regex that will be used to match against the url when
29834 * it is time to determine which url will match.
29836 * @returns {Object} New `UrlMatcher` object
29838 function UrlMatcher(pattern, config, parentMatcher) {
29839 config = extend({ params: {} }, isObject(config) ? config : {});
29841 // Find all placeholders and create a compiled pattern, using either classic or curly syntax:
29845 // '{' name ':' regexp '}'
29846 // The regular expression is somewhat complicated due to the need to allow curly braces
29847 // inside the regular expression. The placeholder regexp breaks down as follows:
29848 // ([:*])([\w\[\]]+) - classic placeholder ($1 / $2) (search version has - for snake-case)
29849 // \{([\w\[\]]+)(?:\:( ... ))?\} - curly brace placeholder ($3) with optional regexp/type ... ($4) (search version has - for snake-case
29850 // (?: ... | ... | ... )+ - the regexp consists of any number of atoms, an atom being either
29851 // [^{}\\]+ - anything other than curly braces or backslash
29852 // \\. - a backslash escape
29853 // \{(?:[^{}\\]+|\\.)*\} - a matched set of curly braces containing other atoms
29854 var placeholder = /([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,
29855 searchPlaceholder = /([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,
29856 compiled = '^', last = 0, m,
29857 segments = this.segments = [],
29858 parentParams = parentMatcher ? parentMatcher.params : {},
29859 params = this.params = parentMatcher ? parentMatcher.params.$$new() : new $$UMFP.ParamSet(),
29862 function addParameter(id, type, config, location) {
29863 paramNames.push(id);
29864 if (parentParams[id]) return parentParams[id];
29865 if (!/^\w+(-+\w+)*(?:\[\])?$/.test(id)) throw new Error("Invalid parameter name '" + id + "' in pattern '" + pattern + "'");
29866 if (params[id]) throw new Error("Duplicate parameter name '" + id + "' in pattern '" + pattern + "'");
29867 params[id] = new $$UMFP.Param(id, type, config, location);
29871 function quoteRegExp(string, pattern, squash, optional) {
29872 var surroundPattern = ['',''], result = string.replace(/[\\\[\]\^$*+?.()|{}]/g, "\\$&");
29873 if (!pattern) return result;
29875 case false: surroundPattern = ['(', ')' + (optional ? "?" : "")]; break;
29876 case true: surroundPattern = ['?(', ')?']; break;
29877 default: surroundPattern = ['(' + squash + "|", ')?']; break;
29879 return result + surroundPattern[0] + pattern + surroundPattern[1];
29882 this.source = pattern;
29884 // Split into static segments separated by path parameter placeholders.
29885 // The number of segments is always 1 more than the number of parameters.
29886 function matchDetails(m, isSearch) {
29887 var id, regexp, segment, type, cfg, arrayMode;
29888 id = m[2] || m[3]; // IE[78] returns '' for unmatched groups instead of null
29889 cfg = config.params[id];
29890 segment = pattern.substring(last, m.index);
29891 regexp = isSearch ? m[4] : m[4] || (m[1] == '*' ? '.*' : null);
29892 type = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp, config.caseInsensitive ? 'i' : undefined) });
29894 id: id, regexp: regexp, segment: segment, type: type, cfg: cfg
29898 var p, param, segment;
29899 while ((m = placeholder.exec(pattern))) {
29900 p = matchDetails(m, false);
29901 if (p.segment.indexOf('?') >= 0) break; // we're into the search part
29903 param = addParameter(p.id, p.type, p.cfg, "path");
29904 compiled += quoteRegExp(p.segment, param.type.pattern.source, param.squash, param.isOptional);
29905 segments.push(p.segment);
29906 last = placeholder.lastIndex;
29908 segment = pattern.substring(last);
29910 // Find any search parameter names and remove them from the last segment
29911 var i = segment.indexOf('?');
29914 var search = this.sourceSearch = segment.substring(i);
29915 segment = segment.substring(0, i);
29916 this.sourcePath = pattern.substring(0, last + i);
29918 if (search.length > 0) {
29920 while ((m = searchPlaceholder.exec(search))) {
29921 p = matchDetails(m, true);
29922 param = addParameter(p.id, p.type, p.cfg, "search");
29923 last = placeholder.lastIndex;
29928 this.sourcePath = pattern;
29929 this.sourceSearch = '';
29932 compiled += quoteRegExp(segment) + (config.strict === false ? '\/?' : '') + '$';
29933 segments.push(segment);
29935 this.regexp = new RegExp(compiled, config.caseInsensitive ? 'i' : undefined);
29936 this.prefix = segments[0];
29937 this.$$paramNames = paramNames;
29942 * @name ui.router.util.type:UrlMatcher#concat
29943 * @methodOf ui.router.util.type:UrlMatcher
29946 * Returns a new matcher for a pattern constructed by appending the path part and adding the
29947 * search parameters of the specified pattern to this pattern. The current pattern is not
29948 * modified. This can be understood as creating a pattern for URLs that are relative to (or
29949 * suffixes of) the current pattern.
29952 * The following two matchers are equivalent:
29954 * new UrlMatcher('/user/{id}?q').concat('/details?date');
29955 * new UrlMatcher('/user/{id}/details?q&date');
29958 * @param {string} pattern The pattern to append.
29959 * @param {Object} config An object hash of the configuration for the matcher.
29960 * @returns {UrlMatcher} A matcher for the concatenated pattern.
29962 UrlMatcher.prototype.concat = function (pattern, config) {
29963 // Because order of search parameters is irrelevant, we can add our own search
29964 // parameters to the end of the new pattern. Parse the new pattern by itself
29965 // and then join the bits together, but it's much easier to do this on a string level.
29966 var defaultConfig = {
29967 caseInsensitive: $$UMFP.caseInsensitive(),
29968 strict: $$UMFP.strictMode(),
29969 squash: $$UMFP.defaultSquashPolicy()
29971 return new UrlMatcher(this.sourcePath + pattern + this.sourceSearch, extend(defaultConfig, config), this);
29974 UrlMatcher.prototype.toString = function () {
29975 return this.source;
29980 * @name ui.router.util.type:UrlMatcher#exec
29981 * @methodOf ui.router.util.type:UrlMatcher
29984 * Tests the specified path against this matcher, and returns an object containing the captured
29985 * parameter values, or null if the path does not match. The returned object contains the values
29986 * of any search parameters that are mentioned in the pattern, but their value may be null if
29987 * they are not present in `searchParams`. This means that search parameters are always treated
29992 * new UrlMatcher('/user/{id}?q&r').exec('/user/bob', {
29993 * x: '1', q: 'hello'
29995 * // returns { id: 'bob', q: 'hello', r: null }
29998 * @param {string} path The URL path to match, e.g. `$location.path()`.
29999 * @param {Object} searchParams URL search parameters, e.g. `$location.search()`.
30000 * @returns {Object} The captured parameter values.
30002 UrlMatcher.prototype.exec = function (path, searchParams) {
30003 var m = this.regexp.exec(path);
30004 if (!m) return null;
30005 searchParams = searchParams || {};
30007 var paramNames = this.parameters(), nTotal = paramNames.length,
30008 nPath = this.segments.length - 1,
30009 values = {}, i, j, cfg, paramName;
30011 if (nPath !== m.length - 1) throw new Error("Unbalanced capture group in route '" + this.source + "'");
30013 function decodePathArray(string) {
30014 function reverseString(str) { return str.split("").reverse().join(""); }
30015 function unquoteDashes(str) { return str.replace(/\\-/g, "-"); }
30017 var split = reverseString(string).split(/-(?!\\)/);
30018 var allReversed = map(split, reverseString);
30019 return map(allReversed, unquoteDashes).reverse();
30022 for (i = 0; i < nPath; i++) {
30023 paramName = paramNames[i];
30024 var param = this.params[paramName];
30025 var paramVal = m[i+1];
30026 // if the param value matches a pre-replace pair, replace the value before decoding.
30027 for (j = 0; j < param.replace; j++) {
30028 if (param.replace[j].from === paramVal) paramVal = param.replace[j].to;
30030 if (paramVal && param.array === true) paramVal = decodePathArray(paramVal);
30031 values[paramName] = param.value(paramVal);
30033 for (/**/; i < nTotal; i++) {
30034 paramName = paramNames[i];
30035 values[paramName] = this.params[paramName].value(searchParams[paramName]);
30043 * @name ui.router.util.type:UrlMatcher#parameters
30044 * @methodOf ui.router.util.type:UrlMatcher
30047 * Returns the names of all path and search parameters of this pattern in an unspecified order.
30049 * @returns {Array.<string>} An array of parameter names. Must be treated as read-only. If the
30050 * pattern has no parameters, an empty array is returned.
30052 UrlMatcher.prototype.parameters = function (param) {
30053 if (!isDefined(param)) return this.$$paramNames;
30054 return this.params[param] || null;
30059 * @name ui.router.util.type:UrlMatcher#validate
30060 * @methodOf ui.router.util.type:UrlMatcher
30063 * Checks an object hash of parameters to validate their correctness according to the parameter
30064 * types of this `UrlMatcher`.
30066 * @param {Object} params The object hash of parameters to validate.
30067 * @returns {boolean} Returns `true` if `params` validates, otherwise `false`.
30069 UrlMatcher.prototype.validates = function (params) {
30070 return this.params.$$validates(params);
30075 * @name ui.router.util.type:UrlMatcher#format
30076 * @methodOf ui.router.util.type:UrlMatcher
30079 * Creates a URL that matches this pattern by substituting the specified values
30080 * for the path and search parameters. Null values for path parameters are
30081 * treated as empty strings.
30085 * new UrlMatcher('/user/{id}?q').format({ id:'bob', q:'yes' });
30086 * // returns '/user/bob?q=yes'
30089 * @param {Object} values the values to substitute for the parameters in this pattern.
30090 * @returns {string} the formatted URL (path and optionally search part).
30092 UrlMatcher.prototype.format = function (values) {
30093 values = values || {};
30094 var segments = this.segments, params = this.parameters(), paramset = this.params;
30095 if (!this.validates(values)) return null;
30097 var i, search = false, nPath = segments.length - 1, nTotal = params.length, result = segments[0];
30099 function encodeDashes(str) { // Replace dashes with encoded "\-"
30100 return encodeURIComponent(str).replace(/-/g, function(c) { return '%5C%' + c.charCodeAt(0).toString(16).toUpperCase(); });
30103 for (i = 0; i < nTotal; i++) {
30104 var isPathParam = i < nPath;
30105 var name = params[i], param = paramset[name], value = param.value(values[name]);
30106 var isDefaultValue = param.isOptional && param.type.equals(param.value(), value);
30107 var squash = isDefaultValue ? param.squash : false;
30108 var encoded = param.type.encode(value);
30111 var nextSegment = segments[i + 1];
30112 if (squash === false) {
30113 if (encoded != null) {
30114 if (isArray(encoded)) {
30115 result += map(encoded, encodeDashes).join("-");
30117 result += encodeURIComponent(encoded);
30120 result += nextSegment;
30121 } else if (squash === true) {
30122 var capture = result.match(/\/$/) ? /\/?(.*)/ : /(.*)/;
30123 result += nextSegment.match(capture)[1];
30124 } else if (isString(squash)) {
30125 result += squash + nextSegment;
30128 if (encoded == null || (isDefaultValue && squash !== false)) continue;
30129 if (!isArray(encoded)) encoded = [ encoded ];
30130 encoded = map(encoded, encodeURIComponent).join('&' + name + '=');
30131 result += (search ? '&' : '?') + (name + '=' + encoded);
30141 * @name ui.router.util.type:Type
30144 * Implements an interface to define custom parameter types that can be decoded from and encoded to
30145 * string parameters matched in a URL. Used by {@link ui.router.util.type:UrlMatcher `UrlMatcher`}
30146 * objects when matching or formatting URLs, or comparing or validating parameter values.
30148 * See {@link ui.router.util.$urlMatcherFactory#methods_type `$urlMatcherFactory#type()`} for more
30149 * information on registering custom types.
30151 * @param {Object} config A configuration object which contains the custom type definition. The object's
30152 * properties will override the default methods and/or pattern in `Type`'s public interface.
30156 * decode: function(val) { return parseInt(val, 10); },
30157 * encode: function(val) { return val && val.toString(); },
30158 * equals: function(a, b) { return this.is(a) && a === b; },
30159 * is: function(val) { return angular.isNumber(val) isFinite(val) && val % 1 === 0; },
30164 * @property {RegExp} pattern The regular expression pattern used to match values of this type when
30165 * coming from a substring of a URL.
30167 * @returns {Object} Returns a new `Type` object.
30169 function Type(config) {
30170 extend(this, config);
30175 * @name ui.router.util.type:Type#is
30176 * @methodOf ui.router.util.type:Type
30179 * Detects whether a value is of a particular type. Accepts a native (decoded) value
30180 * and determines whether it matches the current `Type` object.
30182 * @param {*} val The value to check.
30183 * @param {string} key Optional. If the type check is happening in the context of a specific
30184 * {@link ui.router.util.type:UrlMatcher `UrlMatcher`} object, this is the name of the
30185 * parameter in which `val` is stored. Can be used for meta-programming of `Type` objects.
30186 * @returns {Boolean} Returns `true` if the value matches the type, otherwise `false`.
30188 Type.prototype.is = function(val, key) {
30194 * @name ui.router.util.type:Type#encode
30195 * @methodOf ui.router.util.type:Type
30198 * Encodes a custom/native type value to a string that can be embedded in a URL. Note that the
30199 * return value does *not* need to be URL-safe (i.e. passed through `encodeURIComponent()`), it
30200 * only needs to be a representation of `val` that has been coerced to a string.
30202 * @param {*} val The value to encode.
30203 * @param {string} key The name of the parameter in which `val` is stored. Can be used for
30204 * meta-programming of `Type` objects.
30205 * @returns {string} Returns a string representation of `val` that can be encoded in a URL.
30207 Type.prototype.encode = function(val, key) {
30213 * @name ui.router.util.type:Type#decode
30214 * @methodOf ui.router.util.type:Type
30217 * Converts a parameter value (from URL string or transition param) to a custom/native value.
30219 * @param {string} val The URL parameter value to decode.
30220 * @param {string} key The name of the parameter in which `val` is stored. Can be used for
30221 * meta-programming of `Type` objects.
30222 * @returns {*} Returns a custom representation of the URL parameter value.
30224 Type.prototype.decode = function(val, key) {
30230 * @name ui.router.util.type:Type#equals
30231 * @methodOf ui.router.util.type:Type
30234 * Determines whether two decoded values are equivalent.
30236 * @param {*} a A value to compare against.
30237 * @param {*} b A value to compare against.
30238 * @returns {Boolean} Returns `true` if the values are equivalent/equal, otherwise `false`.
30240 Type.prototype.equals = function(a, b) {
30244 Type.prototype.$subPattern = function() {
30245 var sub = this.pattern.toString();
30246 return sub.substr(1, sub.length - 2);
30249 Type.prototype.pattern = /.*/;
30251 Type.prototype.toString = function() { return "{Type:" + this.name + "}"; };
30253 /** Given an encoded string, or a decoded object, returns a decoded object */
30254 Type.prototype.$normalize = function(val) {
30255 return this.is(val) ? val : this.decode(val);
30259 * Wraps an existing custom Type as an array of Type, depending on 'mode'.
30261 * - urlmatcher pattern "/path?{queryParam[]:int}"
30262 * - url: "/path?queryParam=1&queryParam=2
30263 * - $stateParams.queryParam will be [1, 2]
30264 * if `mode` is "auto", then
30265 * - url: "/path?queryParam=1 will create $stateParams.queryParam: 1
30266 * - url: "/path?queryParam=1&queryParam=2 will create $stateParams.queryParam: [1, 2]
30268 Type.prototype.$asArray = function(mode, isSearch) {
30269 if (!mode) return this;
30270 if (mode === "auto" && !isSearch) throw new Error("'auto' array mode is for query parameters only");
30272 function ArrayType(type, mode) {
30273 function bindTo(type, callbackName) {
30274 return function() {
30275 return type[callbackName].apply(type, arguments);
30279 // Wrap non-array value as array
30280 function arrayWrap(val) { return isArray(val) ? val : (isDefined(val) ? [ val ] : []); }
30281 // Unwrap array value for "auto" mode. Return undefined for empty array.
30282 function arrayUnwrap(val) {
30283 switch(val.length) {
30284 case 0: return undefined;
30285 case 1: return mode === "auto" ? val[0] : val;
30286 default: return val;
30289 function falsey(val) { return !val; }
30291 // Wraps type (.is/.encode/.decode) functions to operate on each value of an array
30292 function arrayHandler(callback, allTruthyMode) {
30293 return function handleArray(val) {
30294 val = arrayWrap(val);
30295 var result = map(val, callback);
30296 if (allTruthyMode === true)
30297 return filter(result, falsey).length === 0;
30298 return arrayUnwrap(result);
30302 // Wraps type (.equals) functions to operate on each value of an array
30303 function arrayEqualsHandler(callback) {
30304 return function handleArray(val1, val2) {
30305 var left = arrayWrap(val1), right = arrayWrap(val2);
30306 if (left.length !== right.length) return false;
30307 for (var i = 0; i < left.length; i++) {
30308 if (!callback(left[i], right[i])) return false;
30314 this.encode = arrayHandler(bindTo(type, 'encode'));
30315 this.decode = arrayHandler(bindTo(type, 'decode'));
30316 this.is = arrayHandler(bindTo(type, 'is'), true);
30317 this.equals = arrayEqualsHandler(bindTo(type, 'equals'));
30318 this.pattern = type.pattern;
30319 this.$normalize = arrayHandler(bindTo(type, '$normalize'));
30320 this.name = type.name;
30321 this.$arrayMode = mode;
30324 return new ArrayType(this, mode);
30331 * @name ui.router.util.$urlMatcherFactory
30334 * Factory for {@link ui.router.util.type:UrlMatcher `UrlMatcher`} instances. The factory
30335 * is also available to providers under the name `$urlMatcherFactoryProvider`.
30337 function $UrlMatcherFactory() {
30340 var isCaseInsensitive = false, isStrictMode = true, defaultSquashPolicy = false;
30342 function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; }
30343 function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; }
30345 var $types = {}, enqueue = true, typeQueue = [], injector, defaultTypes = {
30347 encode: valToString,
30348 decode: valFromString,
30349 // TODO: in 1.0, make string .is() return false if value is undefined/null by default.
30350 // In 0.2.x, string params are optional by default for backwards compat
30351 is: function(val) { return val == null || !isDefined(val) || typeof val === "string"; },
30355 encode: valToString,
30356 decode: function(val) { return parseInt(val, 10); },
30357 is: function(val) { return isDefined(val) && this.decode(val.toString()) === val; },
30361 encode: function(val) { return val ? 1 : 0; },
30362 decode: function(val) { return parseInt(val, 10) !== 0; },
30363 is: function(val) { return val === true || val === false; },
30367 encode: function (val) {
30370 return [ val.getFullYear(),
30371 ('0' + (val.getMonth() + 1)).slice(-2),
30372 ('0' + val.getDate()).slice(-2)
30375 decode: function (val) {
30376 if (this.is(val)) return val;
30377 var match = this.capture.exec(val);
30378 return match ? new Date(match[1], match[2] - 1, match[3]) : undefined;
30380 is: function(val) { return val instanceof Date && !isNaN(val.valueOf()); },
30381 equals: function (a, b) { return this.is(a) && this.is(b) && a.toISOString() === b.toISOString(); },
30382 pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,
30383 capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/
30386 encode: angular.toJson,
30387 decode: angular.fromJson,
30388 is: angular.isObject,
30389 equals: angular.equals,
30392 any: { // does not encode/decode
30393 encode: angular.identity,
30394 decode: angular.identity,
30395 equals: angular.equals,
30400 function getDefaultConfig() {
30402 strict: isStrictMode,
30403 caseInsensitive: isCaseInsensitive
30407 function isInjectable(value) {
30408 return (isFunction(value) || (isArray(value) && isFunction(value[value.length - 1])));
30412 * [Internal] Get the default value of a parameter, which may be an injectable function.
30414 $UrlMatcherFactory.$$getDefaultValue = function(config) {
30415 if (!isInjectable(config.value)) return config.value;
30416 if (!injector) throw new Error("Injectable functions cannot be called at configuration time");
30417 return injector.invoke(config.value);
30422 * @name ui.router.util.$urlMatcherFactory#caseInsensitive
30423 * @methodOf ui.router.util.$urlMatcherFactory
30426 * Defines whether URL matching should be case sensitive (the default behavior), or not.
30428 * @param {boolean} value `false` to match URL in a case sensitive manner; otherwise `true`;
30429 * @returns {boolean} the current value of caseInsensitive
30431 this.caseInsensitive = function(value) {
30432 if (isDefined(value))
30433 isCaseInsensitive = value;
30434 return isCaseInsensitive;
30439 * @name ui.router.util.$urlMatcherFactory#strictMode
30440 * @methodOf ui.router.util.$urlMatcherFactory
30443 * Defines whether URLs should match trailing slashes, or not (the default behavior).
30445 * @param {boolean=} value `false` to match trailing slashes in URLs, otherwise `true`.
30446 * @returns {boolean} the current value of strictMode
30448 this.strictMode = function(value) {
30449 if (isDefined(value))
30450 isStrictMode = value;
30451 return isStrictMode;
30456 * @name ui.router.util.$urlMatcherFactory#defaultSquashPolicy
30457 * @methodOf ui.router.util.$urlMatcherFactory
30460 * Sets the default behavior when generating or matching URLs with default parameter values.
30462 * @param {string} value A string that defines the default parameter URL squashing behavior.
30463 * `nosquash`: When generating an href with a default parameter value, do not squash the parameter value from the URL
30464 * `slash`: When generating an href with a default parameter value, squash (remove) the parameter value, and, if the
30465 * parameter is surrounded by slashes, squash (remove) one slash from the URL
30466 * any other string, e.g. "~": When generating an href with a default parameter value, squash (remove)
30467 * the parameter value from the URL and replace it with this string.
30469 this.defaultSquashPolicy = function(value) {
30470 if (!isDefined(value)) return defaultSquashPolicy;
30471 if (value !== true && value !== false && !isString(value))
30472 throw new Error("Invalid squash policy: " + value + ". Valid policies: false, true, arbitrary-string");
30473 defaultSquashPolicy = value;
30479 * @name ui.router.util.$urlMatcherFactory#compile
30480 * @methodOf ui.router.util.$urlMatcherFactory
30483 * Creates a {@link ui.router.util.type:UrlMatcher `UrlMatcher`} for the specified pattern.
30485 * @param {string} pattern The URL pattern.
30486 * @param {Object} config The config object hash.
30487 * @returns {UrlMatcher} The UrlMatcher.
30489 this.compile = function (pattern, config) {
30490 return new UrlMatcher(pattern, extend(getDefaultConfig(), config));
30495 * @name ui.router.util.$urlMatcherFactory#isMatcher
30496 * @methodOf ui.router.util.$urlMatcherFactory
30499 * Returns true if the specified object is a `UrlMatcher`, or false otherwise.
30501 * @param {Object} object The object to perform the type check against.
30502 * @returns {Boolean} Returns `true` if the object matches the `UrlMatcher` interface, by
30503 * implementing all the same methods.
30505 this.isMatcher = function (o) {
30506 if (!isObject(o)) return false;
30509 forEach(UrlMatcher.prototype, function(val, name) {
30510 if (isFunction(val)) {
30511 result = result && (isDefined(o[name]) && isFunction(o[name]));
30519 * @name ui.router.util.$urlMatcherFactory#type
30520 * @methodOf ui.router.util.$urlMatcherFactory
30523 * Registers a custom {@link ui.router.util.type:Type `Type`} object that can be used to
30524 * generate URLs with typed parameters.
30526 * @param {string} name The type name.
30527 * @param {Object|Function} definition The type definition. See
30528 * {@link ui.router.util.type:Type `Type`} for information on the values accepted.
30529 * @param {Object|Function} definitionFn (optional) A function that is injected before the app
30530 * runtime starts. The result of this function is merged into the existing `definition`.
30531 * See {@link ui.router.util.type:Type `Type`} for information on the values accepted.
30533 * @returns {Object} Returns `$urlMatcherFactoryProvider`.
30536 * This is a simple example of a custom type that encodes and decodes items from an
30537 * array, using the array index as the URL-encoded value:
30540 * var list = ['John', 'Paul', 'George', 'Ringo'];
30542 * $urlMatcherFactoryProvider.type('listItem', {
30543 * encode: function(item) {
30544 * // Represent the list item in the URL using its corresponding index
30545 * return list.indexOf(item);
30547 * decode: function(item) {
30548 * // Look up the list item by index
30549 * return list[parseInt(item, 10)];
30551 * is: function(item) {
30552 * // Ensure the item is valid by checking to see that it appears
30554 * return list.indexOf(item) > -1;
30558 * $stateProvider.state('list', {
30559 * url: "/list/{item:listItem}",
30560 * controller: function($scope, $stateParams) {
30561 * console.log($stateParams.item);
30567 * // Changes URL to '/list/3', logs "Ringo" to the console
30568 * $state.go('list', { item: "Ringo" });
30571 * This is a more complex example of a type that relies on dependency injection to
30572 * interact with services, and uses the parameter name from the URL to infer how to
30573 * handle encoding and decoding parameter values:
30576 * // Defines a custom type that gets a value from a service,
30577 * // where each service gets different types of values from
30578 * // a backend API:
30579 * $urlMatcherFactoryProvider.type('dbObject', {}, function(Users, Posts) {
30581 * // Matches up services to URL parameter names
30588 * encode: function(object) {
30589 * // Represent the object in the URL using its unique ID
30590 * return object.id;
30592 * decode: function(value, key) {
30593 * // Look up the object by ID, using the parameter
30594 * // name (key) to call the correct service
30595 * return services[key].findById(value);
30597 * is: function(object, key) {
30598 * // Check that object is a valid dbObject
30599 * return angular.isObject(object) && object.id && services[key];
30601 * equals: function(a, b) {
30602 * // Check the equality of decoded objects by comparing
30603 * // their unique IDs
30604 * return a.id === b.id;
30609 * // In a config() block, you can then attach URLs with
30610 * // type-annotated parameters:
30611 * $stateProvider.state('users', {
30614 * }).state('users.item', {
30615 * url: "/{user:dbObject}",
30616 * controller: function($scope, $stateParams) {
30617 * // $stateParams.user will now be an object returned from
30618 * // the Users service
30624 this.type = function (name, definition, definitionFn) {
30625 if (!isDefined(definition)) return $types[name];
30626 if ($types.hasOwnProperty(name)) throw new Error("A type named '" + name + "' has already been defined.");
30628 $types[name] = new Type(extend({ name: name }, definition));
30629 if (definitionFn) {
30630 typeQueue.push({ name: name, def: definitionFn });
30631 if (!enqueue) flushTypeQueue();
30636 // `flushTypeQueue()` waits until `$urlMatcherFactory` is injected before invoking the queued `definitionFn`s
30637 function flushTypeQueue() {
30638 while(typeQueue.length) {
30639 var type = typeQueue.shift();
30640 if (type.pattern) throw new Error("You cannot override a type's .pattern at runtime.");
30641 angular.extend($types[type.name], injector.invoke(type.def));
30645 // Register default types. Store them in the prototype of $types.
30646 forEach(defaultTypes, function(type, name) { $types[name] = new Type(extend({name: name}, type)); });
30647 $types = inherit($types, {});
30649 /* No need to document $get, since it returns this */
30650 this.$get = ['$injector', function ($injector) {
30651 injector = $injector;
30655 forEach(defaultTypes, function(type, name) {
30656 if (!$types[name]) $types[name] = new Type(type);
30661 this.Param = function Param(id, type, config, location) {
30663 config = unwrapShorthand(config);
30664 type = getType(config, type, location);
30665 var arrayMode = getArrayMode();
30666 type = arrayMode ? type.$asArray(arrayMode, location === "search") : type;
30667 if (type.name === "string" && !arrayMode && location === "path" && config.value === undefined)
30668 config.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to ""
30669 var isOptional = config.value !== undefined;
30670 var squash = getSquashPolicy(config, isOptional);
30671 var replace = getReplace(config, arrayMode, isOptional, squash);
30673 function unwrapShorthand(config) {
30674 var keys = isObject(config) ? objectKeys(config) : [];
30675 var isShorthand = indexOf(keys, "value") === -1 && indexOf(keys, "type") === -1 &&
30676 indexOf(keys, "squash") === -1 && indexOf(keys, "array") === -1;
30677 if (isShorthand) config = { value: config };
30678 config.$$fn = isInjectable(config.value) ? config.value : function () { return config.value; };
30682 function getType(config, urlType, location) {
30683 if (config.type && urlType) throw new Error("Param '"+id+"' has two type configurations.");
30684 if (urlType) return urlType;
30685 if (!config.type) return (location === "config" ? $types.any : $types.string);
30686 return config.type instanceof Type ? config.type : new Type(config.type);
30689 // array config: param name (param[]) overrides default settings. explicit config overrides param name.
30690 function getArrayMode() {
30691 var arrayDefaults = { array: (location === "search" ? "auto" : false) };
30692 var arrayParamNomenclature = id.match(/\[\]$/) ? { array: true } : {};
30693 return extend(arrayDefaults, arrayParamNomenclature, config).array;
30697 * returns false, true, or the squash value to indicate the "default parameter url squash policy".
30699 function getSquashPolicy(config, isOptional) {
30700 var squash = config.squash;
30701 if (!isOptional || squash === false) return false;
30702 if (!isDefined(squash) || squash == null) return defaultSquashPolicy;
30703 if (squash === true || isString(squash)) return squash;
30704 throw new Error("Invalid squash policy: '" + squash + "'. Valid policies: false, true, or arbitrary string");
30707 function getReplace(config, arrayMode, isOptional, squash) {
30708 var replace, configuredKeys, defaultPolicy = [
30709 { from: "", to: (isOptional || arrayMode ? undefined : "") },
30710 { from: null, to: (isOptional || arrayMode ? undefined : "") }
30712 replace = isArray(config.replace) ? config.replace : [];
30713 if (isString(squash))
30714 replace.push({ from: squash, to: undefined });
30715 configuredKeys = map(replace, function(item) { return item.from; } );
30716 return filter(defaultPolicy, function(item) { return indexOf(configuredKeys, item.from) === -1; }).concat(replace);
30720 * [Internal] Get the default value of a parameter, which may be an injectable function.
30722 function $$getDefaultValue() {
30723 if (!injector) throw new Error("Injectable functions cannot be called at configuration time");
30724 var defaultValue = injector.invoke(config.$$fn);
30725 if (defaultValue !== null && defaultValue !== undefined && !self.type.is(defaultValue))
30726 throw new Error("Default value (" + defaultValue + ") for parameter '" + self.id + "' is not an instance of Type (" + self.type.name + ")");
30727 return defaultValue;
30731 * [Internal] Gets the decoded representation of a value if the value is defined, otherwise, returns the
30732 * default value, which may be the result of an injectable function.
30734 function $value(value) {
30735 function hasReplaceVal(val) { return function(obj) { return obj.from === val; }; }
30736 function $replace(value) {
30737 var replacement = map(filter(self.replace, hasReplaceVal(value)), function(obj) { return obj.to; });
30738 return replacement.length ? replacement[0] : value;
30740 value = $replace(value);
30741 return !isDefined(value) ? $$getDefaultValue() : self.type.$normalize(value);
30744 function toString() { return "{Param:" + id + " " + type + " squash: '" + squash + "' optional: " + isOptional + "}"; }
30749 location: location,
30753 isOptional: isOptional,
30755 dynamic: undefined,
30761 function ParamSet(params) {
30762 extend(this, params || {});
30765 ParamSet.prototype = {
30766 $$new: function() {
30767 return inherit(this, extend(new ParamSet(), { $$parent: this}));
30769 $$keys: function () {
30770 var keys = [], chain = [], parent = this,
30771 ignore = objectKeys(ParamSet.prototype);
30772 while (parent) { chain.push(parent); parent = parent.$$parent; }
30774 forEach(chain, function(paramset) {
30775 forEach(objectKeys(paramset), function(key) {
30776 if (indexOf(keys, key) === -1 && indexOf(ignore, key) === -1) keys.push(key);
30781 $$values: function(paramValues) {
30782 var values = {}, self = this;
30783 forEach(self.$$keys(), function(key) {
30784 values[key] = self[key].value(paramValues && paramValues[key]);
30788 $$equals: function(paramValues1, paramValues2) {
30789 var equal = true, self = this;
30790 forEach(self.$$keys(), function(key) {
30791 var left = paramValues1 && paramValues1[key], right = paramValues2 && paramValues2[key];
30792 if (!self[key].type.equals(left, right)) equal = false;
30796 $$validates: function $$validate(paramValues) {
30797 var keys = this.$$keys(), i, param, rawVal, normalized, encoded;
30798 for (i = 0; i < keys.length; i++) {
30799 param = this[keys[i]];
30800 rawVal = paramValues[keys[i]];
30801 if ((rawVal === undefined || rawVal === null) && param.isOptional)
30802 break; // There was no parameter value, but the param is optional
30803 normalized = param.type.$normalize(rawVal);
30804 if (!param.type.is(normalized))
30805 return false; // The value was not of the correct Type, and could not be decoded to the correct Type
30806 encoded = param.type.encode(normalized);
30807 if (angular.isString(encoded) && !param.type.pattern.exec(encoded))
30808 return false; // The value was of the correct type, but when encoded, did not match the Type's regexp
30812 $$parent: undefined
30815 this.ParamSet = ParamSet;
30818 // Register as a provider so it's available to other providers
30819 angular.module('ui.router.util').provider('$urlMatcherFactory', $UrlMatcherFactory);
30820 angular.module('ui.router.util').run(['$urlMatcherFactory', function($urlMatcherFactory) { }]);
30824 * @name ui.router.router.$urlRouterProvider
30826 * @requires ui.router.util.$urlMatcherFactoryProvider
30827 * @requires $locationProvider
30830 * `$urlRouterProvider` has the responsibility of watching `$location`.
30831 * When `$location` changes it runs through a list of rules one by one until a
30832 * match is found. `$urlRouterProvider` is used behind the scenes anytime you specify
30833 * a url in a state configuration. All urls are compiled into a UrlMatcher object.
30835 * There are several methods on `$urlRouterProvider` that make it useful to use directly
30836 * in your module config.
30838 $UrlRouterProvider.$inject = ['$locationProvider', '$urlMatcherFactoryProvider'];
30839 function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
30840 var rules = [], otherwise = null, interceptDeferred = false, listener;
30842 // Returns a string that is a prefix of all strings matching the RegExp
30843 function regExpPrefix(re) {
30844 var prefix = /^\^((?:\\[^a-zA-Z0-9]|[^\\\[\]\^$*+?.()|{}]+)*)/.exec(re.source);
30845 return (prefix != null) ? prefix[1].replace(/\\(.)/g, "$1") : '';
30848 // Interpolates matched values into a String.replace()-style pattern
30849 function interpolate(pattern, match) {
30850 return pattern.replace(/\$(\$|\d{1,2})/, function (m, what) {
30851 return match[what === '$' ? 0 : Number(what)];
30857 * @name ui.router.router.$urlRouterProvider#rule
30858 * @methodOf ui.router.router.$urlRouterProvider
30861 * Defines rules that are used by `$urlRouterProvider` to find matches for
30866 * var app = angular.module('app', ['ui.router.router']);
30868 * app.config(function ($urlRouterProvider) {
30869 * // Here's an example of how you might allow case insensitive urls
30870 * $urlRouterProvider.rule(function ($injector, $location) {
30871 * var path = $location.path(),
30872 * normalized = path.toLowerCase();
30874 * if (path !== normalized) {
30875 * return normalized;
30881 * @param {object} rule Handler function that takes `$injector` and `$location`
30882 * services as arguments. You can use them to return a valid path as a string.
30884 * @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance
30886 this.rule = function (rule) {
30887 if (!isFunction(rule)) throw new Error("'rule' must be a function");
30894 * @name ui.router.router.$urlRouterProvider#otherwise
30895 * @methodOf ui.router.router.$urlRouterProvider
30898 * Defines a path that is used when an invalid route is requested.
30902 * var app = angular.module('app', ['ui.router.router']);
30904 * app.config(function ($urlRouterProvider) {
30905 * // if the path doesn't match any of the urls you configured
30906 * // otherwise will take care of routing the user to the
30908 * $urlRouterProvider.otherwise('/index');
30910 * // Example of using function rule as param
30911 * $urlRouterProvider.otherwise(function ($injector, $location) {
30912 * return '/a/valid/url';
30917 * @param {string|object} rule The url path you want to redirect to or a function
30918 * rule that returns the url path. The function version is passed two params:
30919 * `$injector` and `$location` services, and must return a url string.
30921 * @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance
30923 this.otherwise = function (rule) {
30924 if (isString(rule)) {
30925 var redirect = rule;
30926 rule = function () { return redirect; };
30928 else if (!isFunction(rule)) throw new Error("'rule' must be a function");
30934 function handleIfMatch($injector, handler, match) {
30935 if (!match) return false;
30936 var result = $injector.invoke(handler, handler, { $match: match });
30937 return isDefined(result) ? result : true;
30942 * @name ui.router.router.$urlRouterProvider#when
30943 * @methodOf ui.router.router.$urlRouterProvider
30946 * Registers a handler for a given url matching. if handle is a string, it is
30947 * treated as a redirect, and is interpolated according to the syntax of match
30948 * (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise).
30950 * If the handler is a function, it is injectable. It gets invoked if `$location`
30951 * matches. You have the option of inject the match object as `$match`.
30953 * The handler can return
30955 * - **falsy** to indicate that the rule didn't match after all, then `$urlRouter`
30956 * will continue trying to find another one that matches.
30957 * - **string** which is treated as a redirect and passed to `$location.url()`
30958 * - **void** or any **truthy** value tells `$urlRouter` that the url was handled.
30962 * var app = angular.module('app', ['ui.router.router']);
30964 * app.config(function ($urlRouterProvider) {
30965 * $urlRouterProvider.when($state.url, function ($match, $stateParams) {
30966 * if ($state.$current.navigable !== state ||
30967 * !equalForKeys($match, $stateParams) {
30968 * $state.transitionTo(state, $match, false);
30974 * @param {string|object} what The incoming path that you want to redirect.
30975 * @param {string|object} handler The path you want to redirect your user to.
30977 this.when = function (what, handler) {
30978 var redirect, handlerIsString = isString(handler);
30979 if (isString(what)) what = $urlMatcherFactory.compile(what);
30981 if (!handlerIsString && !isFunction(handler) && !isArray(handler))
30982 throw new Error("invalid 'handler' in when()");
30985 matcher: function (what, handler) {
30986 if (handlerIsString) {
30987 redirect = $urlMatcherFactory.compile(handler);
30988 handler = ['$match', function ($match) { return redirect.format($match); }];
30990 return extend(function ($injector, $location) {
30991 return handleIfMatch($injector, handler, what.exec($location.path(), $location.search()));
30993 prefix: isString(what.prefix) ? what.prefix : ''
30996 regex: function (what, handler) {
30997 if (what.global || what.sticky) throw new Error("when() RegExp must not be global or sticky");
30999 if (handlerIsString) {
31000 redirect = handler;
31001 handler = ['$match', function ($match) { return interpolate(redirect, $match); }];
31003 return extend(function ($injector, $location) {
31004 return handleIfMatch($injector, handler, what.exec($location.path()));
31006 prefix: regExpPrefix(what)
31011 var check = { matcher: $urlMatcherFactory.isMatcher(what), regex: what instanceof RegExp };
31013 for (var n in check) {
31014 if (check[n]) return this.rule(strategies[n](what, handler));
31017 throw new Error("invalid 'what' in when()");
31022 * @name ui.router.router.$urlRouterProvider#deferIntercept
31023 * @methodOf ui.router.router.$urlRouterProvider
31026 * Disables (or enables) deferring location change interception.
31028 * If you wish to customize the behavior of syncing the URL (for example, if you wish to
31029 * defer a transition but maintain the current URL), call this method at configuration time.
31030 * Then, at run time, call `$urlRouter.listen()` after you have configured your own
31031 * `$locationChangeSuccess` event handler.
31035 * var app = angular.module('app', ['ui.router.router']);
31037 * app.config(function ($urlRouterProvider) {
31039 * // Prevent $urlRouter from automatically intercepting URL changes;
31040 * // this allows you to configure custom behavior in between
31041 * // location changes and route synchronization:
31042 * $urlRouterProvider.deferIntercept();
31044 * }).run(function ($rootScope, $urlRouter, UserService) {
31046 * $rootScope.$on('$locationChangeSuccess', function(e) {
31047 * // UserService is an example service for managing user state
31048 * if (UserService.isLoggedIn()) return;
31050 * // Prevent $urlRouter's default handler from firing
31051 * e.preventDefault();
31053 * UserService.handleLogin().then(function() {
31054 * // Once the user has logged in, sync the current URL
31055 * // to the router:
31056 * $urlRouter.sync();
31060 * // Configures $urlRouter's listener *after* your custom listener
31061 * $urlRouter.listen();
31065 * @param {boolean} defer Indicates whether to defer location change interception. Passing
31066 no parameter is equivalent to `true`.
31068 this.deferIntercept = function (defer) {
31069 if (defer === undefined) defer = true;
31070 interceptDeferred = defer;
31075 * @name ui.router.router.$urlRouter
31077 * @requires $location
31078 * @requires $rootScope
31079 * @requires $injector
31080 * @requires $browser
31086 $get.$inject = ['$location', '$rootScope', '$injector', '$browser'];
31087 function $get( $location, $rootScope, $injector, $browser) {
31089 var baseHref = $browser.baseHref(), location = $location.url(), lastPushedUrl;
31091 function appendBasePath(url, isHtml5, absolute) {
31092 if (baseHref === '/') return url;
31093 if (isHtml5) return baseHref.slice(0, -1) + url;
31094 if (absolute) return baseHref.slice(1) + url;
31098 // TODO: Optimize groups of rules with non-empty prefix into some sort of decision tree
31099 function update(evt) {
31100 if (evt && evt.defaultPrevented) return;
31101 var ignoreUpdate = lastPushedUrl && $location.url() === lastPushedUrl;
31102 lastPushedUrl = undefined;
31103 // TODO: Re-implement this in 1.0 for https://github.com/angular-ui/ui-router/issues/1573
31104 //if (ignoreUpdate) return true;
31106 function check(rule) {
31107 var handled = rule($injector, $location);
31109 if (!handled) return false;
31110 if (isString(handled)) $location.replace().url(handled);
31113 var n = rules.length, i;
31115 for (i = 0; i < n; i++) {
31116 if (check(rules[i])) return;
31118 // always check otherwise last to allow dynamic updates to the set of rules
31119 if (otherwise) check(otherwise);
31122 function listen() {
31123 listener = listener || $rootScope.$on('$locationChangeSuccess', update);
31127 if (!interceptDeferred) listen();
31132 * @name ui.router.router.$urlRouter#sync
31133 * @methodOf ui.router.router.$urlRouter
31136 * Triggers an update; the same update that happens when the address bar url changes, aka `$locationChangeSuccess`.
31137 * This method is useful when you need to use `preventDefault()` on the `$locationChangeSuccess` event,
31138 * perform some custom logic (route protection, auth, config, redirection, etc) and then finally proceed
31139 * with the transition by calling `$urlRouter.sync()`.
31143 * angular.module('app', ['ui.router'])
31144 * .run(function($rootScope, $urlRouter) {
31145 * $rootScope.$on('$locationChangeSuccess', function(evt) {
31146 * // Halt state change from even starting
31147 * evt.preventDefault();
31148 * // Perform custom logic
31149 * var meetsRequirement = ...
31150 * // Continue with the update and state transition if logic allows
31151 * if (meetsRequirement) $urlRouter.sync();
31160 listen: function() {
31164 update: function(read) {
31166 location = $location.url();
31169 if ($location.url() === location) return;
31171 $location.url(location);
31172 $location.replace();
31175 push: function(urlMatcher, params, options) {
31176 var url = urlMatcher.format(params || {});
31178 // Handle the special hash param, if needed
31179 if (url !== null && params && params['#']) {
31180 url += '#' + params['#'];
31183 $location.url(url);
31184 lastPushedUrl = options && options.$$avoidResync ? $location.url() : undefined;
31185 if (options && options.replace) $location.replace();
31190 * @name ui.router.router.$urlRouter#href
31191 * @methodOf ui.router.router.$urlRouter
31194 * A URL generation method that returns the compiled URL for a given
31195 * {@link ui.router.util.type:UrlMatcher `UrlMatcher`}, populated with the provided parameters.
31199 * $bob = $urlRouter.href(new UrlMatcher("/about/:person"), {
31202 * // $bob == "/about/bob";
31205 * @param {UrlMatcher} urlMatcher The `UrlMatcher` object which is used as the template of the URL to generate.
31206 * @param {object=} params An object of parameter values to fill the matcher's required parameters.
31207 * @param {object=} options Options object. The options are:
31209 * - **`absolute`** - {boolean=false}, If true will generate an absolute url, e.g. "http://www.example.com/fullurl".
31211 * @returns {string} Returns the fully compiled URL, or `null` if `params` fail validation against `urlMatcher`
31213 href: function(urlMatcher, params, options) {
31214 if (!urlMatcher.validates(params)) return null;
31216 var isHtml5 = $locationProvider.html5Mode();
31217 if (angular.isObject(isHtml5)) {
31218 isHtml5 = isHtml5.enabled;
31221 var url = urlMatcher.format(params);
31222 options = options || {};
31224 if (!isHtml5 && url !== null) {
31225 url = "#" + $locationProvider.hashPrefix() + url;
31228 // Handle special hash param, if needed
31229 if (url !== null && params && params['#']) {
31230 url += '#' + params['#'];
31233 url = appendBasePath(url, isHtml5, options.absolute);
31235 if (!options.absolute || !url) {
31239 var slash = (!isHtml5 && url ? '/' : ''), port = $location.port();
31240 port = (port === 80 || port === 443 ? '' : ':' + port);
31242 return [$location.protocol(), '://', $location.host(), port, slash, url].join('');
31248 angular.module('ui.router.router').provider('$urlRouter', $UrlRouterProvider);
31252 * @name ui.router.state.$stateProvider
31254 * @requires ui.router.router.$urlRouterProvider
31255 * @requires ui.router.util.$urlMatcherFactoryProvider
31258 * The new `$stateProvider` works similar to Angular's v1 router, but it focuses purely
31261 * A state corresponds to a "place" in the application in terms of the overall UI and
31262 * navigation. A state describes (via the controller / template / view properties) what
31263 * the UI looks like and does at that place.
31265 * States often have things in common, and the primary way of factoring out these
31266 * commonalities in this model is via the state hierarchy, i.e. parent/child states aka
31269 * The `$stateProvider` provides interfaces to declare these states for your app.
31271 $StateProvider.$inject = ['$urlRouterProvider', '$urlMatcherFactoryProvider'];
31272 function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
31274 var root, states = {}, $state, queue = {}, abstractKey = 'abstract';
31276 // Builds state properties from definition passed to registerState()
31277 var stateBuilder = {
31279 // Derive parent state from a hierarchical name only if 'parent' is not explicitly defined.
31280 // state.children = [];
31281 // if (parent) parent.children.push(state);
31282 parent: function(state) {
31283 if (isDefined(state.parent) && state.parent) return findState(state.parent);
31284 // regex matches any valid composite state name
31285 // would match "contact.list" but not "contacts"
31286 var compositeName = /^(.+)\.[^.]+$/.exec(state.name);
31287 return compositeName ? findState(compositeName[1]) : root;
31290 // inherit 'data' from parent and override by own values (if any)
31291 data: function(state) {
31292 if (state.parent && state.parent.data) {
31293 state.data = state.self.data = extend({}, state.parent.data, state.data);
31298 // Build a URLMatcher if necessary, either via a relative or absolute URL
31299 url: function(state) {
31300 var url = state.url, config = { params: state.params || {} };
31302 if (isString(url)) {
31303 if (url.charAt(0) == '^') return $urlMatcherFactory.compile(url.substring(1), config);
31304 return (state.parent.navigable || root).url.concat(url, config);
31307 if (!url || $urlMatcherFactory.isMatcher(url)) return url;
31308 throw new Error("Invalid url '" + url + "' in state '" + state + "'");
31311 // Keep track of the closest ancestor state that has a URL (i.e. is navigable)
31312 navigable: function(state) {
31313 return state.url ? state : (state.parent ? state.parent.navigable : null);
31316 // Own parameters for this state. state.url.params is already built at this point. Create and add non-url params
31317 ownParams: function(state) {
31318 var params = state.url && state.url.params || new $$UMFP.ParamSet();
31319 forEach(state.params || {}, function(config, id) {
31320 if (!params[id]) params[id] = new $$UMFP.Param(id, null, config, "config");
31325 // Derive parameters for this state and ensure they're a super-set of parent's parameters
31326 params: function(state) {
31327 return state.parent && state.parent.params ? extend(state.parent.params.$$new(), state.ownParams) : new $$UMFP.ParamSet();
31330 // If there is no explicit multi-view configuration, make one up so we don't have
31331 // to handle both cases in the view directive later. Note that having an explicit
31332 // 'views' property will mean the default unnamed view properties are ignored. This
31333 // is also a good time to resolve view names to absolute names, so everything is a
31334 // straight lookup at link time.
31335 views: function(state) {
31338 forEach(isDefined(state.views) ? state.views : { '': state }, function (view, name) {
31339 if (name.indexOf('@') < 0) name += '@' + state.parent.name;
31340 views[name] = view;
31345 // Keep a full path from the root down to this state as this is needed for state activation.
31346 path: function(state) {
31347 return state.parent ? state.parent.path.concat(state) : []; // exclude root from path
31350 // Speed up $state.contains() as it's used a lot
31351 includes: function(state) {
31352 var includes = state.parent ? extend({}, state.parent.includes) : {};
31353 includes[state.name] = true;
31360 function isRelative(stateName) {
31361 return stateName.indexOf(".") === 0 || stateName.indexOf("^") === 0;
31364 function findState(stateOrName, base) {
31365 if (!stateOrName) return undefined;
31367 var isStr = isString(stateOrName),
31368 name = isStr ? stateOrName : stateOrName.name,
31369 path = isRelative(name);
31372 if (!base) throw new Error("No reference point given for path '" + name + "'");
31373 base = findState(base);
31375 var rel = name.split("."), i = 0, pathLength = rel.length, current = base;
31377 for (; i < pathLength; i++) {
31378 if (rel[i] === "" && i === 0) {
31382 if (rel[i] === "^") {
31383 if (!current.parent) throw new Error("Path '" + name + "' not valid for state '" + base.name + "'");
31384 current = current.parent;
31389 rel = rel.slice(i).join(".");
31390 name = current.name + (current.name && rel ? "." : "") + rel;
31392 var state = states[name];
31394 if (state && (isStr || (!isStr && (state === stateOrName || state.self === stateOrName)))) {
31400 function queueState(parentName, state) {
31401 if (!queue[parentName]) {
31402 queue[parentName] = [];
31404 queue[parentName].push(state);
31407 function flushQueuedChildren(parentName) {
31408 var queued = queue[parentName] || [];
31409 while(queued.length) {
31410 registerState(queued.shift());
31414 function registerState(state) {
31415 // Wrap a new object around the state so we can store our private details easily.
31416 state = inherit(state, {
31418 resolve: state.resolve || {},
31419 toString: function() { return this.name; }
31422 var name = state.name;
31423 if (!isString(name) || name.indexOf('@') >= 0) throw new Error("State must have a valid name");
31424 if (states.hasOwnProperty(name)) throw new Error("State '" + name + "'' is already defined");
31427 var parentName = (name.indexOf('.') !== -1) ? name.substring(0, name.lastIndexOf('.'))
31428 : (isString(state.parent)) ? state.parent
31429 : (isObject(state.parent) && isString(state.parent.name)) ? state.parent.name
31432 // If parent is not registered yet, add state to queue and register later
31433 if (parentName && !states[parentName]) {
31434 return queueState(parentName, state.self);
31437 for (var key in stateBuilder) {
31438 if (isFunction(stateBuilder[key])) state[key] = stateBuilder[key](state, stateBuilder.$delegates[key]);
31440 states[name] = state;
31442 // Register the state in the global state list and with $urlRouter if necessary.
31443 if (!state[abstractKey] && state.url) {
31444 $urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
31445 if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
31446 $state.transitionTo(state, $match, { inherit: true, location: false });
31451 // Register any queued children
31452 flushQueuedChildren(name);
31457 // Checks text to see if it looks like a glob.
31458 function isGlob (text) {
31459 return text.indexOf('*') > -1;
31462 // Returns true if glob matches current $state name.
31463 function doesStateMatchGlob (glob) {
31464 var globSegments = glob.split('.'),
31465 segments = $state.$current.name.split('.');
31467 //match single stars
31468 for (var i = 0, l = globSegments.length; i < l; i++) {
31469 if (globSegments[i] === '*') {
31474 //match greedy starts
31475 if (globSegments[0] === '**') {
31476 segments = segments.slice(indexOf(segments, globSegments[1]));
31477 segments.unshift('**');
31479 //match greedy ends
31480 if (globSegments[globSegments.length - 1] === '**') {
31481 segments.splice(indexOf(segments, globSegments[globSegments.length - 2]) + 1, Number.MAX_VALUE);
31482 segments.push('**');
31485 if (globSegments.length != segments.length) {
31489 return segments.join('') === globSegments.join('');
31493 // Implicit root state that is always active
31494 root = registerState({
31500 root.navigable = null;
31505 * @name ui.router.state.$stateProvider#decorator
31506 * @methodOf ui.router.state.$stateProvider
31509 * Allows you to extend (carefully) or override (at your own peril) the
31510 * `stateBuilder` object used internally by `$stateProvider`. This can be used
31511 * to add custom functionality to ui-router, for example inferring templateUrl
31512 * based on the state name.
31514 * When passing only a name, it returns the current (original or decorated) builder
31515 * function that matches `name`.
31517 * The builder functions that can be decorated are listed below. Though not all
31518 * necessarily have a good use case for decoration, that is up to you to decide.
31520 * In addition, users can attach custom decorators, which will generate new
31521 * properties within the state's internal definition. There is currently no clear
31522 * use-case for this beyond accessing internal states (i.e. $state.$current),
31523 * however, expect this to become increasingly relevant as we introduce additional
31524 * meta-programming features.
31526 * **Warning**: Decorators should not be interdependent because the order of
31527 * execution of the builder functions in non-deterministic. Builder functions
31528 * should only be dependent on the state definition object and super function.
31531 * Existing builder functions and current return values:
31533 * - **parent** `{object}` - returns the parent state object.
31534 * - **data** `{object}` - returns state data, including any inherited data that is not
31535 * overridden by own values (if any).
31536 * - **url** `{object}` - returns a {@link ui.router.util.type:UrlMatcher UrlMatcher}
31538 * - **navigable** `{object}` - returns closest ancestor state that has a URL (aka is
31540 * - **params** `{object}` - returns an array of state params that are ensured to
31541 * be a super-set of parent's params.
31542 * - **views** `{object}` - returns a views object where each key is an absolute view
31543 * name (i.e. "viewName@stateName") and each value is the config object
31544 * (template, controller) for the view. Even when you don't use the views object
31545 * explicitly on a state config, one is still created for you internally.
31546 * So by decorating this builder function you have access to decorating template
31547 * and controller properties.
31548 * - **ownParams** `{object}` - returns an array of params that belong to the state,
31549 * not including any params defined by ancestor states.
31550 * - **path** `{string}` - returns the full path from the root down to this state.
31551 * Needed for state activation.
31552 * - **includes** `{object}` - returns an object that includes every state that
31553 * would pass a `$state.includes()` test.
31557 * // Override the internal 'views' builder with a function that takes the state
31558 * // definition, and a reference to the internal function being overridden:
31559 * $stateProvider.decorator('views', function (state, parent) {
31561 * views = parent(state);
31563 * angular.forEach(views, function (config, name) {
31564 * var autoName = (state.name + '.' + name).replace('.', '/');
31565 * config.templateUrl = config.templateUrl || '/partials/' + autoName + '.html';
31566 * result[name] = config;
31571 * $stateProvider.state('home', {
31573 * 'contact.list': { controller: 'ListController' },
31574 * 'contact.item': { controller: 'ItemController' }
31580 * $state.go('home');
31581 * // Auto-populates list and item views with /partials/home/contact/list.html,
31582 * // and /partials/home/contact/item.html, respectively.
31585 * @param {string} name The name of the builder function to decorate.
31586 * @param {object} func A function that is responsible for decorating the original
31587 * builder function. The function receives two parameters:
31589 * - `{object}` - state - The state config object.
31590 * - `{object}` - super - The original builder function.
31592 * @return {object} $stateProvider - $stateProvider instance
31594 this.decorator = decorator;
31595 function decorator(name, func) {
31596 /*jshint validthis: true */
31597 if (isString(name) && !isDefined(func)) {
31598 return stateBuilder[name];
31600 if (!isFunction(func) || !isString(name)) {
31603 if (stateBuilder[name] && !stateBuilder.$delegates[name]) {
31604 stateBuilder.$delegates[name] = stateBuilder[name];
31606 stateBuilder[name] = func;
31612 * @name ui.router.state.$stateProvider#state
31613 * @methodOf ui.router.state.$stateProvider
31616 * Registers a state configuration under a given state name. The stateConfig object
31617 * has the following acceptable properties.
31619 * @param {string} name A unique state name, e.g. "home", "about", "contacts".
31620 * To create a parent/child state use a dot, e.g. "about.sales", "home.newest".
31621 * @param {object} stateConfig State configuration object.
31622 * @param {string|function=} stateConfig.template
31623 * <a id='template'></a>
31624 * html template as a string or a function that returns
31625 * an html template as a string which should be used by the uiView directives. This property
31626 * takes precedence over templateUrl.
31628 * If `template` is a function, it will be called with the following parameters:
31630 * - {array.<object>} - state parameters extracted from the current $location.path() by
31631 * applying the current state
31634 * "<h1>inline template definition</h1>" +
31635 * "<div ui-view></div>"</pre>
31636 * <pre>template: function(params) {
31637 * return "<h1>generated template</h1>"; }</pre>
31640 * @param {string|function=} stateConfig.templateUrl
31641 * <a id='templateUrl'></a>
31643 * path or function that returns a path to an html
31644 * template that should be used by uiView.
31646 * If `templateUrl` is a function, it will be called with the following parameters:
31648 * - {array.<object>} - state parameters extracted from the current $location.path() by
31649 * applying the current state
31651 * <pre>templateUrl: "home.html"</pre>
31652 * <pre>templateUrl: function(params) {
31653 * return myTemplates[params.pageId]; }</pre>
31655 * @param {function=} stateConfig.templateProvider
31656 * <a id='templateProvider'></a>
31657 * Provider function that returns HTML content string.
31658 * <pre> templateProvider:
31659 * function(MyTemplateService, params) {
31660 * return MyTemplateService.getTemplate(params.pageId);
31663 * @param {string|function=} stateConfig.controller
31664 * <a id='controller'></a>
31666 * Controller fn that should be associated with newly
31667 * related scope or the name of a registered controller if passed as a string.
31668 * Optionally, the ControllerAs may be declared here.
31669 * <pre>controller: "MyRegisteredController"</pre>
31671 * "MyRegisteredController as fooCtrl"}</pre>
31672 * <pre>controller: function($scope, MyService) {
31673 * $scope.data = MyService.getData(); }</pre>
31675 * @param {function=} stateConfig.controllerProvider
31676 * <a id='controllerProvider'></a>
31678 * Injectable provider function that returns the actual controller or string.
31679 * <pre>controllerProvider:
31680 * function(MyResolveData) {
31681 * if (MyResolveData.foo)
31683 * else if (MyResolveData.bar)
31684 * return "BarCtrl";
31685 * else return function($scope) {
31686 * $scope.baz = "Qux";
31690 * @param {string=} stateConfig.controllerAs
31691 * <a id='controllerAs'></a>
31693 * A controller alias name. If present the controller will be
31694 * published to scope under the controllerAs name.
31695 * <pre>controllerAs: "myCtrl"</pre>
31697 * @param {string|object=} stateConfig.parent
31698 * <a id='parent'></a>
31699 * Optionally specifies the parent state of this state.
31701 * <pre>parent: 'parentState'</pre>
31702 * <pre>parent: parentState // JS variable</pre>
31704 * @param {object=} stateConfig.resolve
31705 * <a id='resolve'></a>
31707 * An optional map<string, function> of dependencies which
31708 * should be injected into the controller. If any of these dependencies are promises,
31709 * the router will wait for them all to be resolved before the controller is instantiated.
31710 * If all the promises are resolved successfully, the $stateChangeSuccess event is fired
31711 * and the values of the resolved promises are injected into any controllers that reference them.
31712 * If any of the promises are rejected the $stateChangeError event is fired.
31714 * The map object is:
31716 * - key - {string}: name of dependency to be injected into controller
31717 * - factory - {string|function}: If string then it is alias for service. Otherwise if function,
31718 * it is injected and return value it treated as dependency. If result is a promise, it is
31719 * resolved before its value is injected into controller.
31723 * function($http, $stateParams) {
31724 * return $http.get("/api/foos/"+stateParams.fooID);
31728 * @param {string=} stateConfig.url
31731 * A url fragment with optional parameters. When a state is navigated or
31732 * transitioned to, the `$stateParams` service will be populated with any
31733 * parameters that were passed.
31735 * (See {@link ui.router.util.type:UrlMatcher UrlMatcher} `UrlMatcher`} for
31736 * more details on acceptable patterns )
31739 * <pre>url: "/home"
31740 * url: "/users/:userid"
31741 * url: "/books/{bookid:[a-zA-Z_-]}"
31742 * url: "/books/{categoryid:int}"
31743 * url: "/books/{publishername:string}/{categoryid:int}"
31744 * url: "/messages?before&after"
31745 * url: "/messages?{before:date}&{after:date}"
31746 * url: "/messages/:mailboxid?{before:date}&{after:date}"
31749 * @param {object=} stateConfig.views
31750 * <a id='views'></a>
31751 * an optional map<string, object> which defined multiple views, or targets views
31752 * manually/explicitly.
31756 * Targets three named `ui-view`s in the parent state's template
31759 * controller: "headerCtrl",
31760 * templateUrl: "header.html"
31762 * controller: "bodyCtrl",
31763 * templateUrl: "body.html"
31765 * controller: "footCtrl",
31766 * templateUrl: "footer.html"
31770 * Targets named `ui-view="header"` from grandparent state 'top''s template, and named `ui-view="body" from parent state's template.
31773 * controller: "msgHeaderCtrl",
31774 * templateUrl: "msgHeader.html"
31776 * controller: "messagesCtrl",
31777 * templateUrl: "messages.html"
31781 * @param {boolean=} [stateConfig.abstract=false]
31782 * <a id='abstract'></a>
31783 * An abstract state will never be directly activated,
31784 * but can provide inherited properties to its common children states.
31785 * <pre>abstract: true</pre>
31787 * @param {function=} stateConfig.onEnter
31788 * <a id='onEnter'></a>
31790 * Callback function for when a state is entered. Good way
31791 * to trigger an action or dispatch an event, such as opening a dialog.
31792 * If minifying your scripts, make sure to explictly annotate this function,
31793 * because it won't be automatically annotated by your build tools.
31795 * <pre>onEnter: function(MyService, $stateParams) {
31796 * MyService.foo($stateParams.myParam);
31799 * @param {function=} stateConfig.onExit
31800 * <a id='onExit'></a>
31802 * Callback function for when a state is exited. Good way to
31803 * trigger an action or dispatch an event, such as opening a dialog.
31804 * If minifying your scripts, make sure to explictly annotate this function,
31805 * because it won't be automatically annotated by your build tools.
31807 * <pre>onExit: function(MyService, $stateParams) {
31808 * MyService.cleanup($stateParams.myParam);
31811 * @param {boolean=} [stateConfig.reloadOnSearch=true]
31812 * <a id='reloadOnSearch'></a>
31814 * If `false`, will not retrigger the same state
31815 * just because a search/query parameter has changed (via $location.search() or $location.hash()).
31816 * Useful for when you'd like to modify $location.search() without triggering a reload.
31817 * <pre>reloadOnSearch: false</pre>
31819 * @param {object=} stateConfig.data
31820 * <a id='data'></a>
31822 * Arbitrary data object, useful for custom configuration. The parent state's `data` is
31823 * prototypally inherited. In other words, adding a data property to a state adds it to
31824 * the entire subtree via prototypal inheritance.
31827 * requiredRole: 'foo'
31830 * @param {object=} stateConfig.params
31831 * <a id='params'></a>
31833 * A map which optionally configures parameters declared in the `url`, or
31834 * defines additional non-url parameters. For each parameter being
31835 * configured, add a configuration object keyed to the name of the parameter.
31837 * Each parameter configuration object may contain the following properties:
31839 * - ** value ** - {object|function=}: specifies the default value for this
31840 * parameter. This implicitly sets this parameter as optional.
31842 * When UI-Router routes to a state and no value is
31843 * specified for this parameter in the URL or transition, the
31844 * default value will be used instead. If `value` is a function,
31845 * it will be injected and invoked, and the return value used.
31847 * *Note*: `undefined` is treated as "no default value" while `null`
31848 * is treated as "the default value is `null`".
31850 * *Shorthand*: If you only need to configure the default value of the
31851 * parameter, you may use a shorthand syntax. In the **`params`**
31852 * map, instead mapping the param name to a full parameter configuration
31853 * object, simply set map it to the default parameter value, e.g.:
31855 * <pre>// define a parameter's default value
31857 * param1: { value: "defaultValue" }
31859 * // shorthand default values
31861 * param1: "defaultValue",
31862 * param2: "param2Default"
31865 * - ** array ** - {boolean=}: *(default: false)* If true, the param value will be
31866 * treated as an array of values. If you specified a Type, the value will be
31867 * treated as an array of the specified Type. Note: query parameter values
31868 * default to a special `"auto"` mode.
31870 * For query parameters in `"auto"` mode, if multiple values for a single parameter
31871 * are present in the URL (e.g.: `/foo?bar=1&bar=2&bar=3`) then the values
31872 * are mapped to an array (e.g.: `{ foo: [ '1', '2', '3' ] }`). However, if
31873 * only one value is present (e.g.: `/foo?bar=1`) then the value is treated as single
31874 * value (e.g.: `{ foo: '1' }`).
31877 * param1: { array: true }
31880 * - ** squash ** - {bool|string=}: `squash` configures how a default parameter value is represented in the URL when
31881 * the current parameter value is the same as the default value. If `squash` is not set, it uses the
31882 * configured default squash policy.
31883 * (See {@link ui.router.util.$urlMatcherFactory#methods_defaultSquashPolicy `defaultSquashPolicy()`})
31885 * There are three squash settings:
31887 * - false: The parameter's default value is not squashed. It is encoded and included in the URL
31888 * - true: The parameter's default value is omitted from the URL. If the parameter is preceeded and followed
31889 * by slashes in the state's `url` declaration, then one of those slashes are omitted.
31890 * This can allow for cleaner looking URLs.
31891 * - `"<arbitrary string>"`: The parameter's default value is replaced with an arbitrary placeholder of your choice.
31895 * value: "defaultId",
31898 * // squash "defaultValue" to "~"
31901 * value: "defaultValue",
31909 * // Some state name examples
31911 * // stateName can be a single top-level name (must be unique).
31912 * $stateProvider.state("home", {});
31914 * // Or it can be a nested state name. This state is a child of the
31915 * // above "home" state.
31916 * $stateProvider.state("home.newest", {});
31918 * // Nest states as deeply as needed.
31919 * $stateProvider.state("home.newest.abc.xyz.inception", {});
31921 * // state() returns $stateProvider, so you can chain state declarations.
31923 * .state("home", {})
31924 * .state("about", {})
31925 * .state("contacts", {});
31929 this.state = state;
31930 function state(name, definition) {
31931 /*jshint validthis: true */
31932 if (isObject(name)) definition = name;
31933 else definition.name = name;
31934 registerState(definition);
31940 * @name ui.router.state.$state
31942 * @requires $rootScope
31944 * @requires ui.router.state.$view
31945 * @requires $injector
31946 * @requires ui.router.util.$resolve
31947 * @requires ui.router.state.$stateParams
31948 * @requires ui.router.router.$urlRouter
31950 * @property {object} params A param object, e.g. {sectionId: section.id)}, that
31951 * you'd like to test against the current active state.
31952 * @property {object} current A reference to the state's config object. However
31953 * you passed it in. Useful for accessing custom data.
31954 * @property {object} transition Currently pending transition. A promise that'll
31955 * resolve or reject.
31958 * `$state` service is responsible for representing states as well as transitioning
31959 * between them. It also provides interfaces to ask for current state or even states
31960 * you're coming from.
31963 $get.$inject = ['$rootScope', '$q', '$view', '$injector', '$resolve', '$stateParams', '$urlRouter', '$location', '$urlMatcherFactory'];
31964 function $get( $rootScope, $q, $view, $injector, $resolve, $stateParams, $urlRouter, $location, $urlMatcherFactory) {
31966 var TransitionSuperseded = $q.reject(new Error('transition superseded'));
31967 var TransitionPrevented = $q.reject(new Error('transition prevented'));
31968 var TransitionAborted = $q.reject(new Error('transition aborted'));
31969 var TransitionFailed = $q.reject(new Error('transition failed'));
31971 // Handles the case where a state which is the target of a transition is not found, and the user
31972 // can optionally retry or defer the transition
31973 function handleRedirect(redirect, state, params, options) {
31976 * @name ui.router.state.$state#$stateNotFound
31977 * @eventOf ui.router.state.$state
31978 * @eventType broadcast on root scope
31980 * Fired when a requested state **cannot be found** using the provided state name during transition.
31981 * The event is broadcast allowing any handlers a single chance to deal with the error (usually by
31982 * lazy-loading the unfound state). A special `unfoundState` object is passed to the listener handler,
31983 * you can see its three properties in the example. You can use `event.preventDefault()` to abort the
31984 * transition and the promise returned from `go` will be rejected with a `'transition aborted'` value.
31986 * @param {Object} event Event object.
31987 * @param {Object} unfoundState Unfound State information. Contains: `to, toParams, options` properties.
31988 * @param {State} fromState Current state object.
31989 * @param {Object} fromParams Current state params.
31994 * // somewhere, assume lazy.state has not been defined
31995 * $state.go("lazy.state", {a:1, b:2}, {inherit:false});
31997 * // somewhere else
31998 * $scope.$on('$stateNotFound',
31999 * function(event, unfoundState, fromState, fromParams){
32000 * console.log(unfoundState.to); // "lazy.state"
32001 * console.log(unfoundState.toParams); // {a:1, b:2}
32002 * console.log(unfoundState.options); // {inherit:false} + default options
32006 var evt = $rootScope.$broadcast('$stateNotFound', redirect, state, params);
32008 if (evt.defaultPrevented) {
32009 $urlRouter.update();
32010 return TransitionAborted;
32017 // Allow the handler to return a promise to defer state lookup retry
32018 if (options.$retry) {
32019 $urlRouter.update();
32020 return TransitionFailed;
32022 var retryTransition = $state.transition = $q.when(evt.retry);
32024 retryTransition.then(function() {
32025 if (retryTransition !== $state.transition) return TransitionSuperseded;
32026 redirect.options.$retry = true;
32027 return $state.transitionTo(redirect.to, redirect.toParams, redirect.options);
32029 return TransitionAborted;
32031 $urlRouter.update();
32033 return retryTransition;
32036 root.locals = { resolve: null, globals: { $stateParams: {} } };
32040 current: root.self,
32047 * @name ui.router.state.$state#reload
32048 * @methodOf ui.router.state.$state
32051 * A method that force reloads the current state. All resolves are re-resolved,
32052 * controllers reinstantiated, and events re-fired.
32056 * var app angular.module('app', ['ui.router']);
32058 * app.controller('ctrl', function ($scope, $state) {
32059 * $scope.reload = function(){
32065 * `reload()` is just an alias for:
32067 * $state.transitionTo($state.current, $stateParams, {
32068 * reload: true, inherit: false, notify: true
32072 * @param {string=|object=} state - A state name or a state object, which is the root of the resolves to be re-resolved.
32075 * //assuming app application consists of 3 states: 'contacts', 'contacts.detail', 'contacts.detail.item'
32076 * //and current state is 'contacts.detail.item'
32077 * var app angular.module('app', ['ui.router']);
32079 * app.controller('ctrl', function ($scope, $state) {
32080 * $scope.reload = function(){
32081 * //will reload 'contact.detail' and 'contact.detail.item' states
32082 * $state.reload('contact.detail');
32087 * `reload()` is just an alias for:
32089 * $state.transitionTo($state.current, $stateParams, {
32090 * reload: true, inherit: false, notify: true
32094 * @returns {promise} A promise representing the state of the new transition. See
32095 * {@link ui.router.state.$state#methods_go $state.go}.
32097 $state.reload = function reload(state) {
32098 return $state.transitionTo($state.current, $stateParams, { reload: state || true, inherit: false, notify: true});
32103 * @name ui.router.state.$state#go
32104 * @methodOf ui.router.state.$state
32107 * Convenience method for transitioning to a new state. `$state.go` calls
32108 * `$state.transitionTo` internally but automatically sets options to
32109 * `{ location: true, inherit: true, relative: $state.$current, notify: true }`.
32110 * This allows you to easily use an absolute or relative to path and specify
32111 * only the parameters you'd like to update (while letting unspecified parameters
32112 * inherit from the currently active ancestor states).
32116 * var app = angular.module('app', ['ui.router']);
32118 * app.controller('ctrl', function ($scope, $state) {
32119 * $scope.changeState = function () {
32120 * $state.go('contact.detail');
32124 * <img src='../ngdoc_assets/StateGoExamples.png'/>
32126 * @param {string} to Absolute state name or relative state path. Some examples:
32128 * - `$state.go('contact.detail')` - will go to the `contact.detail` state
32129 * - `$state.go('^')` - will go to a parent state
32130 * - `$state.go('^.sibling')` - will go to a sibling state
32131 * - `$state.go('.child.grandchild')` - will go to grandchild state
32133 * @param {object=} params A map of the parameters that will be sent to the state,
32134 * will populate $stateParams. Any parameters that are not specified will be inherited from currently
32135 * defined parameters. This allows, for example, going to a sibling state that shares parameters
32136 * specified in a parent state. Parameter inheritance only works between common ancestor states, I.e.
32137 * transitioning to a sibling will get you the parameters for all parents, transitioning to a child
32138 * will get you all current parameters, etc.
32139 * @param {object=} options Options object. The options are:
32141 * - **`location`** - {boolean=true|string=} - If `true` will update the url in the location bar, if `false`
32142 * will not. If string, must be `"replace"`, which will update url and also replace last history record.
32143 * - **`inherit`** - {boolean=true}, If `true` will inherit url parameters from current url.
32144 * - **`relative`** - {object=$state.$current}, When transitioning with relative path (e.g '^'),
32145 * defines which state to be relative from.
32146 * - **`notify`** - {boolean=true}, If `true` will broadcast $stateChangeStart and $stateChangeSuccess events.
32147 * - **`reload`** (v0.2.5) - {boolean=false}, If `true` will force transition even if the state or params
32148 * have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
32149 * use this when you want to force a reload when *everything* is the same, including search params.
32151 * @returns {promise} A promise representing the state of the new transition.
32153 * Possible success values:
32157 * <br/>Possible rejection values:
32159 * - 'transition superseded' - when a newer transition has been started after this one
32160 * - 'transition prevented' - when `event.preventDefault()` has been called in a `$stateChangeStart` listener
32161 * - 'transition aborted' - when `event.preventDefault()` has been called in a `$stateNotFound` listener or
32162 * when a `$stateNotFound` `event.retry` promise errors.
32163 * - 'transition failed' - when a state has been unsuccessfully found after 2 tries.
32164 * - *resolve error* - when an error has occurred with a `resolve`
32167 $state.go = function go(to, params, options) {
32168 return $state.transitionTo(to, params, extend({ inherit: true, relative: $state.$current }, options));
32173 * @name ui.router.state.$state#transitionTo
32174 * @methodOf ui.router.state.$state
32177 * Low-level method for transitioning to a new state. {@link ui.router.state.$state#methods_go $state.go}
32178 * uses `transitionTo` internally. `$state.go` is recommended in most situations.
32182 * var app = angular.module('app', ['ui.router']);
32184 * app.controller('ctrl', function ($scope, $state) {
32185 * $scope.changeState = function () {
32186 * $state.transitionTo('contact.detail');
32191 * @param {string} to State name.
32192 * @param {object=} toParams A map of the parameters that will be sent to the state,
32193 * will populate $stateParams.
32194 * @param {object=} options Options object. The options are:
32196 * - **`location`** - {boolean=true|string=} - If `true` will update the url in the location bar, if `false`
32197 * will not. If string, must be `"replace"`, which will update url and also replace last history record.
32198 * - **`inherit`** - {boolean=false}, If `true` will inherit url parameters from current url.
32199 * - **`relative`** - {object=}, When transitioning with relative path (e.g '^'),
32200 * defines which state to be relative from.
32201 * - **`notify`** - {boolean=true}, If `true` will broadcast $stateChangeStart and $stateChangeSuccess events.
32202 * - **`reload`** (v0.2.5) - {boolean=false|string=|object=}, If `true` will force transition even if the state or params
32203 * have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
32204 * use this when you want to force a reload when *everything* is the same, including search params.
32205 * if String, then will reload the state with the name given in reload, and any children.
32206 * if Object, then a stateObj is expected, will reload the state found in stateObj, and any children.
32208 * @returns {promise} A promise representing the state of the new transition. See
32209 * {@link ui.router.state.$state#methods_go $state.go}.
32211 $state.transitionTo = function transitionTo(to, toParams, options) {
32212 toParams = toParams || {};
32214 location: true, inherit: false, relative: null, notify: true, reload: false, $retry: false
32217 var from = $state.$current, fromParams = $state.params, fromPath = from.path;
32218 var evt, toState = findState(to, options.relative);
32220 // Store the hash param for later (since it will be stripped out by various methods)
32221 var hash = toParams['#'];
32223 if (!isDefined(toState)) {
32224 var redirect = { to: to, toParams: toParams, options: options };
32225 var redirectResult = handleRedirect(redirect, from.self, fromParams, options);
32227 if (redirectResult) {
32228 return redirectResult;
32231 // Always retry once if the $stateNotFound was not prevented
32232 // (handles either redirect changed or state lazy-definition)
32234 toParams = redirect.toParams;
32235 options = redirect.options;
32236 toState = findState(to, options.relative);
32238 if (!isDefined(toState)) {
32239 if (!options.relative) throw new Error("No such state '" + to + "'");
32240 throw new Error("Could not resolve '" + to + "' from state '" + options.relative + "'");
32243 if (toState[abstractKey]) throw new Error("Cannot transition to abstract state '" + to + "'");
32244 if (options.inherit) toParams = inheritParams($stateParams, toParams || {}, $state.$current, toState);
32245 if (!toState.params.$$validates(toParams)) return TransitionFailed;
32247 toParams = toState.params.$$values(toParams);
32250 var toPath = to.path;
32252 // Starting from the root of the path, keep all levels that haven't changed
32253 var keep = 0, state = toPath[keep], locals = root.locals, toLocals = [];
32255 if (!options.reload) {
32256 while (state && state === fromPath[keep] && state.ownParams.$$equals(toParams, fromParams)) {
32257 locals = toLocals[keep] = state.locals;
32259 state = toPath[keep];
32261 } else if (isString(options.reload) || isObject(options.reload)) {
32262 if (isObject(options.reload) && !options.reload.name) {
32263 throw new Error('Invalid reload state object');
32266 var reloadState = options.reload === true ? fromPath[0] : findState(options.reload);
32267 if (options.reload && !reloadState) {
32268 throw new Error("No such reload state '" + (isString(options.reload) ? options.reload : options.reload.name) + "'");
32271 while (state && state === fromPath[keep] && state !== reloadState) {
32272 locals = toLocals[keep] = state.locals;
32274 state = toPath[keep];
32278 // If we're going to the same state and all locals are kept, we've got nothing to do.
32279 // But clear 'transition', as we still want to cancel any other pending transitions.
32280 // TODO: We may not want to bump 'transition' if we're called from a location change
32281 // that we've initiated ourselves, because we might accidentally abort a legitimate
32282 // transition initiated from code?
32283 if (shouldSkipReload(to, toParams, from, fromParams, locals, options)) {
32284 if (hash) toParams['#'] = hash;
32285 $state.params = toParams;
32286 copy($state.params, $stateParams);
32287 if (options.location && to.navigable && to.navigable.url) {
32288 $urlRouter.push(to.navigable.url, toParams, {
32289 $$avoidResync: true, replace: options.location === 'replace'
32291 $urlRouter.update(true);
32293 $state.transition = null;
32294 return $q.when($state.current);
32297 // Filter parameters before we pass them to event handlers etc.
32298 toParams = filterByKeys(to.params.$$keys(), toParams || {});
32300 // Broadcast start event and cancel the transition if requested
32301 if (options.notify) {
32304 * @name ui.router.state.$state#$stateChangeStart
32305 * @eventOf ui.router.state.$state
32306 * @eventType broadcast on root scope
32308 * Fired when the state transition **begins**. You can use `event.preventDefault()`
32309 * to prevent the transition from happening and then the transition promise will be
32310 * rejected with a `'transition prevented'` value.
32312 * @param {Object} event Event object.
32313 * @param {State} toState The state being transitioned to.
32314 * @param {Object} toParams The params supplied to the `toState`.
32315 * @param {State} fromState The current state, pre-transition.
32316 * @param {Object} fromParams The params supplied to the `fromState`.
32321 * $rootScope.$on('$stateChangeStart',
32322 * function(event, toState, toParams, fromState, fromParams){
32323 * event.preventDefault();
32324 * // transitionTo() promise will be rejected with
32325 * // a 'transition prevented' error
32329 if ($rootScope.$broadcast('$stateChangeStart', to.self, toParams, from.self, fromParams).defaultPrevented) {
32330 $rootScope.$broadcast('$stateChangeCancel', to.self, toParams, from.self, fromParams);
32331 $urlRouter.update();
32332 return TransitionPrevented;
32336 // Resolve locals for the remaining states, but don't update any global state just
32337 // yet -- if anything fails to resolve the current state needs to remain untouched.
32338 // We also set up an inheritance chain for the locals here. This allows the view directive
32339 // to quickly look up the correct definition for each view in the current state. Even
32340 // though we create the locals object itself outside resolveState(), it is initially
32341 // empty and gets filled asynchronously. We need to keep track of the promise for the
32342 // (fully resolved) current locals, and pass this down the chain.
32343 var resolved = $q.when(locals);
32345 for (var l = keep; l < toPath.length; l++, state = toPath[l]) {
32346 locals = toLocals[l] = inherit(locals);
32347 resolved = resolveState(state, toParams, state === to, resolved, locals, options);
32350 // Once everything is resolved, we are ready to perform the actual transition
32351 // and return a promise for the new state. We also keep track of what the
32352 // current promise is, so that we can detect overlapping transitions and
32353 // keep only the outcome of the last transition.
32354 var transition = $state.transition = resolved.then(function () {
32355 var l, entering, exiting;
32357 if ($state.transition !== transition) return TransitionSuperseded;
32359 // Exit 'from' states not kept
32360 for (l = fromPath.length - 1; l >= keep; l--) {
32361 exiting = fromPath[l];
32362 if (exiting.self.onExit) {
32363 $injector.invoke(exiting.self.onExit, exiting.self, exiting.locals.globals);
32365 exiting.locals = null;
32368 // Enter 'to' states not kept
32369 for (l = keep; l < toPath.length; l++) {
32370 entering = toPath[l];
32371 entering.locals = toLocals[l];
32372 if (entering.self.onEnter) {
32373 $injector.invoke(entering.self.onEnter, entering.self, entering.locals.globals);
32377 // Re-add the saved hash before we start returning things
32378 if (hash) toParams['#'] = hash;
32380 // Run it again, to catch any transitions in callbacks
32381 if ($state.transition !== transition) return TransitionSuperseded;
32383 // Update globals in $state
32384 $state.$current = to;
32385 $state.current = to.self;
32386 $state.params = toParams;
32387 copy($state.params, $stateParams);
32388 $state.transition = null;
32390 if (options.location && to.navigable) {
32391 $urlRouter.push(to.navigable.url, to.navigable.locals.globals.$stateParams, {
32392 $$avoidResync: true, replace: options.location === 'replace'
32396 if (options.notify) {
32399 * @name ui.router.state.$state#$stateChangeSuccess
32400 * @eventOf ui.router.state.$state
32401 * @eventType broadcast on root scope
32403 * Fired once the state transition is **complete**.
32405 * @param {Object} event Event object.
32406 * @param {State} toState The state being transitioned to.
32407 * @param {Object} toParams The params supplied to the `toState`.
32408 * @param {State} fromState The current state, pre-transition.
32409 * @param {Object} fromParams The params supplied to the `fromState`.
32411 $rootScope.$broadcast('$stateChangeSuccess', to.self, toParams, from.self, fromParams);
32413 $urlRouter.update(true);
32415 return $state.current;
32416 }, function (error) {
32417 if ($state.transition !== transition) return TransitionSuperseded;
32419 $state.transition = null;
32422 * @name ui.router.state.$state#$stateChangeError
32423 * @eventOf ui.router.state.$state
32424 * @eventType broadcast on root scope
32426 * Fired when an **error occurs** during transition. It's important to note that if you
32427 * have any errors in your resolve functions (javascript errors, non-existent services, etc)
32428 * they will not throw traditionally. You must listen for this $stateChangeError event to
32429 * catch **ALL** errors.
32431 * @param {Object} event Event object.
32432 * @param {State} toState The state being transitioned to.
32433 * @param {Object} toParams The params supplied to the `toState`.
32434 * @param {State} fromState The current state, pre-transition.
32435 * @param {Object} fromParams The params supplied to the `fromState`.
32436 * @param {Error} error The resolve error object.
32438 evt = $rootScope.$broadcast('$stateChangeError', to.self, toParams, from.self, fromParams, error);
32440 if (!evt.defaultPrevented) {
32441 $urlRouter.update();
32444 return $q.reject(error);
32452 * @name ui.router.state.$state#is
32453 * @methodOf ui.router.state.$state
32456 * Similar to {@link ui.router.state.$state#methods_includes $state.includes},
32457 * but only checks for the full state name. If params is supplied then it will be
32458 * tested for strict equality against the current active params object, so all params
32459 * must match with none missing and no extras.
32463 * $state.$current.name = 'contacts.details.item';
32466 * $state.is('contact.details.item'); // returns true
32467 * $state.is(contactDetailItemStateObject); // returns true
32469 * // relative name (. and ^), typically from a template
32470 * // E.g. from the 'contacts.details' template
32471 * <div ng-class="{highlighted: $state.is('.item')}">Item</div>
32474 * @param {string|object} stateOrName The state name (absolute or relative) or state object you'd like to check.
32475 * @param {object=} params A param object, e.g. `{sectionId: section.id}`, that you'd like
32476 * to test against the current active state.
32477 * @param {object=} options An options object. The options are:
32479 * - **`relative`** - {string|object} - If `stateOrName` is a relative state name and `options.relative` is set, .is will
32480 * test relative to `options.relative` state (or name).
32482 * @returns {boolean} Returns true if it is the state.
32484 $state.is = function is(stateOrName, params, options) {
32485 options = extend({ relative: $state.$current }, options || {});
32486 var state = findState(stateOrName, options.relative);
32488 if (!isDefined(state)) { return undefined; }
32489 if ($state.$current !== state) { return false; }
32490 return params ? equalForKeys(state.params.$$values(params), $stateParams) : true;
32495 * @name ui.router.state.$state#includes
32496 * @methodOf ui.router.state.$state
32499 * A method to determine if the current active state is equal to or is the child of the
32500 * state stateName. If any params are passed then they will be tested for a match as well.
32501 * Not all the parameters need to be passed, just the ones you'd like to test for equality.
32504 * Partial and relative names
32506 * $state.$current.name = 'contacts.details.item';
32508 * // Using partial names
32509 * $state.includes("contacts"); // returns true
32510 * $state.includes("contacts.details"); // returns true
32511 * $state.includes("contacts.details.item"); // returns true
32512 * $state.includes("contacts.list"); // returns false
32513 * $state.includes("about"); // returns false
32515 * // Using relative names (. and ^), typically from a template
32516 * // E.g. from the 'contacts.details' template
32517 * <div ng-class="{highlighted: $state.includes('.item')}">Item</div>
32520 * Basic globbing patterns
32522 * $state.$current.name = 'contacts.details.item.url';
32524 * $state.includes("*.details.*.*"); // returns true
32525 * $state.includes("*.details.**"); // returns true
32526 * $state.includes("**.item.**"); // returns true
32527 * $state.includes("*.details.item.url"); // returns true
32528 * $state.includes("*.details.*.url"); // returns true
32529 * $state.includes("*.details.*"); // returns false
32530 * $state.includes("item.**"); // returns false
32533 * @param {string} stateOrName A partial name, relative name, or glob pattern
32534 * to be searched for within the current state name.
32535 * @param {object=} params A param object, e.g. `{sectionId: section.id}`,
32536 * that you'd like to test against the current active state.
32537 * @param {object=} options An options object. The options are:
32539 * - **`relative`** - {string|object=} - If `stateOrName` is a relative state reference and `options.relative` is set,
32540 * .includes will test relative to `options.relative` state (or name).
32542 * @returns {boolean} Returns true if it does include the state
32544 $state.includes = function includes(stateOrName, params, options) {
32545 options = extend({ relative: $state.$current }, options || {});
32546 if (isString(stateOrName) && isGlob(stateOrName)) {
32547 if (!doesStateMatchGlob(stateOrName)) {
32550 stateOrName = $state.$current.name;
32553 var state = findState(stateOrName, options.relative);
32554 if (!isDefined(state)) { return undefined; }
32555 if (!isDefined($state.$current.includes[state.name])) { return false; }
32556 return params ? equalForKeys(state.params.$$values(params), $stateParams, objectKeys(params)) : true;
32562 * @name ui.router.state.$state#href
32563 * @methodOf ui.router.state.$state
32566 * A url generation method that returns the compiled url for the given state populated with the given params.
32570 * expect($state.href("about.person", { person: "bob" })).toEqual("/about/bob");
32573 * @param {string|object} stateOrName The state name or state object you'd like to generate a url from.
32574 * @param {object=} params An object of parameter values to fill the state's required parameters.
32575 * @param {object=} options Options object. The options are:
32577 * - **`lossy`** - {boolean=true} - If true, and if there is no url associated with the state provided in the
32578 * first parameter, then the constructed href url will be built from the first navigable ancestor (aka
32579 * ancestor with a valid url).
32580 * - **`inherit`** - {boolean=true}, If `true` will inherit url parameters from current url.
32581 * - **`relative`** - {object=$state.$current}, When transitioning with relative path (e.g '^'),
32582 * defines which state to be relative from.
32583 * - **`absolute`** - {boolean=false}, If true will generate an absolute url, e.g. "http://www.example.com/fullurl".
32585 * @returns {string} compiled state url
32587 $state.href = function href(stateOrName, params, options) {
32592 relative: $state.$current
32595 var state = findState(stateOrName, options.relative);
32597 if (!isDefined(state)) return null;
32598 if (options.inherit) params = inheritParams($stateParams, params || {}, $state.$current, state);
32600 var nav = (state && options.lossy) ? state.navigable : state;
32602 if (!nav || nav.url === undefined || nav.url === null) {
32605 return $urlRouter.href(nav.url, filterByKeys(state.params.$$keys().concat('#'), params || {}), {
32606 absolute: options.absolute
32612 * @name ui.router.state.$state#get
32613 * @methodOf ui.router.state.$state
32616 * Returns the state configuration object for any specific state or all states.
32618 * @param {string|object=} stateOrName (absolute or relative) If provided, will only get the config for
32619 * the requested state. If not provided, returns an array of ALL state configs.
32620 * @param {string|object=} context When stateOrName is a relative state reference, the state will be retrieved relative to context.
32621 * @returns {Object|Array} State configuration object or array of all objects.
32623 $state.get = function (stateOrName, context) {
32624 if (arguments.length === 0) return map(objectKeys(states), function(name) { return states[name].self; });
32625 var state = findState(stateOrName, context || $state.$current);
32626 return (state && state.self) ? state.self : null;
32629 function resolveState(state, params, paramsAreFiltered, inherited, dst, options) {
32630 // Make a restricted $stateParams with only the parameters that apply to this state if
32631 // necessary. In addition to being available to the controller and onEnter/onExit callbacks,
32632 // we also need $stateParams to be available for any $injector calls we make during the
32633 // dependency resolution process.
32634 var $stateParams = (paramsAreFiltered) ? params : filterByKeys(state.params.$$keys(), params);
32635 var locals = { $stateParams: $stateParams };
32637 // Resolve 'global' dependencies for the state, i.e. those not specific to a view.
32638 // We're also including $stateParams in this; that way the parameters are restricted
32639 // to the set that should be visible to the state, and are independent of when we update
32640 // the global $state and $stateParams values.
32641 dst.resolve = $resolve.resolve(state.resolve, locals, dst.resolve, state);
32642 var promises = [dst.resolve.then(function (globals) {
32643 dst.globals = globals;
32645 if (inherited) promises.push(inherited);
32647 function resolveViews() {
32648 var viewsPromises = [];
32650 // Resolve template and dependencies for all views.
32651 forEach(state.views, function (view, name) {
32652 var injectables = (view.resolve && view.resolve !== state.resolve ? view.resolve : {});
32653 injectables.$template = [ function () {
32654 return $view.load(name, { view: view, locals: dst.globals, params: $stateParams, notify: options.notify }) || '';
32657 viewsPromises.push($resolve.resolve(injectables, dst.globals, dst.resolve, state).then(function (result) {
32658 // References to the controller (only instantiated at link time)
32659 if (isFunction(view.controllerProvider) || isArray(view.controllerProvider)) {
32660 var injectLocals = angular.extend({}, injectables, dst.globals);
32661 result.$$controller = $injector.invoke(view.controllerProvider, null, injectLocals);
32663 result.$$controller = view.controller;
32665 // Provide access to the state itself for internal use
32666 result.$$state = state;
32667 result.$$controllerAs = view.controllerAs;
32668 dst[name] = result;
32672 return $q.all(viewsPromises).then(function(){
32673 return dst.globals;
32677 // Wait for all the promises and then return the activation object
32678 return $q.all(promises).then(resolveViews).then(function (values) {
32686 function shouldSkipReload(to, toParams, from, fromParams, locals, options) {
32687 // Return true if there are no differences in non-search (path/object) params, false if there are differences
32688 function nonSearchParamsEqual(fromAndToState, fromParams, toParams) {
32689 // Identify whether all the parameters that differ between `fromParams` and `toParams` were search params.
32690 function notSearchParam(key) {
32691 return fromAndToState.params[key].location != "search";
32693 var nonQueryParamKeys = fromAndToState.params.$$keys().filter(notSearchParam);
32694 var nonQueryParams = pick.apply({}, [fromAndToState.params].concat(nonQueryParamKeys));
32695 var nonQueryParamSet = new $$UMFP.ParamSet(nonQueryParams);
32696 return nonQueryParamSet.$$equals(fromParams, toParams);
32699 // If reload was not explicitly requested
32700 // and we're transitioning to the same state we're already in
32701 // and the locals didn't change
32702 // or they changed in a way that doesn't merit reloading
32703 // (reloadOnParams:false, or reloadOnSearch.false and only search params changed)
32704 // Then return true.
32705 if (!options.reload && to === from &&
32706 (locals === from.locals || (to.self.reloadOnSearch === false && nonSearchParamsEqual(from, fromParams, toParams)))) {
32712 angular.module('ui.router.state')
32713 .value('$stateParams', {})
32714 .provider('$state', $StateProvider);
32717 $ViewProvider.$inject = [];
32718 function $ViewProvider() {
32723 * @name ui.router.state.$view
32725 * @requires ui.router.util.$templateFactory
32726 * @requires $rootScope
32731 $get.$inject = ['$rootScope', '$templateFactory'];
32732 function $get( $rootScope, $templateFactory) {
32734 // $view.load('full.viewName', { template: ..., controller: ..., resolve: ..., async: false, params: ... })
32737 * @name ui.router.state.$view#load
32738 * @methodOf ui.router.state.$view
32742 * @param {string} name name
32743 * @param {object} options option object.
32745 load: function load(name, options) {
32746 var result, defaults = {
32747 template: null, controller: null, view: null, locals: null, notify: true, async: true, params: {}
32749 options = extend(defaults, options);
32751 if (options.view) {
32752 result = $templateFactory.fromConfig(options.view, options.params, options.locals);
32754 if (result && options.notify) {
32757 * @name ui.router.state.$state#$viewContentLoading
32758 * @eventOf ui.router.state.$view
32759 * @eventType broadcast on root scope
32762 * Fired once the view **begins loading**, *before* the DOM is rendered.
32764 * @param {Object} event Event object.
32765 * @param {Object} viewConfig The view config properties (template, controller, etc).
32770 * $scope.$on('$viewContentLoading',
32771 * function(event, viewConfig){
32772 * // Access to all the view config properties.
32773 * // and one special property 'targetView'
32774 * // viewConfig.targetView
32778 $rootScope.$broadcast('$viewContentLoading', options);
32786 angular.module('ui.router.state').provider('$view', $ViewProvider);
32790 * @name ui.router.state.$uiViewScrollProvider
32793 * Provider that returns the {@link ui.router.state.$uiViewScroll} service function.
32795 function $ViewScrollProvider() {
32797 var useAnchorScroll = false;
32801 * @name ui.router.state.$uiViewScrollProvider#useAnchorScroll
32802 * @methodOf ui.router.state.$uiViewScrollProvider
32805 * Reverts back to using the core [`$anchorScroll`](http://docs.angularjs.org/api/ng.$anchorScroll) service for
32806 * scrolling based on the url anchor.
32808 this.useAnchorScroll = function () {
32809 useAnchorScroll = true;
32814 * @name ui.router.state.$uiViewScroll
32816 * @requires $anchorScroll
32817 * @requires $timeout
32820 * When called with a jqLite element, it scrolls the element into view (after a
32821 * `$timeout` so the DOM has time to refresh).
32823 * If you prefer to rely on `$anchorScroll` to scroll the view to the anchor,
32824 * this can be enabled by calling {@link ui.router.state.$uiViewScrollProvider#methods_useAnchorScroll `$uiViewScrollProvider.useAnchorScroll()`}.
32826 this.$get = ['$anchorScroll', '$timeout', function ($anchorScroll, $timeout) {
32827 if (useAnchorScroll) {
32828 return $anchorScroll;
32831 return function ($element) {
32832 return $timeout(function () {
32833 $element[0].scrollIntoView();
32839 angular.module('ui.router.state').provider('$uiViewScroll', $ViewScrollProvider);
32843 * @name ui.router.state.directive:ui-view
32845 * @requires ui.router.state.$state
32846 * @requires $compile
32847 * @requires $controller
32848 * @requires $injector
32849 * @requires ui.router.state.$uiViewScroll
32850 * @requires $document
32855 * The ui-view directive tells $state where to place your templates.
32857 * @param {string=} name A view name. The name should be unique amongst the other views in the
32858 * same state. You can have views of the same name that live in different states.
32860 * @param {string=} autoscroll It allows you to set the scroll behavior of the browser window
32861 * when a view is populated. By default, $anchorScroll is overridden by ui-router's custom scroll
32862 * service, {@link ui.router.state.$uiViewScroll}. This custom service let's you
32863 * scroll ui-view elements into view when they are populated during a state activation.
32865 * *Note: To revert back to old [`$anchorScroll`](http://docs.angularjs.org/api/ng.$anchorScroll)
32866 * functionality, call `$uiViewScrollProvider.useAnchorScroll()`.*
32868 * @param {string=} onload Expression to evaluate whenever the view updates.
32871 * A view can be unnamed or named.
32874 * <div ui-view></div>
32877 * <div ui-view="viewName"></div>
32880 * You can only have one unnamed view within any template (or root html). If you are only using a
32881 * single view and it is unnamed then you can populate it like so:
32883 * <div ui-view></div>
32884 * $stateProvider.state("home", {
32885 * template: "<h1>HELLO!</h1>"
32889 * The above is a convenient shortcut equivalent to specifying your view explicitly with the {@link ui.router.state.$stateProvider#views `views`}
32890 * config property, by name, in this case an empty name:
32892 * $stateProvider.state("home", {
32895 * template: "<h1>HELLO!</h1>"
32901 * But typically you'll only use the views property if you name your view or have more than one view
32902 * in the same template. There's not really a compelling reason to name a view if its the only one,
32903 * but you could if you wanted, like so:
32905 * <div ui-view="main"></div>
32908 * $stateProvider.state("home", {
32911 * template: "<h1>HELLO!</h1>"
32917 * Really though, you'll use views to set up multiple views:
32919 * <div ui-view></div>
32920 * <div ui-view="chart"></div>
32921 * <div ui-view="data"></div>
32925 * $stateProvider.state("home", {
32928 * template: "<h1>HELLO!</h1>"
32931 * template: "<chart_thing/>"
32934 * template: "<data_thing/>"
32940 * Examples for `autoscroll`:
32943 * <!-- If autoscroll present with no expression,
32944 * then scroll ui-view into view -->
32945 * <ui-view autoscroll/>
32947 * <!-- If autoscroll present with valid expression,
32948 * then scroll ui-view into view if expression evaluates to true -->
32949 * <ui-view autoscroll='true'/>
32950 * <ui-view autoscroll='false'/>
32951 * <ui-view autoscroll='scopeVariable'/>
32954 $ViewDirective.$inject = ['$state', '$injector', '$uiViewScroll', '$interpolate'];
32955 function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate) {
32957 function getService() {
32958 return ($injector.has) ? function(service) {
32959 return $injector.has(service) ? $injector.get(service) : null;
32960 } : function(service) {
32962 return $injector.get(service);
32969 var service = getService(),
32970 $animator = service('$animator'),
32971 $animate = service('$animate');
32973 // Returns a set of DOM manipulation functions based on which Angular version
32975 function getRenderer(attrs, scope) {
32976 var statics = function() {
32978 enter: function (element, target, cb) { target.after(element); cb(); },
32979 leave: function (element, cb) { element.remove(); cb(); }
32985 enter: function(element, target, cb) {
32986 var promise = $animate.enter(element, null, target, cb);
32987 if (promise && promise.then) promise.then(cb);
32989 leave: function(element, cb) {
32990 var promise = $animate.leave(element, cb);
32991 if (promise && promise.then) promise.then(cb);
32997 var animate = $animator && $animator(scope, attrs);
33000 enter: function(element, target, cb) {animate.enter(element, null, target); cb(); },
33001 leave: function(element, cb) { animate.leave(element); cb(); }
33012 transclude: 'element',
33013 compile: function (tElement, tAttrs, $transclude) {
33014 return function (scope, $element, attrs) {
33015 var previousEl, currentEl, currentScope, latestLocals,
33016 onloadExp = attrs.onload || '',
33017 autoScrollExp = attrs.autoscroll,
33018 renderer = getRenderer(attrs, scope);
33020 scope.$on('$stateChangeSuccess', function() {
33023 scope.$on('$viewContentLoading', function() {
33029 function cleanupLastView() {
33031 previousEl.remove();
33035 if (currentScope) {
33036 currentScope.$destroy();
33037 currentScope = null;
33041 renderer.leave(currentEl, function() {
33045 previousEl = currentEl;
33050 function updateView(firstTime) {
33052 name = getUiViewName(scope, attrs, $element, $interpolate),
33053 previousLocals = name && $state.$current && $state.$current.locals[name];
33055 if (!firstTime && previousLocals === latestLocals) return; // nothing to do
33056 newScope = scope.$new();
33057 latestLocals = $state.$current.locals[name];
33059 var clone = $transclude(newScope, function(clone) {
33060 renderer.enter(clone, $element, function onUiViewEnter() {
33062 currentScope.$emit('$viewContentAnimationEnded');
33065 if (angular.isDefined(autoScrollExp) && !autoScrollExp || scope.$eval(autoScrollExp)) {
33066 $uiViewScroll(clone);
33073 currentScope = newScope;
33076 * @name ui.router.state.directive:ui-view#$viewContentLoaded
33077 * @eventOf ui.router.state.directive:ui-view
33078 * @eventType emits on ui-view directive scope
33080 * Fired once the view is **loaded**, *after* the DOM is rendered.
33082 * @param {Object} event Event object.
33084 currentScope.$emit('$viewContentLoaded');
33085 currentScope.$eval(onloadExp);
33094 $ViewDirectiveFill.$inject = ['$compile', '$controller', '$state', '$interpolate'];
33095 function $ViewDirectiveFill ( $compile, $controller, $state, $interpolate) {
33099 compile: function (tElement) {
33100 var initial = tElement.html();
33101 return function (scope, $element, attrs) {
33102 var current = $state.$current,
33103 name = getUiViewName(scope, attrs, $element, $interpolate),
33104 locals = current && current.locals[name];
33110 $element.data('$uiView', { name: name, state: locals.$$state });
33111 $element.html(locals.$template ? locals.$template : initial);
33113 var link = $compile($element.contents());
33115 if (locals.$$controller) {
33116 locals.$scope = scope;
33117 locals.$element = $element;
33118 var controller = $controller(locals.$$controller, locals);
33119 if (locals.$$controllerAs) {
33120 scope[locals.$$controllerAs] = controller;
33122 $element.data('$ngControllerController', controller);
33123 $element.children().data('$ngControllerController', controller);
33133 * Shared ui-view code for both directives:
33134 * Given scope, element, and its attributes, return the view's name
33136 function getUiViewName(scope, attrs, element, $interpolate) {
33137 var name = $interpolate(attrs.uiView || attrs.name || '')(scope);
33138 var inherited = element.inheritedData('$uiView');
33139 return name.indexOf('@') >= 0 ? name : (name + '@' + (inherited ? inherited.state.name : ''));
33142 angular.module('ui.router.state').directive('uiView', $ViewDirective);
33143 angular.module('ui.router.state').directive('uiView', $ViewDirectiveFill);
33145 function parseStateRef(ref, current) {
33146 var preparsed = ref.match(/^\s*({[^}]*})\s*$/), parsed;
33147 if (preparsed) ref = current + '(' + preparsed[1] + ')';
33148 parsed = ref.replace(/\n/g, " ").match(/^([^(]+?)\s*(\((.*)\))?$/);
33149 if (!parsed || parsed.length !== 4) throw new Error("Invalid state ref '" + ref + "'");
33150 return { state: parsed[1], paramExpr: parsed[3] || null };
33153 function stateContext(el) {
33154 var stateData = el.parent().inheritedData('$uiView');
33156 if (stateData && stateData.state && stateData.state.name) {
33157 return stateData.state;
33163 * @name ui.router.state.directive:ui-sref
33165 * @requires ui.router.state.$state
33166 * @requires $timeout
33171 * A directive that binds a link (`<a>` tag) to a state. If the state has an associated
33172 * URL, the directive will automatically generate & update the `href` attribute via
33173 * the {@link ui.router.state.$state#methods_href $state.href()} method. Clicking
33174 * the link will trigger a state transition with optional parameters.
33176 * Also middle-clicking, right-clicking, and ctrl-clicking on the link will be
33177 * handled natively by the browser.
33179 * You can also use relative state paths within ui-sref, just like the relative
33180 * paths passed to `$state.go()`. You just need to be aware that the path is relative
33181 * to the state that the link lives in, in other words the state that loaded the
33182 * template containing the link.
33184 * You can specify options to pass to {@link ui.router.state.$state#go $state.go()}
33185 * using the `ui-sref-opts` attribute. Options are restricted to `location`, `inherit`,
33189 * Here's an example of how you'd use ui-sref and how it would compile. If you have the
33190 * following template:
33192 * <a ui-sref="home">Home</a> | <a ui-sref="about">About</a> | <a ui-sref="{page: 2}">Next page</a>
33195 * <li ng-repeat="contact in contacts">
33196 * <a ui-sref="contacts.detail({ id: contact.id })">{{ contact.name }}</a>
33201 * Then the compiled html would be (assuming Html5Mode is off and current state is contacts):
33203 * <a href="#/home" ui-sref="home">Home</a> | <a href="#/about" ui-sref="about">About</a> | <a href="#/contacts?page=2" ui-sref="{page: 2}">Next page</a>
33206 * <li ng-repeat="contact in contacts">
33207 * <a href="#/contacts/1" ui-sref="contacts.detail({ id: contact.id })">Joe</a>
33209 * <li ng-repeat="contact in contacts">
33210 * <a href="#/contacts/2" ui-sref="contacts.detail({ id: contact.id })">Alice</a>
33212 * <li ng-repeat="contact in contacts">
33213 * <a href="#/contacts/3" ui-sref="contacts.detail({ id: contact.id })">Bob</a>
33217 * <a ui-sref="home" ui-sref-opts="{reload: true}">Home</a>
33220 * @param {string} ui-sref 'stateName' can be any valid absolute or relative state
33221 * @param {Object} ui-sref-opts options to pass to {@link ui.router.state.$state#go $state.go()}
33223 $StateRefDirective.$inject = ['$state', '$timeout'];
33224 function $StateRefDirective($state, $timeout) {
33225 var allowedOptions = ['location', 'inherit', 'reload', 'absolute'];
33229 require: ['?^uiSrefActive', '?^uiSrefActiveEq'],
33230 link: function(scope, element, attrs, uiSrefActive) {
33231 var ref = parseStateRef(attrs.uiSref, $state.current.name);
33232 var params = null, url = null, base = stateContext(element) || $state.$current;
33233 // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute.
33234 var hrefKind = Object.prototype.toString.call(element.prop('href')) === '[object SVGAnimatedString]' ?
33235 'xlink:href' : 'href';
33236 var newHref = null, isAnchor = element.prop("tagName").toUpperCase() === "A";
33237 var isForm = element[0].nodeName === "FORM";
33238 var attr = isForm ? "action" : hrefKind, nav = true;
33240 var options = { relative: base, inherit: true };
33241 var optionsOverride = scope.$eval(attrs.uiSrefOpts) || {};
33243 angular.forEach(allowedOptions, function(option) {
33244 if (option in optionsOverride) {
33245 options[option] = optionsOverride[option];
33249 var update = function(newVal) {
33250 if (newVal) params = angular.copy(newVal);
33253 newHref = $state.href(ref.state, params, options);
33255 var activeDirective = uiSrefActive[1] || uiSrefActive[0];
33256 if (activeDirective) {
33257 activeDirective.$$addStateInfo(ref.state, params);
33259 if (newHref === null) {
33263 attrs.$set(attr, newHref);
33266 if (ref.paramExpr) {
33267 scope.$watch(ref.paramExpr, function(newVal, oldVal) {
33268 if (newVal !== params) update(newVal);
33270 params = angular.copy(scope.$eval(ref.paramExpr));
33274 if (isForm) return;
33276 element.bind("click", function(e) {
33277 var button = e.which || e.button;
33278 if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
33279 // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
33280 var transition = $timeout(function() {
33281 $state.go(ref.state, params, options);
33283 e.preventDefault();
33285 // if the state has no URL, ignore one preventDefault from the <a> directive.
33286 var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
33287 e.preventDefault = function() {
33288 if (ignorePreventDefaultCount-- <= 0)
33289 $timeout.cancel(transition);
33299 * @name ui.router.state.directive:ui-sref-active
33301 * @requires ui.router.state.$state
33302 * @requires ui.router.state.$stateParams
33303 * @requires $interpolate
33308 * A directive working alongside ui-sref to add classes to an element when the
33309 * related ui-sref directive's state is active, and removing them when it is inactive.
33310 * The primary use-case is to simplify the special appearance of navigation menus
33311 * relying on `ui-sref`, by having the "active" state's menu button appear different,
33312 * distinguishing it from the inactive menu items.
33314 * ui-sref-active can live on the same element as ui-sref or on a parent element. The first
33315 * ui-sref-active found at the same level or above the ui-sref will be used.
33317 * Will activate when the ui-sref's target state or any child state is active. If you
33318 * need to activate only when the ui-sref target state is active and *not* any of
33319 * it's children, then you will use
33320 * {@link ui.router.state.directive:ui-sref-active-eq ui-sref-active-eq}
33323 * Given the following template:
33326 * <li ui-sref-active="active" class="item">
33327 * <a href ui-sref="app.user({user: 'bilbobaggins'})">@bilbobaggins</a>
33333 * When the app state is "app.user" (or any children states), and contains the state parameter "user" with value "bilbobaggins",
33334 * the resulting HTML will appear as (note the 'active' class):
33337 * <li ui-sref-active="active" class="item active">
33338 * <a ui-sref="app.user({user: 'bilbobaggins'})" href="/users/bilbobaggins">@bilbobaggins</a>
33343 * The class name is interpolated **once** during the directives link time (any further changes to the
33344 * interpolated value are ignored).
33346 * Multiple classes may be specified in a space-separated format:
33349 * <li ui-sref-active='class1 class2 class3'>
33350 * <a ui-sref="app.user">link</a>
33358 * @name ui.router.state.directive:ui-sref-active-eq
33360 * @requires ui.router.state.$state
33361 * @requires ui.router.state.$stateParams
33362 * @requires $interpolate
33367 * The same as {@link ui.router.state.directive:ui-sref-active ui-sref-active} but will only activate
33368 * when the exact target state used in the `ui-sref` is active; no child states.
33371 $StateRefActiveDirective.$inject = ['$state', '$stateParams', '$interpolate'];
33372 function $StateRefActiveDirective($state, $stateParams, $interpolate) {
33375 controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
33376 var states = [], activeClass;
33378 // There probably isn't much point in $observing this
33379 // uiSrefActive and uiSrefActiveEq share the same directive object with some
33380 // slight difference in logic routing
33381 activeClass = $interpolate($attrs.uiSrefActiveEq || $attrs.uiSrefActive || '', false)($scope);
33383 // Allow uiSref to communicate with uiSrefActive[Equals]
33384 this.$$addStateInfo = function (newState, newParams) {
33385 var state = $state.get(newState, stateContext($element));
33388 state: state || { name: newState },
33395 $scope.$on('$stateChangeSuccess', update);
33397 // Update route state
33398 function update() {
33400 $element.addClass(activeClass);
33402 $element.removeClass(activeClass);
33406 function anyMatch() {
33407 for (var i = 0; i < states.length; i++) {
33408 if (isMatch(states[i].state, states[i].params)) {
33415 function isMatch(state, params) {
33416 if (typeof $attrs.uiSrefActiveEq !== 'undefined') {
33417 return $state.is(state.name, params);
33419 return $state.includes(state.name, params);
33426 angular.module('ui.router.state')
33427 .directive('uiSref', $StateRefDirective)
33428 .directive('uiSrefActive', $StateRefActiveDirective)
33429 .directive('uiSrefActiveEq', $StateRefActiveDirective);
33433 * @name ui.router.state.filter:isState
33435 * @requires ui.router.state.$state
33438 * Translates to {@link ui.router.state.$state#methods_is $state.is("stateName")}.
33440 $IsStateFilter.$inject = ['$state'];
33441 function $IsStateFilter($state) {
33442 var isFilter = function (state) {
33443 return $state.is(state);
33445 isFilter.$stateful = true;
33451 * @name ui.router.state.filter:includedByState
33453 * @requires ui.router.state.$state
33456 * Translates to {@link ui.router.state.$state#methods_includes $state.includes('fullOrPartialStateName')}.
33458 $IncludedByStateFilter.$inject = ['$state'];
33459 function $IncludedByStateFilter($state) {
33460 var includesFilter = function (state) {
33461 return $state.includes(state);
33463 includesFilter.$stateful = true;
33464 return includesFilter;
33467 angular.module('ui.router.state')
33468 .filter('isState', $IsStateFilter)
33469 .filter('includedByState', $IncludedByStateFilter);
33470 })(window, window.angular);
33474 /***/ function(module, exports, __webpack_require__) {
33476 __webpack_require__(5);
33477 module.exports = 'ngResource';
33482 /***/ function(module, exports) {
33485 * @license AngularJS v1.4.8
33486 * (c) 2010-2015 Google, Inc. http://angularjs.org
33489 (function(window, angular, undefined) {'use strict';
33491 var $resourceMinErr = angular.$$minErr('$resource');
33493 // Helper functions and regex to lookup a dotted path on an object
33494 // stopping at undefined/null. The path must be composed of ASCII
33495 // identifiers (just like $parse)
33496 var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/;
33498 function isValidDottedPath(path) {
33499 return (path != null && path !== '' && path !== 'hasOwnProperty' &&
33500 MEMBER_NAME_REGEX.test('.' + path));
33503 function lookupDottedPath(obj, path) {
33504 if (!isValidDottedPath(path)) {
33505 throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path);
33507 var keys = path.split('.');
33508 for (var i = 0, ii = keys.length; i < ii && angular.isDefined(obj); i++) {
33510 obj = (obj !== null) ? obj[key] : undefined;
33516 * Create a shallow copy of an object and clear other fields from the destination
33518 function shallowClearAndCopy(src, dst) {
33521 angular.forEach(dst, function(value, key) {
33525 for (var key in src) {
33526 if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
33527 dst[key] = src[key];
33541 * The `ngResource` module provides interaction support with RESTful services
33542 * via the $resource service.
33545 * <div doc-module-components="ngResource"></div>
33547 * See {@link ngResource.$resource `$resource`} for usage.
33556 * A factory which creates a resource object that lets you interact with
33557 * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
33559 * The returned resource object has action methods which provide high-level behaviors without
33560 * the need to interact with the low level {@link ng.$http $http} service.
33562 * Requires the {@link ngResource `ngResource`} module to be installed.
33564 * By default, trailing slashes will be stripped from the calculated URLs,
33565 * which can pose problems with server backends that do not expect that
33566 * behavior. This can be disabled by configuring the `$resourceProvider` like
33570 app.config(['$resourceProvider', function($resourceProvider) {
33571 // Don't strip trailing slashes from calculated URLs
33572 $resourceProvider.defaults.stripTrailingSlashes = false;
33576 * @param {string} url A parameterized URL template with parameters prefixed by `:` as in
33577 * `/user/:username`. If you are using a URL with a port number (e.g.
33578 * `http://example.com:8080/api`), it will be respected.
33580 * If you are using a url with a suffix, just add the suffix, like this:
33581 * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
33582 * or even `$resource('http://example.com/resource/:resource_id.:format')`
33583 * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
33584 * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
33585 * can escape it with `/\.`.
33587 * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
33588 * `actions` methods. If any of the parameter value is a function, it will be executed every time
33589 * when a param value needs to be obtained for a request (unless the param was overridden).
33591 * Each key value in the parameter object is first bound to url template if present and then any
33592 * excess keys are appended to the url search query after the `?`.
33594 * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
33595 * URL `/path/greet?salutation=Hello`.
33597 * If the parameter value is prefixed with `@` then the value for that parameter will be extracted
33598 * from the corresponding property on the `data` object (provided when calling an action method). For
33599 * example, if the `defaultParam` object is `{someParam: '@someProp'}` then the value of `someParam`
33600 * will be `data.someProp`.
33602 * @param {Object.<Object>=} actions Hash with declaration of custom actions that should extend
33603 * the default set of resource actions. The declaration should be created in the format of {@link
33604 * ng.$http#usage $http.config}:
33606 * {action1: {method:?, params:?, isArray:?, headers:?, ...},
33607 * action2: {method:?, params:?, isArray:?, headers:?, ...},
33612 * - **`action`** – {string} – The name of action. This name becomes the name of the method on
33613 * your resource object.
33614 * - **`method`** – {string} – Case insensitive HTTP method (e.g. `GET`, `POST`, `PUT`,
33615 * `DELETE`, `JSONP`, etc).
33616 * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
33617 * the parameter value is a function, it will be executed every time when a param value needs to
33618 * be obtained for a request (unless the param was overridden).
33619 * - **`url`** – {string} – action specific `url` override. The url templating is supported just
33620 * like for the resource-level urls.
33621 * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
33622 * see `returns` section.
33623 * - **`transformRequest`** –
33624 * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
33625 * transform function or an array of such functions. The transform function takes the http
33626 * request body and headers and returns its transformed (typically serialized) version.
33627 * By default, transformRequest will contain one function that checks if the request data is
33628 * an object and serializes to using `angular.toJson`. To prevent this behavior, set
33629 * `transformRequest` to an empty array: `transformRequest: []`
33630 * - **`transformResponse`** –
33631 * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
33632 * transform function or an array of such functions. The transform function takes the http
33633 * response body and headers and returns its transformed (typically deserialized) version.
33634 * By default, transformResponse will contain one function that checks if the response looks like
33635 * a JSON string and deserializes it using `angular.fromJson`. To prevent this behavior, set
33636 * `transformResponse` to an empty array: `transformResponse: []`
33637 * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
33638 * GET request, otherwise if a cache instance built with
33639 * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
33641 * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
33642 * should abort the request when resolved.
33643 * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the
33645 * [requests with credentials](https://developer.mozilla.org/en/http_access_control#section_5)
33646 * for more information.
33647 * - **`responseType`** - `{string}` - see
33648 * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
33649 * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
33650 * `response` and `responseError`. Both `response` and `responseError` interceptors get called
33651 * with `http response` object. See {@link ng.$http $http interceptors}.
33653 * @param {Object} options Hash with custom settings that should extend the
33654 * default `$resourceProvider` behavior. The only supported option is
33658 * - **`stripTrailingSlashes`** – {boolean} – If true then the trailing
33659 * slashes from any calculated URL will be stripped. (Defaults to true.)
33661 * @returns {Object} A resource "class" object with methods for the default set of resource actions
33662 * optionally extended with custom `actions`. The default set contains these actions:
33664 * { 'get': {method:'GET'},
33665 * 'save': {method:'POST'},
33666 * 'query': {method:'GET', isArray:true},
33667 * 'remove': {method:'DELETE'},
33668 * 'delete': {method:'DELETE'} };
33671 * Calling these methods invoke an {@link ng.$http} with the specified http method,
33672 * destination and parameters. When the data is returned from the server then the object is an
33673 * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
33674 * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
33675 * read, update, delete) on server-side data like this:
33677 * var User = $resource('/user/:userId', {userId:'@id'});
33678 * var user = User.get({userId:123}, function() {
33684 * It is important to realize that invoking a $resource object method immediately returns an
33685 * empty reference (object or array depending on `isArray`). Once the data is returned from the
33686 * server the existing reference is populated with the actual data. This is a useful trick since
33687 * usually the resource is assigned to a model which is then rendered by the view. Having an empty
33688 * object results in no rendering, once the data arrives from the server then the object is
33689 * populated with the data and the view automatically re-renders itself showing the new data. This
33690 * means that in most cases one never has to write a callback function for the action methods.
33692 * The action methods on the class object or instance object can be invoked with the following
33695 * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
33696 * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
33697 * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
33700 * Success callback is called with (value, responseHeaders) arguments, where the value is
33701 * the populated resource instance or collection object. The error callback is called
33702 * with (httpResponse) argument.
33704 * Class actions return empty instance (with additional properties below).
33705 * Instance actions return promise of the action.
33707 * The Resource instances and collection have these additional properties:
33709 * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
33710 * instance or collection.
33712 * On success, the promise is resolved with the same resource instance or collection object,
33713 * updated with data from server. This makes it easy to use in
33714 * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
33715 * rendering until the resource(s) are loaded.
33717 * On failure, the promise is resolved with the {@link ng.$http http response} object, without
33718 * the `resource` property.
33720 * If an interceptor object was provided, the promise will instead be resolved with the value
33721 * returned by the interceptor.
33723 * - `$resolved`: `true` after first server interaction is completed (either with success or
33724 * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
33729 * # Credit card resource
33732 // Define CreditCard class
33733 var CreditCard = $resource('/user/:userId/card/:cardId',
33734 {userId:123, cardId:'@id'}, {
33735 charge: {method:'POST', params:{charge:true}}
33738 // We can retrieve a collection from the server
33739 var cards = CreditCard.query(function() {
33740 // GET: /user/123/card
33741 // server returns: [ {id:456, number:'1234', name:'Smith'} ];
33743 var card = cards[0];
33744 // each item is an instance of CreditCard
33745 expect(card instanceof CreditCard).toEqual(true);
33746 card.name = "J. Smith";
33747 // non GET methods are mapped onto the instances
33749 // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
33750 // server returns: {id:456, number:'1234', name: 'J. Smith'};
33752 // our custom method is mapped as well.
33753 card.$charge({amount:9.99});
33754 // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
33757 // we can create an instance as well
33758 var newCard = new CreditCard({number:'0123'});
33759 newCard.name = "Mike Smith";
33761 // POST: /user/123/card {number:'0123', name:'Mike Smith'}
33762 // server returns: {id:789, number:'0123', name: 'Mike Smith'};
33763 expect(newCard.id).toEqual(789);
33766 * The object returned from this function execution is a resource "class" which has "static" method
33767 * for each action in the definition.
33769 * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
33771 * When the data is returned from the server then the object is an instance of the resource type and
33772 * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
33773 * operations (create, read, update, delete) on server-side data.
33776 var User = $resource('/user/:userId', {userId:'@id'});
33777 User.get({userId:123}, function(user) {
33783 * It's worth noting that the success callback for `get`, `query` and other methods gets passed
33784 * in the response that came from the server as well as $http header getter function, so one
33785 * could rewrite the above example and get access to http headers as:
33788 var User = $resource('/user/:userId', {userId:'@id'});
33789 User.get({userId:123}, function(u, getResponseHeaders){
33791 u.$save(function(u, putResponseHeaders) {
33792 //u => saved user object
33793 //putResponseHeaders => $http header getter
33798 * You can also access the raw `$http` promise via the `$promise` property on the object returned
33801 var User = $resource('/user/:userId', {userId:'@id'});
33802 User.get({userId:123})
33803 .$promise.then(function(user) {
33804 $scope.user = user;
33808 * # Creating a custom 'PUT' request
33809 * In this example we create a custom method on our resource to make a PUT request
33811 * var app = angular.module('app', ['ngResource', 'ngRoute']);
33813 * // Some APIs expect a PUT request in the format URL/object/ID
33814 * // Here we are creating an 'update' method
33815 * app.factory('Notes', ['$resource', function($resource) {
33816 * return $resource('/notes/:id', null,
33818 * 'update': { method:'PUT' }
33822 * // In our controller we get the ID from the URL using ngRoute and $routeParams
33823 * // We pass in $routeParams and our Notes factory along with $scope
33824 * app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes',
33825 function($scope, $routeParams, Notes) {
33826 * // First get a note object from the factory
33827 * var note = Notes.get({ id:$routeParams.id });
33830 * // Now call update passing in the ID first then the object you are updating
33831 * Notes.update({ id:$id }, note);
33833 * // This will PUT /notes/ID with the note object in the request payload
33837 angular.module('ngResource', ['ng']).
33838 provider('$resource', function() {
33839 var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^\/]*/;
33840 var provider = this;
33843 // Strip slashes by default
33844 stripTrailingSlashes: true,
33846 // Default actions configuration
33848 'get': {method: 'GET'},
33849 'save': {method: 'POST'},
33850 'query': {method: 'GET', isArray: true},
33851 'remove': {method: 'DELETE'},
33852 'delete': {method: 'DELETE'}
33856 this.$get = ['$http', '$q', function($http, $q) {
33858 var noop = angular.noop,
33859 forEach = angular.forEach,
33860 extend = angular.extend,
33861 copy = angular.copy,
33862 isFunction = angular.isFunction;
33865 * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
33866 * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set
33867 * (pchar) allowed in path segments:
33869 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
33870 * pct-encoded = "%" HEXDIG HEXDIG
33871 * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
33872 * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
33873 * / "*" / "+" / "," / ";" / "="
33875 function encodeUriSegment(val) {
33876 return encodeUriQuery(val, true).
33877 replace(/%26/gi, '&').
33878 replace(/%3D/gi, '=').
33879 replace(/%2B/gi, '+');
33884 * This method is intended for encoding *key* or *value* parts of query component. We need a
33885 * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
33886 * have to be encoded per http://tools.ietf.org/html/rfc3986:
33887 * query = *( pchar / "/" / "?" )
33888 * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
33889 * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
33890 * pct-encoded = "%" HEXDIG HEXDIG
33891 * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
33892 * / "*" / "+" / "," / ";" / "="
33894 function encodeUriQuery(val, pctEncodeSpaces) {
33895 return encodeURIComponent(val).
33896 replace(/%40/gi, '@').
33897 replace(/%3A/gi, ':').
33898 replace(/%24/g, '$').
33899 replace(/%2C/gi, ',').
33900 replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
33903 function Route(template, defaults) {
33904 this.template = template;
33905 this.defaults = extend({}, provider.defaults, defaults);
33906 this.urlParams = {};
33909 Route.prototype = {
33910 setUrlParams: function(config, params, actionUrl) {
33912 url = actionUrl || self.template,
33915 protocolAndDomain = '';
33917 var urlParams = self.urlParams = {};
33918 forEach(url.split(/\W/), function(param) {
33919 if (param === 'hasOwnProperty') {
33920 throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
33922 if (!(new RegExp("^\\d+$").test(param)) && param &&
33923 (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
33924 urlParams[param] = true;
33927 url = url.replace(/\\:/g, ':');
33928 url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) {
33929 protocolAndDomain = match;
33933 params = params || {};
33934 forEach(self.urlParams, function(_, urlParam) {
33935 val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
33936 if (angular.isDefined(val) && val !== null) {
33937 encodedVal = encodeUriSegment(val);
33938 url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
33939 return encodedVal + p1;
33942 url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
33943 leadingSlashes, tail) {
33944 if (tail.charAt(0) == '/') {
33947 return leadingSlashes + tail;
33953 // strip trailing slashes and set the url (unless this behavior is specifically disabled)
33954 if (self.defaults.stripTrailingSlashes) {
33955 url = url.replace(/\/+$/, '') || '/';
33958 // then replace collapse `/.` if found in the last URL path segment before the query
33959 // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
33960 url = url.replace(/\/\.(?=\w+($|\?))/, '.');
33961 // replace escaped `/\.` with `/.`
33962 config.url = protocolAndDomain + url.replace(/\/\\\./, '/.');
33965 // set params - delegate param encoding to $http
33966 forEach(params, function(value, key) {
33967 if (!self.urlParams[key]) {
33968 config.params = config.params || {};
33969 config.params[key] = value;
33976 function resourceFactory(url, paramDefaults, actions, options) {
33977 var route = new Route(url, options);
33979 actions = extend({}, provider.defaults.actions, actions);
33981 function extractParams(data, actionParams) {
33983 actionParams = extend({}, paramDefaults, actionParams);
33984 forEach(actionParams, function(value, key) {
33985 if (isFunction(value)) { value = value(); }
33986 ids[key] = value && value.charAt && value.charAt(0) == '@' ?
33987 lookupDottedPath(data, value.substr(1)) : value;
33992 function defaultResponseInterceptor(response) {
33993 return response.resource;
33996 function Resource(value) {
33997 shallowClearAndCopy(value || {}, this);
34000 Resource.prototype.toJSON = function() {
34001 var data = extend({}, this);
34002 delete data.$promise;
34003 delete data.$resolved;
34007 forEach(actions, function(action, name) {
34008 var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
34010 Resource[name] = function(a1, a2, a3, a4) {
34011 var params = {}, data, success, error;
34013 /* jshint -W086 */ /* (purposefully fall through case statements) */
34014 switch (arguments.length) {
34021 if (isFunction(a2)) {
34022 if (isFunction(a1)) {
34038 if (isFunction(a1)) success = a1;
34039 else if (hasBody) data = a1;
34044 throw $resourceMinErr('badargs',
34045 "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
34048 /* jshint +W086 */ /* (purposefully fall through case statements) */
34050 var isInstanceCall = this instanceof Resource;
34051 var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
34052 var httpConfig = {};
34053 var responseInterceptor = action.interceptor && action.interceptor.response ||
34054 defaultResponseInterceptor;
34055 var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
34058 forEach(action, function(value, key) {
34061 httpConfig[key] = copy(value);
34065 case 'interceptor':
34068 httpConfig[key] = value;
34073 if (hasBody) httpConfig.data = data;
34074 route.setUrlParams(httpConfig,
34075 extend({}, extractParams(data, action.params || {}), params),
34078 var promise = $http(httpConfig).then(function(response) {
34079 var data = response.data,
34080 promise = value.$promise;
34083 // Need to convert action.isArray to boolean in case it is undefined
34085 if (angular.isArray(data) !== (!!action.isArray)) {
34086 throw $resourceMinErr('badcfg',
34087 'Error in resource configuration for action `{0}`. Expected response to ' +
34088 'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object',
34089 angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url);
34092 if (action.isArray) {
34094 forEach(data, function(item) {
34095 if (typeof item === "object") {
34096 value.push(new Resource(item));
34098 // Valid JSON values may be string literals, and these should not be converted
34099 // into objects. These items will not have access to the Resource prototype
34100 // methods, but unfortunately there
34105 shallowClearAndCopy(data, value);
34106 value.$promise = promise;
34110 value.$resolved = true;
34112 response.resource = value;
34115 }, function(response) {
34116 value.$resolved = true;
34118 (error || noop)(response);
34120 return $q.reject(response);
34123 promise = promise.then(
34124 function(response) {
34125 var value = responseInterceptor(response);
34126 (success || noop)(value, response.headers);
34129 responseErrorInterceptor);
34131 if (!isInstanceCall) {
34132 // we are creating instance / collection
34133 // - set the initial promise
34134 // - return the instance / collection
34135 value.$promise = promise;
34136 value.$resolved = false;
34146 Resource.prototype['$' + name] = function(params, success, error) {
34147 if (isFunction(params)) {
34148 error = success; success = params; params = {};
34150 var result = Resource[name].call(this, params, this, success, error);
34151 return result.$promise || result;
34155 Resource.bind = function(additionalParamDefaults) {
34156 return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
34162 return resourceFactory;
34167 })(window, window.angular);
34172 /***/ function(module, exports, __webpack_require__) {
34174 __webpack_require__(7);
34176 module.exports = 'ui.bootstrap';
34181 /***/ function(module, exports) {
34184 * angular-ui-bootstrap
34185 * http://angular-ui.github.io/bootstrap/
34187 * Version: 1.0.0 - 2016-01-08
34190 angular.module("ui.bootstrap", ["ui.bootstrap.tpls", "ui.bootstrap.collapse","ui.bootstrap.accordion","ui.bootstrap.alert","ui.bootstrap.buttons","ui.bootstrap.carousel","ui.bootstrap.dateparser","ui.bootstrap.isClass","ui.bootstrap.position","ui.bootstrap.datepicker","ui.bootstrap.debounce","ui.bootstrap.dropdown","ui.bootstrap.stackedMap","ui.bootstrap.modal","ui.bootstrap.paging","ui.bootstrap.pager","ui.bootstrap.pagination","ui.bootstrap.tooltip","ui.bootstrap.popover","ui.bootstrap.progressbar","ui.bootstrap.rating","ui.bootstrap.tabs","ui.bootstrap.timepicker","ui.bootstrap.typeahead"]);
34191 angular.module("ui.bootstrap.tpls", ["uib/template/accordion/accordion-group.html","uib/template/accordion/accordion.html","uib/template/alert/alert.html","uib/template/carousel/carousel.html","uib/template/carousel/slide.html","uib/template/datepicker/datepicker.html","uib/template/datepicker/day.html","uib/template/datepicker/month.html","uib/template/datepicker/popup.html","uib/template/datepicker/year.html","uib/template/modal/backdrop.html","uib/template/modal/window.html","uib/template/pager/pager.html","uib/template/pagination/pagination.html","uib/template/tooltip/tooltip-html-popup.html","uib/template/tooltip/tooltip-popup.html","uib/template/tooltip/tooltip-template-popup.html","uib/template/popover/popover-html.html","uib/template/popover/popover-template.html","uib/template/popover/popover.html","uib/template/progressbar/bar.html","uib/template/progressbar/progress.html","uib/template/progressbar/progressbar.html","uib/template/rating/rating.html","uib/template/tabs/tab.html","uib/template/tabs/tabset.html","uib/template/timepicker/timepicker.html","uib/template/typeahead/typeahead-match.html","uib/template/typeahead/typeahead-popup.html"]);
34192 angular.module('ui.bootstrap.collapse', [])
34194 .directive('uibCollapse', ['$animate', '$injector', function($animate, $injector) {
34195 var $animateCss = $injector.has('$animateCss') ? $injector.get('$animateCss') : null;
34197 link: function(scope, element, attrs) {
34198 if (!scope.$eval(attrs.uibCollapse)) {
34199 element.addClass('in')
34200 .addClass('collapse')
34201 .css({height: 'auto'});
34204 function expand() {
34205 element.removeClass('collapse')
34206 .addClass('collapsing')
34207 .attr('aria-expanded', true)
34208 .attr('aria-hidden', false);
34211 $animateCss(element, {
34214 to: { height: element[0].scrollHeight + 'px' }
34215 }).start()['finally'](expandDone);
34217 $animate.addClass(element, 'in', {
34218 to: { height: element[0].scrollHeight + 'px' }
34219 }).then(expandDone);
34223 function expandDone() {
34224 element.removeClass('collapsing')
34225 .addClass('collapse')
34226 .css({height: 'auto'});
34229 function collapse() {
34230 if (!element.hasClass('collapse') && !element.hasClass('in')) {
34231 return collapseDone();
34235 // IMPORTANT: The height must be set before adding "collapsing" class.
34236 // Otherwise, the browser attempts to animate from height 0 (in
34237 // collapsing class) to the given height here.
34238 .css({height: element[0].scrollHeight + 'px'})
34239 // initially all panel collapse have the collapse class, this removal
34240 // prevents the animation from jumping to collapsed state
34241 .removeClass('collapse')
34242 .addClass('collapsing')
34243 .attr('aria-expanded', false)
34244 .attr('aria-hidden', true);
34247 $animateCss(element, {
34250 }).start()['finally'](collapseDone);
34252 $animate.removeClass(element, 'in', {
34254 }).then(collapseDone);
34258 function collapseDone() {
34259 element.css({height: '0'}); // Required so that collapse works when animation is disabled
34260 element.removeClass('collapsing')
34261 .addClass('collapse');
34264 scope.$watch(attrs.uibCollapse, function(shouldCollapse) {
34265 if (shouldCollapse) {
34275 angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
34277 .constant('uibAccordionConfig', {
34281 .controller('UibAccordionController', ['$scope', '$attrs', 'uibAccordionConfig', function($scope, $attrs, accordionConfig) {
34282 // This array keeps track of the accordion groups
34285 // Ensure that all the groups in this accordion are closed, unless close-others explicitly says not to
34286 this.closeOthers = function(openGroup) {
34287 var closeOthers = angular.isDefined($attrs.closeOthers) ?
34288 $scope.$eval($attrs.closeOthers) : accordionConfig.closeOthers;
34290 angular.forEach(this.groups, function(group) {
34291 if (group !== openGroup) {
34292 group.isOpen = false;
34298 // This is called from the accordion-group directive to add itself to the accordion
34299 this.addGroup = function(groupScope) {
34301 this.groups.push(groupScope);
34303 groupScope.$on('$destroy', function(event) {
34304 that.removeGroup(groupScope);
34308 // This is called from the accordion-group directive when to remove itself
34309 this.removeGroup = function(group) {
34310 var index = this.groups.indexOf(group);
34311 if (index !== -1) {
34312 this.groups.splice(index, 1);
34317 // The accordion directive simply sets up the directive controller
34318 // and adds an accordion CSS class to itself element.
34319 .directive('uibAccordion', function() {
34321 controller: 'UibAccordionController',
34322 controllerAs: 'accordion',
34324 templateUrl: function(element, attrs) {
34325 return attrs.templateUrl || 'uib/template/accordion/accordion.html';
34330 // The accordion-group directive indicates a block of html that will expand and collapse in an accordion
34331 .directive('uibAccordionGroup', function() {
34333 require: '^uibAccordion', // We need this directive to be inside an accordion
34334 transclude: true, // It transcludes the contents of the directive into the template
34335 replace: true, // The element containing the directive will be replaced with the template
34336 templateUrl: function(element, attrs) {
34337 return attrs.templateUrl || 'uib/template/accordion/accordion-group.html';
34340 heading: '@', // Interpolate the heading attribute onto this scope
34344 controller: function() {
34345 this.setHeading = function(element) {
34346 this.heading = element;
34349 link: function(scope, element, attrs, accordionCtrl) {
34350 accordionCtrl.addGroup(scope);
34352 scope.openClass = attrs.openClass || 'panel-open';
34353 scope.panelClass = attrs.panelClass || 'panel-default';
34354 scope.$watch('isOpen', function(value) {
34355 element.toggleClass(scope.openClass, !!value);
34357 accordionCtrl.closeOthers(scope);
34361 scope.toggleOpen = function($event) {
34362 if (!scope.isDisabled) {
34363 if (!$event || $event.which === 32) {
34364 scope.isOpen = !scope.isOpen;
34372 // Use accordion-heading below an accordion-group to provide a heading containing HTML
34373 .directive('uibAccordionHeading', function() {
34375 transclude: true, // Grab the contents to be used as the heading
34376 template: '', // In effect remove this element!
34378 require: '^uibAccordionGroup',
34379 link: function(scope, element, attrs, accordionGroupCtrl, transclude) {
34380 // Pass the heading to the accordion-group controller
34381 // so that it can be transcluded into the right place in the template
34382 // [The second parameter to transclude causes the elements to be cloned so that they work in ng-repeat]
34383 accordionGroupCtrl.setHeading(transclude(scope, angular.noop));
34388 // Use in the accordion-group template to indicate where you want the heading to be transcluded
34389 // You must provide the property on the accordion-group controller that will hold the transcluded element
34390 .directive('uibAccordionTransclude', function() {
34392 require: '^uibAccordionGroup',
34393 link: function(scope, element, attrs, controller) {
34394 scope.$watch(function() { return controller[attrs.uibAccordionTransclude]; }, function(heading) {
34396 element.find('span').html('');
34397 element.find('span').append(heading);
34404 angular.module('ui.bootstrap.alert', [])
34406 .controller('UibAlertController', ['$scope', '$attrs', '$interpolate', '$timeout', function($scope, $attrs, $interpolate, $timeout) {
34407 $scope.closeable = !!$attrs.close;
34409 var dismissOnTimeout = angular.isDefined($attrs.dismissOnTimeout) ?
34410 $interpolate($attrs.dismissOnTimeout)($scope.$parent) : null;
34412 if (dismissOnTimeout) {
34413 $timeout(function() {
34415 }, parseInt(dismissOnTimeout, 10));
34419 .directive('uibAlert', function() {
34421 controller: 'UibAlertController',
34422 controllerAs: 'alert',
34423 templateUrl: function(element, attrs) {
34424 return attrs.templateUrl || 'uib/template/alert/alert.html';
34435 angular.module('ui.bootstrap.buttons', [])
34437 .constant('uibButtonConfig', {
34438 activeClass: 'active',
34439 toggleEvent: 'click'
34442 .controller('UibButtonsController', ['uibButtonConfig', function(buttonConfig) {
34443 this.activeClass = buttonConfig.activeClass || 'active';
34444 this.toggleEvent = buttonConfig.toggleEvent || 'click';
34447 .directive('uibBtnRadio', ['$parse', function($parse) {
34449 require: ['uibBtnRadio', 'ngModel'],
34450 controller: 'UibButtonsController',
34451 controllerAs: 'buttons',
34452 link: function(scope, element, attrs, ctrls) {
34453 var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];
34454 var uncheckableExpr = $parse(attrs.uibUncheckable);
34456 element.find('input').css({display: 'none'});
34459 ngModelCtrl.$render = function() {
34460 element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, scope.$eval(attrs.uibBtnRadio)));
34464 element.on(buttonsCtrl.toggleEvent, function() {
34465 if (attrs.disabled) {
34469 var isActive = element.hasClass(buttonsCtrl.activeClass);
34471 if (!isActive || angular.isDefined(attrs.uncheckable)) {
34472 scope.$apply(function() {
34473 ngModelCtrl.$setViewValue(isActive ? null : scope.$eval(attrs.uibBtnRadio));
34474 ngModelCtrl.$render();
34479 if (attrs.uibUncheckable) {
34480 scope.$watch(uncheckableExpr, function(uncheckable) {
34481 attrs.$set('uncheckable', uncheckable ? '' : null);
34488 .directive('uibBtnCheckbox', function() {
34490 require: ['uibBtnCheckbox', 'ngModel'],
34491 controller: 'UibButtonsController',
34492 controllerAs: 'button',
34493 link: function(scope, element, attrs, ctrls) {
34494 var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];
34496 element.find('input').css({display: 'none'});
34498 function getTrueValue() {
34499 return getCheckboxValue(attrs.btnCheckboxTrue, true);
34502 function getFalseValue() {
34503 return getCheckboxValue(attrs.btnCheckboxFalse, false);
34506 function getCheckboxValue(attribute, defaultValue) {
34507 return angular.isDefined(attribute) ? scope.$eval(attribute) : defaultValue;
34511 ngModelCtrl.$render = function() {
34512 element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, getTrueValue()));
34516 element.on(buttonsCtrl.toggleEvent, function() {
34517 if (attrs.disabled) {
34521 scope.$apply(function() {
34522 ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
34523 ngModelCtrl.$render();
34530 angular.module('ui.bootstrap.carousel', [])
34532 .controller('UibCarouselController', ['$scope', '$element', '$interval', '$timeout', '$animate', function($scope, $element, $interval, $timeout, $animate) {
34534 slides = self.slides = $scope.slides = [],
34535 SLIDE_DIRECTION = 'uib-slideDirection',
34537 currentInterval, isPlaying, bufferedTransitions = [];
34538 self.currentSlide = null;
34540 var destroyed = false;
34542 self.addSlide = function(slide, element) {
34543 slide.$element = element;
34544 slides.push(slide);
34545 //if this is the first slide or the slide is set to active, select it
34546 if (slides.length === 1 || slide.active) {
34547 if ($scope.$currentTransition) {
34548 $scope.$currentTransition = null;
34551 self.select(slides[slides.length - 1]);
34552 if (slides.length === 1) {
34556 slide.active = false;
34560 self.getCurrentIndex = function() {
34561 if (self.currentSlide && angular.isDefined(self.currentSlide.index)) {
34562 return +self.currentSlide.index;
34564 return currentIndex;
34567 self.next = $scope.next = function() {
34568 var newIndex = (self.getCurrentIndex() + 1) % slides.length;
34570 if (newIndex === 0 && $scope.noWrap()) {
34575 return self.select(getSlideByIndex(newIndex), 'next');
34578 self.prev = $scope.prev = function() {
34579 var newIndex = self.getCurrentIndex() - 1 < 0 ? slides.length - 1 : self.getCurrentIndex() - 1;
34581 if ($scope.noWrap() && newIndex === slides.length - 1) {
34586 return self.select(getSlideByIndex(newIndex), 'prev');
34589 self.removeSlide = function(slide) {
34590 if (angular.isDefined(slide.index)) {
34591 slides.sort(function(a, b) {
34592 return +a.index > +b.index;
34596 var bufferedIndex = bufferedTransitions.indexOf(slide);
34597 if (bufferedIndex !== -1) {
34598 bufferedTransitions.splice(bufferedIndex, 1);
34600 //get the index of the slide inside the carousel
34601 var index = slides.indexOf(slide);
34602 slides.splice(index, 1);
34603 $timeout(function() {
34604 if (slides.length > 0 && slide.active) {
34605 if (index >= slides.length) {
34606 self.select(slides[index - 1]);
34608 self.select(slides[index]);
34610 } else if (currentIndex > index) {
34615 //clean the currentSlide when no more slide
34616 if (slides.length === 0) {
34617 self.currentSlide = null;
34618 clearBufferedTransitions();
34622 /* direction: "prev" or "next" */
34623 self.select = $scope.select = function(nextSlide, direction) {
34624 var nextIndex = $scope.indexOfSlide(nextSlide);
34625 //Decide direction if it's not given
34626 if (direction === undefined) {
34627 direction = nextIndex > self.getCurrentIndex() ? 'next' : 'prev';
34629 //Prevent this user-triggered transition from occurring if there is already one in progress
34630 if (nextSlide && nextSlide !== self.currentSlide && !$scope.$currentTransition) {
34631 goNext(nextSlide, nextIndex, direction);
34632 } else if (nextSlide && nextSlide !== self.currentSlide && $scope.$currentTransition) {
34633 bufferedTransitions.push(nextSlide);
34637 /* Allow outside people to call indexOf on slides array */
34638 $scope.indexOfSlide = function(slide) {
34639 return angular.isDefined(slide.index) ? +slide.index : slides.indexOf(slide);
34642 $scope.isActive = function(slide) {
34643 return self.currentSlide === slide;
34646 $scope.pause = function() {
34647 if (!$scope.noPause) {
34653 $scope.play = function() {
34660 $scope.$on('$destroy', function() {
34665 $scope.$watch('noTransition', function(noTransition) {
34666 $animate.enabled($element, !noTransition);
34669 $scope.$watch('interval', restartTimer);
34671 $scope.$watchCollection('slides', resetTransition);
34673 function clearBufferedTransitions() {
34674 while (bufferedTransitions.length) {
34675 bufferedTransitions.shift();
34679 function getSlideByIndex(index) {
34680 if (angular.isUndefined(slides[index].index)) {
34681 return slides[index];
34683 for (var i = 0, l = slides.length; i < l; ++i) {
34684 if (slides[i].index === index) {
34690 function goNext(slide, index, direction) {
34691 if (destroyed) { return; }
34693 angular.extend(slide, {direction: direction, active: true});
34694 angular.extend(self.currentSlide || {}, {direction: direction, active: false});
34695 if ($animate.enabled($element) && !$scope.$currentTransition &&
34696 slide.$element && self.slides.length > 1) {
34697 slide.$element.data(SLIDE_DIRECTION, slide.direction);
34698 if (self.currentSlide && self.currentSlide.$element) {
34699 self.currentSlide.$element.data(SLIDE_DIRECTION, slide.direction);
34702 $scope.$currentTransition = true;
34703 $animate.on('addClass', slide.$element, function(element, phase) {
34704 if (phase === 'close') {
34705 $scope.$currentTransition = null;
34706 $animate.off('addClass', element);
34707 if (bufferedTransitions.length) {
34708 var nextSlide = bufferedTransitions.pop();
34709 var nextIndex = $scope.indexOfSlide(nextSlide);
34710 var nextDirection = nextIndex > self.getCurrentIndex() ? 'next' : 'prev';
34711 clearBufferedTransitions();
34713 goNext(nextSlide, nextIndex, nextDirection);
34719 self.currentSlide = slide;
34720 currentIndex = index;
34722 //every time you change slides, reset the timer
34726 function resetTimer() {
34727 if (currentInterval) {
34728 $interval.cancel(currentInterval);
34729 currentInterval = null;
34733 function resetTransition(slides) {
34734 if (!slides.length) {
34735 $scope.$currentTransition = null;
34736 clearBufferedTransitions();
34740 function restartTimer() {
34742 var interval = +$scope.interval;
34743 if (!isNaN(interval) && interval > 0) {
34744 currentInterval = $interval(timerFn, interval);
34748 function timerFn() {
34749 var interval = +$scope.interval;
34750 if (isPlaying && !isNaN(interval) && interval > 0 && slides.length) {
34758 .directive('uibCarousel', function() {
34762 controller: 'UibCarouselController',
34763 controllerAs: 'carousel',
34764 templateUrl: function(element, attrs) {
34765 return attrs.templateUrl || 'uib/template/carousel/carousel.html';
34776 .directive('uibSlide', function() {
34778 require: '^uibCarousel',
34781 templateUrl: function(element, attrs) {
34782 return attrs.templateUrl || 'uib/template/carousel/slide.html';
34789 link: function (scope, element, attrs, carouselCtrl) {
34790 carouselCtrl.addSlide(scope, element);
34791 //when the scope is destroyed then remove the slide from the current slides array
34792 scope.$on('$destroy', function() {
34793 carouselCtrl.removeSlide(scope);
34796 scope.$watch('active', function(active) {
34798 carouselCtrl.select(scope);
34805 .animation('.item', ['$animateCss',
34806 function($animateCss) {
34807 var SLIDE_DIRECTION = 'uib-slideDirection';
34809 function removeClass(element, className, callback) {
34810 element.removeClass(className);
34817 beforeAddClass: function(element, className, done) {
34818 if (className === 'active') {
34819 var stopped = false;
34820 var direction = element.data(SLIDE_DIRECTION);
34821 var directionClass = direction === 'next' ? 'left' : 'right';
34822 var removeClassFn = removeClass.bind(this, element,
34823 directionClass + ' ' + direction, done);
34824 element.addClass(direction);
34826 $animateCss(element, {addClass: directionClass})
34828 .done(removeClassFn);
34830 return function() {
34836 beforeRemoveClass: function (element, className, done) {
34837 if (className === 'active') {
34838 var stopped = false;
34839 var direction = element.data(SLIDE_DIRECTION);
34840 var directionClass = direction === 'next' ? 'left' : 'right';
34841 var removeClassFn = removeClass.bind(this, element, directionClass, done);
34843 $animateCss(element, {addClass: directionClass})
34845 .done(removeClassFn);
34847 return function() {
34856 angular.module('ui.bootstrap.dateparser', [])
34858 .service('uibDateParser', ['$log', '$locale', 'orderByFilter', function($log, $locale, orderByFilter) {
34859 // Pulled from https://github.com/mbostock/d3/blob/master/src/format/requote.js
34860 var SPECIAL_CHARACTERS_REGEXP = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
34863 var formatCodeToRegex;
34865 this.init = function() {
34866 localeId = $locale.id;
34870 formatCodeToRegex = [
34874 apply: function(value) { this.year = +value; }
34879 apply: function(value) { this.year = +value + 2000; }
34884 apply: function(value) { this.year = +value; }
34888 regex: '0?[1-9]|1[0-2]',
34889 apply: function(value) { this.month = value - 1; }
34893 regex: $locale.DATETIME_FORMATS.MONTH.join('|'),
34894 apply: function(value) { this.month = $locale.DATETIME_FORMATS.MONTH.indexOf(value); }
34898 regex: $locale.DATETIME_FORMATS.SHORTMONTH.join('|'),
34899 apply: function(value) { this.month = $locale.DATETIME_FORMATS.SHORTMONTH.indexOf(value); }
34903 regex: '0[1-9]|1[0-2]',
34904 apply: function(value) { this.month = value - 1; }
34908 regex: '[1-9]|1[0-2]',
34909 apply: function(value) { this.month = value - 1; }
34913 regex: '[0-2]?[0-9]{1}|3[0-1]{1}',
34914 apply: function(value) { this.date = +value; }
34918 regex: '[0-2][0-9]{1}|3[0-1]{1}',
34919 apply: function(value) { this.date = +value; }
34923 regex: '[1-2]?[0-9]{1}|3[0-1]{1}',
34924 apply: function(value) { this.date = +value; }
34928 regex: $locale.DATETIME_FORMATS.DAY.join('|')
34932 regex: $locale.DATETIME_FORMATS.SHORTDAY.join('|')
34936 regex: '(?:0|1)[0-9]|2[0-3]',
34937 apply: function(value) { this.hours = +value; }
34941 regex: '0[0-9]|1[0-2]',
34942 apply: function(value) { this.hours = +value; }
34946 regex: '1?[0-9]|2[0-3]',
34947 apply: function(value) { this.hours = +value; }
34951 regex: '[0-9]|1[0-2]',
34952 apply: function(value) { this.hours = +value; }
34956 regex: '[0-5][0-9]',
34957 apply: function(value) { this.minutes = +value; }
34961 regex: '[0-9]|[1-5][0-9]',
34962 apply: function(value) { this.minutes = +value; }
34966 regex: '[0-9][0-9][0-9]',
34967 apply: function(value) { this.milliseconds = +value; }
34971 regex: '[0-5][0-9]',
34972 apply: function(value) { this.seconds = +value; }
34976 regex: '[0-9]|[1-5][0-9]',
34977 apply: function(value) { this.seconds = +value; }
34981 regex: $locale.DATETIME_FORMATS.AMPMS.join('|'),
34982 apply: function(value) {
34983 if (this.hours === 12) {
34987 if (value === 'PM') {
34994 regex: '[+-]\\d{4}',
34995 apply: function(value) {
34996 var matches = value.match(/([+-])(\d{2})(\d{2})/),
34998 hours = matches[2],
34999 minutes = matches[3];
35000 this.hours += toInt(sign + hours);
35001 this.minutes += toInt(sign + minutes);
35006 regex: '[0-4][0-9]|5[0-3]'
35010 regex: '[0-9]|[1-4][0-9]|5[0-3]'
35014 regex: $locale.DATETIME_FORMATS.ERANAMES.join('|').replace(/\s/g, '\\s')
35018 regex: $locale.DATETIME_FORMATS.ERAS.join('|')
35022 regex: $locale.DATETIME_FORMATS.ERAS.join('|')
35026 regex: $locale.DATETIME_FORMATS.ERAS.join('|')
35033 function createParser(format) {
35034 var map = [], regex = format.split('');
35036 // check for literal values
35037 var quoteIndex = format.indexOf('\'');
35038 if (quoteIndex > -1) {
35039 var inLiteral = false;
35040 format = format.split('');
35041 for (var i = quoteIndex; i < format.length; i++) {
35043 if (format[i] === '\'') {
35044 if (i + 1 < format.length && format[i+1] === '\'') { // escaped single quote
35047 } else { // end of literal
35054 if (format[i] === '\'') { // start of literal
35062 format = format.join('');
35065 angular.forEach(formatCodeToRegex, function(data) {
35066 var index = format.indexOf(data.key);
35069 format = format.split('');
35071 regex[index] = '(' + data.regex + ')';
35072 format[index] = '$'; // Custom symbol to define consumed part of format
35073 for (var i = index + 1, n = index + data.key.length; i < n; i++) {
35077 format = format.join('');
35082 matcher: data.regex
35088 regex: new RegExp('^' + regex.join('') + '$'),
35089 map: orderByFilter(map, 'index')
35093 this.parse = function(input, format, baseDate) {
35094 if (!angular.isString(input) || !format) {
35098 format = $locale.DATETIME_FORMATS[format] || format;
35099 format = format.replace(SPECIAL_CHARACTERS_REGEXP, '\\$&');
35101 if ($locale.id !== localeId) {
35105 if (!this.parsers[format]) {
35106 this.parsers[format] = createParser(format);
35109 var parser = this.parsers[format],
35110 regex = parser.regex,
35112 results = input.match(regex),
35114 if (results && results.length) {
35116 if (angular.isDate(baseDate) && !isNaN(baseDate.getTime())) {
35118 year: baseDate.getFullYear(),
35119 month: baseDate.getMonth(),
35120 date: baseDate.getDate(),
35121 hours: baseDate.getHours(),
35122 minutes: baseDate.getMinutes(),
35123 seconds: baseDate.getSeconds(),
35124 milliseconds: baseDate.getMilliseconds()
35128 $log.warn('dateparser:', 'baseDate is not a valid date');
35130 fields = { year: 1900, month: 0, date: 1, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 };
35133 for (var i = 1, n = results.length; i < n; i++) {
35134 var mapper = map[i - 1];
35135 if (mapper.matcher === 'Z') {
35139 if (mapper.apply) {
35140 mapper.apply.call(fields, results[i]);
35144 var datesetter = tzOffset ? Date.prototype.setUTCFullYear :
35145 Date.prototype.setFullYear;
35146 var timesetter = tzOffset ? Date.prototype.setUTCHours :
35147 Date.prototype.setHours;
35149 if (isValid(fields.year, fields.month, fields.date)) {
35150 if (angular.isDate(baseDate) && !isNaN(baseDate.getTime()) && !tzOffset) {
35151 dt = new Date(baseDate);
35152 datesetter.call(dt, fields.year, fields.month, fields.date);
35153 timesetter.call(dt, fields.hours, fields.minutes,
35154 fields.seconds, fields.milliseconds);
35157 datesetter.call(dt, fields.year, fields.month, fields.date);
35158 timesetter.call(dt, fields.hours || 0, fields.minutes || 0,
35159 fields.seconds || 0, fields.milliseconds || 0);
35167 // Check if date is valid for specific month (and year for February).
35168 // Month: 0 = Jan, 1 = Feb, etc
35169 function isValid(year, month, date) {
35174 if (month === 1 && date > 28) {
35175 return date === 29 && (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0);
35178 if (month === 3 || month === 5 || month === 8 || month === 10) {
35185 function toInt(str) {
35186 return parseInt(str, 10);
35189 this.toTimezone = toTimezone;
35190 this.fromTimezone = fromTimezone;
35191 this.timezoneToOffset = timezoneToOffset;
35192 this.addDateMinutes = addDateMinutes;
35193 this.convertTimezoneToLocal = convertTimezoneToLocal;
35195 function toTimezone(date, timezone) {
35196 return date && timezone ? convertTimezoneToLocal(date, timezone) : date;
35199 function fromTimezone(date, timezone) {
35200 return date && timezone ? convertTimezoneToLocal(date, timezone, true) : date;
35203 //https://github.com/angular/angular.js/blob/4daafd3dbe6a80d578f5a31df1bb99c77559543e/src/Angular.js#L1207
35204 function timezoneToOffset(timezone, fallback) {
35205 var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
35206 return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
35209 function addDateMinutes(date, minutes) {
35210 date = new Date(date.getTime());
35211 date.setMinutes(date.getMinutes() + minutes);
35215 function convertTimezoneToLocal(date, timezone, reverse) {
35216 reverse = reverse ? -1 : 1;
35217 var timezoneOffset = timezoneToOffset(timezone, date.getTimezoneOffset());
35218 return addDateMinutes(date, reverse * (timezoneOffset - date.getTimezoneOffset()));
35222 // Avoiding use of ng-class as it creates a lot of watchers when a class is to be applied to
35223 // at most one element.
35224 angular.module('ui.bootstrap.isClass', [])
35225 .directive('uibIsClass', [
35227 function ($animate) {
35228 // 11111111 22222222
35229 var ON_REGEXP = /^\s*([\s\S]+?)\s+on\s+([\s\S]+?)\s*$/;
35230 // 11111111 22222222
35231 var IS_REGEXP = /^\s*([\s\S]+?)\s+for\s+([\s\S]+?)\s*$/;
35233 var dataPerTracked = {};
35237 compile: function (tElement, tAttrs) {
35238 var linkedScopes = [];
35239 var instances = [];
35240 var expToData = {};
35241 var lastActivated = null;
35242 var onExpMatches = tAttrs.uibIsClass.match(ON_REGEXP);
35243 var onExp = onExpMatches[2];
35244 var expsStr = onExpMatches[1];
35245 var exps = expsStr.split(',');
35249 function linkFn(scope, element, attrs) {
35250 linkedScopes.push(scope);
35256 exps.forEach(function (exp, k) {
35257 addForExp(exp, scope);
35260 scope.$on('$destroy', removeScope);
35263 function addForExp(exp, scope) {
35264 var matches = exp.match(IS_REGEXP);
35265 var clazz = scope.$eval(matches[1]);
35266 var compareWithExp = matches[2];
35267 var data = expToData[exp];
35269 var watchFn = function (compareWithVal) {
35270 var newActivated = null;
35271 instances.some(function (instance) {
35272 var thisVal = instance.scope.$eval(onExp);
35273 if (thisVal === compareWithVal) {
35274 newActivated = instance;
35278 if (data.lastActivated !== newActivated) {
35279 if (data.lastActivated) {
35280 $animate.removeClass(data.lastActivated.element, clazz);
35282 if (newActivated) {
35283 $animate.addClass(newActivated.element, clazz);
35285 data.lastActivated = newActivated;
35288 expToData[exp] = data = {
35289 lastActivated: null,
35292 compareWithExp: compareWithExp,
35293 watcher: scope.$watch(compareWithExp, watchFn)
35296 data.watchFn(scope.$eval(compareWithExp));
35299 function removeScope(e) {
35300 var removedScope = e.targetScope;
35301 var index = linkedScopes.indexOf(removedScope);
35302 linkedScopes.splice(index, 1);
35303 instances.splice(index, 1);
35304 if (linkedScopes.length) {
35305 var newWatchScope = linkedScopes[0];
35306 angular.forEach(expToData, function (data) {
35307 if (data.scope === removedScope) {
35308 data.watcher = newWatchScope.$watch(data.compareWithExp, data.watchFn);
35309 data.scope = newWatchScope;
35320 angular.module('ui.bootstrap.position', [])
35323 * A set of utility methods for working with the DOM.
35324 * It is meant to be used where we need to absolute-position elements in
35325 * relation to another element (this is the case for tooltips, popovers,
35326 * typeahead suggestions etc.).
35328 .factory('$uibPosition', ['$document', '$window', function($document, $window) {
35330 * Used by scrollbarWidth() function to cache scrollbar's width.
35331 * Do not access this variable directly, use scrollbarWidth() instead.
35333 var SCROLLBAR_WIDTH;
35334 var OVERFLOW_REGEX = {
35335 normal: /(auto|scroll)/,
35336 hidden: /(auto|scroll|hidden)/
35338 var PLACEMENT_REGEX = {
35339 auto: /\s?auto?\s?/i,
35340 primary: /^(top|bottom|left|right)$/,
35341 secondary: /^(top|bottom|left|right|center)$/,
35342 vertical: /^(top|bottom)$/
35348 * Provides a raw DOM element from a jQuery/jQLite element.
35350 * @param {element} elem - The element to convert.
35352 * @returns {element} A HTML element.
35354 getRawNode: function(elem) {
35355 return elem[0] || elem;
35359 * Provides a parsed number for a style property. Strips
35360 * units and casts invalid numbers to 0.
35362 * @param {string} value - The style value to parse.
35364 * @returns {number} A valid number.
35366 parseStyle: function(value) {
35367 value = parseFloat(value);
35368 return isFinite(value) ? value : 0;
35372 * Provides the closest positioned ancestor.
35374 * @param {element} element - The element to get the offest parent for.
35376 * @returns {element} The closest positioned ancestor.
35378 offsetParent: function(elem) {
35379 elem = this.getRawNode(elem);
35381 var offsetParent = elem.offsetParent || $document[0].documentElement;
35383 function isStaticPositioned(el) {
35384 return ($window.getComputedStyle(el).position || 'static') === 'static';
35387 while (offsetParent && offsetParent !== $document[0].documentElement && isStaticPositioned(offsetParent)) {
35388 offsetParent = offsetParent.offsetParent;
35391 return offsetParent || $document[0].documentElement;
35395 * Provides the scrollbar width, concept from TWBS measureScrollbar()
35396 * function in https://github.com/twbs/bootstrap/blob/master/js/modal.js
35398 * @returns {number} The width of the browser scollbar.
35400 scrollbarWidth: function() {
35401 if (angular.isUndefined(SCROLLBAR_WIDTH)) {
35402 var scrollElem = angular.element('<div style="position: absolute; top: -9999px; width: 50px; height: 50px; overflow: scroll;"></div>');
35403 $document.find('body').append(scrollElem);
35404 SCROLLBAR_WIDTH = scrollElem[0].offsetWidth - scrollElem[0].clientWidth;
35405 SCROLLBAR_WIDTH = isFinite(SCROLLBAR_WIDTH) ? SCROLLBAR_WIDTH : 0;
35406 scrollElem.remove();
35409 return SCROLLBAR_WIDTH;
35413 * Provides the closest scrollable ancestor.
35414 * A port of the jQuery UI scrollParent method:
35415 * https://github.com/jquery/jquery-ui/blob/master/ui/scroll-parent.js
35417 * @param {element} elem - The element to find the scroll parent of.
35418 * @param {boolean=} [includeHidden=false] - Should scroll style of 'hidden' be considered,
35419 * default is false.
35421 * @returns {element} A HTML element.
35423 scrollParent: function(elem, includeHidden) {
35424 elem = this.getRawNode(elem);
35426 var overflowRegex = includeHidden ? OVERFLOW_REGEX.hidden : OVERFLOW_REGEX.normal;
35427 var documentEl = $document[0].documentElement;
35428 var elemStyle = $window.getComputedStyle(elem);
35429 var excludeStatic = elemStyle.position === 'absolute';
35430 var scrollParent = elem.parentElement || documentEl;
35432 if (scrollParent === documentEl || elemStyle.position === 'fixed') {
35436 while (scrollParent.parentElement && scrollParent !== documentEl) {
35437 var spStyle = $window.getComputedStyle(scrollParent);
35438 if (excludeStatic && spStyle.position !== 'static') {
35439 excludeStatic = false;
35442 if (!excludeStatic && overflowRegex.test(spStyle.overflow + spStyle.overflowY + spStyle.overflowX)) {
35445 scrollParent = scrollParent.parentElement;
35448 return scrollParent;
35452 * Provides read-only equivalent of jQuery's position function:
35453 * http://api.jquery.com/position/ - distance to closest positioned
35454 * ancestor. Does not account for margins by default like jQuery position.
35456 * @param {element} elem - The element to caclulate the position on.
35457 * @param {boolean=} [includeMargins=false] - Should margins be accounted
35458 * for, default is false.
35460 * @returns {object} An object with the following properties:
35462 * <li>**width**: the width of the element</li>
35463 * <li>**height**: the height of the element</li>
35464 * <li>**top**: distance to top edge of offset parent</li>
35465 * <li>**left**: distance to left edge of offset parent</li>
35468 position: function(elem, includeMagins) {
35469 elem = this.getRawNode(elem);
35471 var elemOffset = this.offset(elem);
35472 if (includeMagins) {
35473 var elemStyle = $window.getComputedStyle(elem);
35474 elemOffset.top -= this.parseStyle(elemStyle.marginTop);
35475 elemOffset.left -= this.parseStyle(elemStyle.marginLeft);
35477 var parent = this.offsetParent(elem);
35478 var parentOffset = {top: 0, left: 0};
35480 if (parent !== $document[0].documentElement) {
35481 parentOffset = this.offset(parent);
35482 parentOffset.top += parent.clientTop - parent.scrollTop;
35483 parentOffset.left += parent.clientLeft - parent.scrollLeft;
35487 width: Math.round(angular.isNumber(elemOffset.width) ? elemOffset.width : elem.offsetWidth),
35488 height: Math.round(angular.isNumber(elemOffset.height) ? elemOffset.height : elem.offsetHeight),
35489 top: Math.round(elemOffset.top - parentOffset.top),
35490 left: Math.round(elemOffset.left - parentOffset.left)
35495 * Provides read-only equivalent of jQuery's offset function:
35496 * http://api.jquery.com/offset/ - distance to viewport. Does
35497 * not account for borders, margins, or padding on the body
35500 * @param {element} elem - The element to calculate the offset on.
35502 * @returns {object} An object with the following properties:
35504 * <li>**width**: the width of the element</li>
35505 * <li>**height**: the height of the element</li>
35506 * <li>**top**: distance to top edge of viewport</li>
35507 * <li>**right**: distance to bottom edge of viewport</li>
35510 offset: function(elem) {
35511 elem = this.getRawNode(elem);
35513 var elemBCR = elem.getBoundingClientRect();
35515 width: Math.round(angular.isNumber(elemBCR.width) ? elemBCR.width : elem.offsetWidth),
35516 height: Math.round(angular.isNumber(elemBCR.height) ? elemBCR.height : elem.offsetHeight),
35517 top: Math.round(elemBCR.top + ($window.pageYOffset || $document[0].documentElement.scrollTop)),
35518 left: Math.round(elemBCR.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft))
35523 * Provides offset distance to the closest scrollable ancestor
35524 * or viewport. Accounts for border and scrollbar width.
35526 * Right and bottom dimensions represent the distance to the
35527 * respective edge of the viewport element. If the element
35528 * edge extends beyond the viewport, a negative value will be
35531 * @param {element} elem - The element to get the viewport offset for.
35532 * @param {boolean=} [useDocument=false] - Should the viewport be the document element instead
35533 * of the first scrollable element, default is false.
35534 * @param {boolean=} [includePadding=true] - Should the padding on the offset parent element
35535 * be accounted for, default is true.
35537 * @returns {object} An object with the following properties:
35539 * <li>**top**: distance to the top content edge of viewport element</li>
35540 * <li>**bottom**: distance to the bottom content edge of viewport element</li>
35541 * <li>**left**: distance to the left content edge of viewport element</li>
35542 * <li>**right**: distance to the right content edge of viewport element</li>
35545 viewportOffset: function(elem, useDocument, includePadding) {
35546 elem = this.getRawNode(elem);
35547 includePadding = includePadding !== false ? true : false;
35549 var elemBCR = elem.getBoundingClientRect();
35550 var offsetBCR = {top: 0, left: 0, bottom: 0, right: 0};
35552 var offsetParent = useDocument ? $document[0].documentElement : this.scrollParent(elem);
35553 var offsetParentBCR = offsetParent.getBoundingClientRect();
35555 offsetBCR.top = offsetParentBCR.top + offsetParent.clientTop;
35556 offsetBCR.left = offsetParentBCR.left + offsetParent.clientLeft;
35557 if (offsetParent === $document[0].documentElement) {
35558 offsetBCR.top += $window.pageYOffset;
35559 offsetBCR.left += $window.pageXOffset;
35561 offsetBCR.bottom = offsetBCR.top + offsetParent.clientHeight;
35562 offsetBCR.right = offsetBCR.left + offsetParent.clientWidth;
35564 if (includePadding) {
35565 var offsetParentStyle = $window.getComputedStyle(offsetParent);
35566 offsetBCR.top += this.parseStyle(offsetParentStyle.paddingTop);
35567 offsetBCR.bottom -= this.parseStyle(offsetParentStyle.paddingBottom);
35568 offsetBCR.left += this.parseStyle(offsetParentStyle.paddingLeft);
35569 offsetBCR.right -= this.parseStyle(offsetParentStyle.paddingRight);
35573 top: Math.round(elemBCR.top - offsetBCR.top),
35574 bottom: Math.round(offsetBCR.bottom - elemBCR.bottom),
35575 left: Math.round(elemBCR.left - offsetBCR.left),
35576 right: Math.round(offsetBCR.right - elemBCR.right)
35581 * Provides an array of placement values parsed from a placement string.
35582 * Along with the 'auto' indicator, supported placement strings are:
35584 * <li>top: element on top, horizontally centered on host element.</li>
35585 * <li>top-left: element on top, left edge aligned with host element left edge.</li>
35586 * <li>top-right: element on top, lerightft edge aligned with host element right edge.</li>
35587 * <li>bottom: element on bottom, horizontally centered on host element.</li>
35588 * <li>bottom-left: element on bottom, left edge aligned with host element left edge.</li>
35589 * <li>bottom-right: element on bottom, right edge aligned with host element right edge.</li>
35590 * <li>left: element on left, vertically centered on host element.</li>
35591 * <li>left-top: element on left, top edge aligned with host element top edge.</li>
35592 * <li>left-bottom: element on left, bottom edge aligned with host element bottom edge.</li>
35593 * <li>right: element on right, vertically centered on host element.</li>
35594 * <li>right-top: element on right, top edge aligned with host element top edge.</li>
35595 * <li>right-bottom: element on right, bottom edge aligned with host element bottom edge.</li>
35597 * A placement string with an 'auto' indicator is expected to be
35598 * space separated from the placement, i.e: 'auto bottom-left' If
35599 * the primary and secondary placement values do not match 'top,
35600 * bottom, left, right' then 'top' will be the primary placement and
35601 * 'center' will be the secondary placement. If 'auto' is passed, true
35602 * will be returned as the 3rd value of the array.
35604 * @param {string} placement - The placement string to parse.
35606 * @returns {array} An array with the following values
35608 * <li>**[0]**: The primary placement.</li>
35609 * <li>**[1]**: The secondary placement.</li>
35610 * <li>**[2]**: If auto is passed: true, else undefined.</li>
35613 parsePlacement: function(placement) {
35614 var autoPlace = PLACEMENT_REGEX.auto.test(placement);
35616 placement = placement.replace(PLACEMENT_REGEX.auto, '');
35619 placement = placement.split('-');
35621 placement[0] = placement[0] || 'top';
35622 if (!PLACEMENT_REGEX.primary.test(placement[0])) {
35623 placement[0] = 'top';
35626 placement[1] = placement[1] || 'center';
35627 if (!PLACEMENT_REGEX.secondary.test(placement[1])) {
35628 placement[1] = 'center';
35632 placement[2] = true;
35634 placement[2] = false;
35641 * Provides coordinates for an element to be positioned relative to
35642 * another element. Passing 'auto' as part of the placement parameter
35643 * will enable smart placement - where the element fits. i.e:
35644 * 'auto left-top' will check to see if there is enough space to the left
35645 * of the hostElem to fit the targetElem, if not place right (same for secondary
35646 * top placement). Available space is calculated using the viewportOffset
35649 * @param {element} hostElem - The element to position against.
35650 * @param {element} targetElem - The element to position.
35651 * @param {string=} [placement=top] - The placement for the targetElem,
35652 * default is 'top'. 'center' is assumed as secondary placement for
35653 * 'top', 'left', 'right', and 'bottom' placements. Available placements are:
35656 * <li>top-right</li>
35657 * <li>top-left</li>
35659 * <li>bottom-left</li>
35660 * <li>bottom-right</li>
35662 * <li>left-top</li>
35663 * <li>left-bottom</li>
35665 * <li>right-top</li>
35666 * <li>right-bottom</li>
35668 * @param {boolean=} [appendToBody=false] - Should the top and left values returned
35669 * be calculated from the body element, default is false.
35671 * @returns {object} An object with the following properties:
35673 * <li>**top**: Value for targetElem top.</li>
35674 * <li>**left**: Value for targetElem left.</li>
35675 * <li>**placement**: The resolved placement.</li>
35678 positionElements: function(hostElem, targetElem, placement, appendToBody) {
35679 hostElem = this.getRawNode(hostElem);
35680 targetElem = this.getRawNode(targetElem);
35682 // need to read from prop to support tests.
35683 var targetWidth = angular.isDefined(targetElem.offsetWidth) ? targetElem.offsetWidth : targetElem.prop('offsetWidth');
35684 var targetHeight = angular.isDefined(targetElem.offsetHeight) ? targetElem.offsetHeight : targetElem.prop('offsetHeight');
35686 placement = this.parsePlacement(placement);
35688 var hostElemPos = appendToBody ? this.offset(hostElem) : this.position(hostElem);
35689 var targetElemPos = {top: 0, left: 0, placement: ''};
35691 if (placement[2]) {
35692 var viewportOffset = this.viewportOffset(hostElem);
35694 var targetElemStyle = $window.getComputedStyle(targetElem);
35695 var adjustedSize = {
35696 width: targetWidth + Math.round(Math.abs(this.parseStyle(targetElemStyle.marginLeft) + this.parseStyle(targetElemStyle.marginRight))),
35697 height: targetHeight + Math.round(Math.abs(this.parseStyle(targetElemStyle.marginTop) + this.parseStyle(targetElemStyle.marginBottom)))
35700 placement[0] = placement[0] === 'top' && adjustedSize.height > viewportOffset.top && adjustedSize.height <= viewportOffset.bottom ? 'bottom' :
35701 placement[0] === 'bottom' && adjustedSize.height > viewportOffset.bottom && adjustedSize.height <= viewportOffset.top ? 'top' :
35702 placement[0] === 'left' && adjustedSize.width > viewportOffset.left && adjustedSize.width <= viewportOffset.right ? 'right' :
35703 placement[0] === 'right' && adjustedSize.width > viewportOffset.right && adjustedSize.width <= viewportOffset.left ? 'left' :
35706 placement[1] = placement[1] === 'top' && adjustedSize.height - hostElemPos.height > viewportOffset.bottom && adjustedSize.height - hostElemPos.height <= viewportOffset.top ? 'bottom' :
35707 placement[1] === 'bottom' && adjustedSize.height - hostElemPos.height > viewportOffset.top && adjustedSize.height - hostElemPos.height <= viewportOffset.bottom ? 'top' :
35708 placement[1] === 'left' && adjustedSize.width - hostElemPos.width > viewportOffset.right && adjustedSize.width - hostElemPos.width <= viewportOffset.left ? 'right' :
35709 placement[1] === 'right' && adjustedSize.width - hostElemPos.width > viewportOffset.left && adjustedSize.width - hostElemPos.width <= viewportOffset.right ? 'left' :
35712 if (placement[1] === 'center') {
35713 if (PLACEMENT_REGEX.vertical.test(placement[0])) {
35714 var xOverflow = hostElemPos.width / 2 - targetWidth / 2;
35715 if (viewportOffset.left + xOverflow < 0 && adjustedSize.width - hostElemPos.width <= viewportOffset.right) {
35716 placement[1] = 'left';
35717 } else if (viewportOffset.right + xOverflow < 0 && adjustedSize.width - hostElemPos.width <= viewportOffset.left) {
35718 placement[1] = 'right';
35721 var yOverflow = hostElemPos.height / 2 - adjustedSize.height / 2;
35722 if (viewportOffset.top + yOverflow < 0 && adjustedSize.height - hostElemPos.height <= viewportOffset.bottom) {
35723 placement[1] = 'top';
35724 } else if (viewportOffset.bottom + yOverflow < 0 && adjustedSize.height - hostElemPos.height <= viewportOffset.top) {
35725 placement[1] = 'bottom';
35731 switch (placement[0]) {
35733 targetElemPos.top = hostElemPos.top - targetHeight;
35736 targetElemPos.top = hostElemPos.top + hostElemPos.height;
35739 targetElemPos.left = hostElemPos.left - targetWidth;
35742 targetElemPos.left = hostElemPos.left + hostElemPos.width;
35746 switch (placement[1]) {
35748 targetElemPos.top = hostElemPos.top;
35751 targetElemPos.top = hostElemPos.top + hostElemPos.height - targetHeight;
35754 targetElemPos.left = hostElemPos.left;
35757 targetElemPos.left = hostElemPos.left + hostElemPos.width - targetWidth;
35760 if (PLACEMENT_REGEX.vertical.test(placement[0])) {
35761 targetElemPos.left = hostElemPos.left + hostElemPos.width / 2 - targetWidth / 2;
35763 targetElemPos.top = hostElemPos.top + hostElemPos.height / 2 - targetHeight / 2;
35768 targetElemPos.top = Math.round(targetElemPos.top);
35769 targetElemPos.left = Math.round(targetElemPos.left);
35770 targetElemPos.placement = placement[1] === 'center' ? placement[0] : placement[0] + '-' + placement[1];
35772 return targetElemPos;
35776 * Provides a way for positioning tooltip & dropdown
35777 * arrows when using placement options beyond the standard
35778 * left, right, top, or bottom.
35780 * @param {element} elem - The tooltip/dropdown element.
35781 * @param {string} placement - The placement for the elem.
35783 positionArrow: function(elem, placement) {
35784 elem = this.getRawNode(elem);
35786 var isTooltip = true;
35788 var innerElem = elem.querySelector('.tooltip-inner');
35791 innerElem = elem.querySelector('.popover-inner');
35797 var arrowElem = isTooltip ? elem.querySelector('.tooltip-arrow') : elem.querySelector('.arrow');
35802 placement = this.parsePlacement(placement);
35803 if (placement[1] === 'center') {
35804 // no adjustment necessary - just reset styles
35805 angular.element(arrowElem).css({top: '', bottom: '', right: '', left: '', margin: ''});
35809 var borderProp = 'border-' + placement[0] + '-width';
35810 var borderWidth = $window.getComputedStyle(arrowElem)[borderProp];
35812 var borderRadiusProp = 'border-';
35813 if (PLACEMENT_REGEX.vertical.test(placement[0])) {
35814 borderRadiusProp += placement[0] + '-' + placement[1];
35816 borderRadiusProp += placement[1] + '-' + placement[0];
35818 borderRadiusProp += '-radius';
35819 var borderRadius = $window.getComputedStyle(isTooltip ? innerElem : elem)[borderRadiusProp];
35829 switch (placement[0]) {
35831 arrowCss.bottom = isTooltip ? '0' : '-' + borderWidth;
35834 arrowCss.top = isTooltip ? '0' : '-' + borderWidth;
35837 arrowCss.right = isTooltip ? '0' : '-' + borderWidth;
35840 arrowCss.left = isTooltip ? '0' : '-' + borderWidth;
35844 arrowCss[placement[1]] = borderRadius;
35846 angular.element(arrowElem).css(arrowCss);
35851 angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.isClass', 'ui.bootstrap.position'])
35853 .value('$datepickerSuppressError', false)
35855 .constant('uibDatepickerConfig', {
35857 formatMonth: 'MMMM',
35858 formatYear: 'yyyy',
35859 formatDayHeader: 'EEE',
35860 formatDayTitle: 'MMMM yyyy',
35861 formatMonthTitle: 'yyyy',
35862 datepickerMode: 'day',
35871 shortcutPropagation: false,
35875 .controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser',
35876 function($scope, $attrs, $parse, $interpolate, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) {
35878 ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl;
35879 ngModelOptions = {};
35882 this.modes = ['day', 'month', 'year'];
35884 // Interpolated configuration attributes
35885 angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle'], function(key) {
35886 self[key] = angular.isDefined($attrs[key]) ? $interpolate($attrs[key])($scope.$parent) : datepickerConfig[key];
35889 // Evaled configuration attributes
35890 angular.forEach(['showWeeks', 'startingDay', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) {
35891 self[key] = angular.isDefined($attrs[key]) ? $scope.$parent.$eval($attrs[key]) : datepickerConfig[key];
35894 // Watchable date attributes
35895 angular.forEach(['minDate', 'maxDate'], function(key) {
35897 $scope.$parent.$watch($attrs[key], function(value) {
35898 self[key] = value ? angular.isDate(value) ? dateParser.fromTimezone(new Date(value), ngModelOptions.timezone) : new Date(dateFilter(value, 'medium')) : null;
35899 self.refreshView();
35902 self[key] = datepickerConfig[key] ? dateParser.fromTimezone(new Date(datepickerConfig[key]), ngModelOptions.timezone) : null;
35906 angular.forEach(['minMode', 'maxMode'], function(key) {
35908 $scope.$parent.$watch($attrs[key], function(value) {
35909 self[key] = $scope[key] = angular.isDefined(value) ? value : $attrs[key];
35910 if (key === 'minMode' && self.modes.indexOf($scope.datepickerMode) < self.modes.indexOf(self[key]) ||
35911 key === 'maxMode' && self.modes.indexOf($scope.datepickerMode) > self.modes.indexOf(self[key])) {
35912 $scope.datepickerMode = self[key];
35916 self[key] = $scope[key] = datepickerConfig[key] || null;
35920 $scope.datepickerMode = $scope.datepickerMode || datepickerConfig.datepickerMode;
35921 $scope.uniqueId = 'datepicker-' + $scope.$id + '-' + Math.floor(Math.random() * 10000);
35923 if (angular.isDefined($attrs.initDate)) {
35924 this.activeDate = dateParser.fromTimezone($scope.$parent.$eval($attrs.initDate), ngModelOptions.timezone) || new Date();
35925 $scope.$parent.$watch($attrs.initDate, function(initDate) {
35926 if (initDate && (ngModelCtrl.$isEmpty(ngModelCtrl.$modelValue) || ngModelCtrl.$invalid)) {
35927 self.activeDate = dateParser.fromTimezone(initDate, ngModelOptions.timezone);
35928 self.refreshView();
35932 this.activeDate = new Date();
35935 $scope.disabled = angular.isDefined($attrs.disabled) || false;
35936 if (angular.isDefined($attrs.ngDisabled)) {
35937 $scope.$parent.$watch($attrs.ngDisabled, function(disabled) {
35938 $scope.disabled = disabled;
35939 self.refreshView();
35943 $scope.isActive = function(dateObject) {
35944 if (self.compare(dateObject.date, self.activeDate) === 0) {
35945 $scope.activeDateId = dateObject.uid;
35951 this.init = function(ngModelCtrl_) {
35952 ngModelCtrl = ngModelCtrl_;
35953 ngModelOptions = ngModelCtrl_.$options || datepickerConfig.ngModelOptions;
35955 if (ngModelCtrl.$modelValue) {
35956 this.activeDate = ngModelCtrl.$modelValue;
35959 ngModelCtrl.$render = function() {
35964 this.render = function() {
35965 if (ngModelCtrl.$viewValue) {
35966 var date = new Date(ngModelCtrl.$viewValue),
35967 isValid = !isNaN(date);
35970 this.activeDate = dateParser.fromTimezone(date, ngModelOptions.timezone);
35971 } else if (!$datepickerSuppressError) {
35972 $log.error('Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.');
35975 this.refreshView();
35978 this.refreshView = function() {
35979 if (this.element) {
35980 $scope.selectedDt = null;
35981 this._refreshView();
35982 if ($scope.activeDt) {
35983 $scope.activeDateId = $scope.activeDt.uid;
35986 var date = ngModelCtrl.$viewValue ? new Date(ngModelCtrl.$viewValue) : null;
35987 date = dateParser.fromTimezone(date, ngModelOptions.timezone);
35988 ngModelCtrl.$setValidity('dateDisabled', !date ||
35989 this.element && !this.isDisabled(date));
35993 this.createDateObject = function(date, format) {
35994 var model = ngModelCtrl.$viewValue ? new Date(ngModelCtrl.$viewValue) : null;
35995 model = dateParser.fromTimezone(model, ngModelOptions.timezone);
35998 label: dateFilter(date, format),
35999 selected: model && this.compare(date, model) === 0,
36000 disabled: this.isDisabled(date),
36001 current: this.compare(date, new Date()) === 0,
36002 customClass: this.customClass(date) || null
36005 if (model && this.compare(date, model) === 0) {
36006 $scope.selectedDt = dt;
36009 if (self.activeDate && this.compare(dt.date, self.activeDate) === 0) {
36010 $scope.activeDt = dt;
36016 this.isDisabled = function(date) {
36017 return $scope.disabled ||
36018 this.minDate && this.compare(date, this.minDate) < 0 ||
36019 this.maxDate && this.compare(date, this.maxDate) > 0 ||
36020 $attrs.dateDisabled && $scope.dateDisabled({date: date, mode: $scope.datepickerMode});
36023 this.customClass = function(date) {
36024 return $scope.customClass({date: date, mode: $scope.datepickerMode});
36027 // Split array into smaller arrays
36028 this.split = function(arr, size) {
36030 while (arr.length > 0) {
36031 arrays.push(arr.splice(0, size));
36036 $scope.select = function(date) {
36037 if ($scope.datepickerMode === self.minMode) {
36038 var dt = ngModelCtrl.$viewValue ? dateParser.fromTimezone(new Date(ngModelCtrl.$viewValue), ngModelOptions.timezone) : new Date(0, 0, 0, 0, 0, 0, 0);
36039 dt.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
36040 dt = dateParser.toTimezone(dt, ngModelOptions.timezone);
36041 ngModelCtrl.$setViewValue(dt);
36042 ngModelCtrl.$render();
36044 self.activeDate = date;
36045 $scope.datepickerMode = self.modes[self.modes.indexOf($scope.datepickerMode) - 1];
36049 $scope.move = function(direction) {
36050 var year = self.activeDate.getFullYear() + direction * (self.step.years || 0),
36051 month = self.activeDate.getMonth() + direction * (self.step.months || 0);
36052 self.activeDate.setFullYear(year, month, 1);
36053 self.refreshView();
36056 $scope.toggleMode = function(direction) {
36057 direction = direction || 1;
36059 if ($scope.datepickerMode === self.maxMode && direction === 1 ||
36060 $scope.datepickerMode === self.minMode && direction === -1) {
36064 $scope.datepickerMode = self.modes[self.modes.indexOf($scope.datepickerMode) + direction];
36067 // Key event mapper
36068 $scope.keys = { 13: 'enter', 32: 'space', 33: 'pageup', 34: 'pagedown', 35: 'end', 36: 'home', 37: 'left', 38: 'up', 39: 'right', 40: 'down' };
36070 var focusElement = function() {
36071 self.element[0].focus();
36074 // Listen for focus requests from popup directive
36075 $scope.$on('uib:datepicker.focus', focusElement);
36077 $scope.keydown = function(evt) {
36078 var key = $scope.keys[evt.which];
36080 if (!key || evt.shiftKey || evt.altKey || $scope.disabled) {
36084 evt.preventDefault();
36085 if (!self.shortcutPropagation) {
36086 evt.stopPropagation();
36089 if (key === 'enter' || key === 'space') {
36090 if (self.isDisabled(self.activeDate)) {
36091 return; // do nothing
36093 $scope.select(self.activeDate);
36094 } else if (evt.ctrlKey && (key === 'up' || key === 'down')) {
36095 $scope.toggleMode(key === 'up' ? 1 : -1);
36097 self.handleKeyDown(key, evt);
36098 self.refreshView();
36103 .controller('UibDaypickerController', ['$scope', '$element', 'dateFilter', function(scope, $element, dateFilter) {
36104 var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
36106 this.step = { months: 1 };
36107 this.element = $element;
36108 function getDaysInMonth(year, month) {
36109 return month === 1 && year % 4 === 0 &&
36110 (year % 100 !== 0 || year % 400 === 0) ? 29 : DAYS_IN_MONTH[month];
36113 this.init = function(ctrl) {
36114 angular.extend(ctrl, this);
36115 scope.showWeeks = ctrl.showWeeks;
36116 ctrl.refreshView();
36119 this.getDates = function(startDate, n) {
36120 var dates = new Array(n), current = new Date(startDate), i = 0, date;
36122 date = new Date(current);
36124 current.setDate(current.getDate() + 1);
36129 this._refreshView = function() {
36130 var year = this.activeDate.getFullYear(),
36131 month = this.activeDate.getMonth(),
36132 firstDayOfMonth = new Date(this.activeDate);
36134 firstDayOfMonth.setFullYear(year, month, 1);
36136 var difference = this.startingDay - firstDayOfMonth.getDay(),
36137 numDisplayedFromPreviousMonth = difference > 0 ?
36138 7 - difference : - difference,
36139 firstDate = new Date(firstDayOfMonth);
36141 if (numDisplayedFromPreviousMonth > 0) {
36142 firstDate.setDate(-numDisplayedFromPreviousMonth + 1);
36145 // 42 is the number of days on a six-week calendar
36146 var days = this.getDates(firstDate, 42);
36147 for (var i = 0; i < 42; i ++) {
36148 days[i] = angular.extend(this.createDateObject(days[i], this.formatDay), {
36149 secondary: days[i].getMonth() !== month,
36150 uid: scope.uniqueId + '-' + i
36154 scope.labels = new Array(7);
36155 for (var j = 0; j < 7; j++) {
36156 scope.labels[j] = {
36157 abbr: dateFilter(days[j].date, this.formatDayHeader),
36158 full: dateFilter(days[j].date, 'EEEE')
36162 scope.title = dateFilter(this.activeDate, this.formatDayTitle);
36163 scope.rows = this.split(days, 7);
36165 if (scope.showWeeks) {
36166 scope.weekNumbers = [];
36167 var thursdayIndex = (4 + 7 - this.startingDay) % 7,
36168 numWeeks = scope.rows.length;
36169 for (var curWeek = 0; curWeek < numWeeks; curWeek++) {
36170 scope.weekNumbers.push(
36171 getISO8601WeekNumber(scope.rows[curWeek][thursdayIndex].date));
36176 this.compare = function(date1, date2) {
36177 var _date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
36178 var _date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
36179 _date1.setFullYear(date1.getFullYear());
36180 _date2.setFullYear(date2.getFullYear());
36181 return _date1 - _date2;
36184 function getISO8601WeekNumber(date) {
36185 var checkDate = new Date(date);
36186 checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); // Thursday
36187 var time = checkDate.getTime();
36188 checkDate.setMonth(0); // Compare with Jan 1
36189 checkDate.setDate(1);
36190 return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
36193 this.handleKeyDown = function(key, evt) {
36194 var date = this.activeDate.getDate();
36196 if (key === 'left') {
36198 } else if (key === 'up') {
36200 } else if (key === 'right') {
36202 } else if (key === 'down') {
36204 } else if (key === 'pageup' || key === 'pagedown') {
36205 var month = this.activeDate.getMonth() + (key === 'pageup' ? - 1 : 1);
36206 this.activeDate.setMonth(month, 1);
36207 date = Math.min(getDaysInMonth(this.activeDate.getFullYear(), this.activeDate.getMonth()), date);
36208 } else if (key === 'home') {
36210 } else if (key === 'end') {
36211 date = getDaysInMonth(this.activeDate.getFullYear(), this.activeDate.getMonth());
36213 this.activeDate.setDate(date);
36217 .controller('UibMonthpickerController', ['$scope', '$element', 'dateFilter', function(scope, $element, dateFilter) {
36218 this.step = { years: 1 };
36219 this.element = $element;
36221 this.init = function(ctrl) {
36222 angular.extend(ctrl, this);
36223 ctrl.refreshView();
36226 this._refreshView = function() {
36227 var months = new Array(12),
36228 year = this.activeDate.getFullYear(),
36231 for (var i = 0; i < 12; i++) {
36232 date = new Date(this.activeDate);
36233 date.setFullYear(year, i, 1);
36234 months[i] = angular.extend(this.createDateObject(date, this.formatMonth), {
36235 uid: scope.uniqueId + '-' + i
36239 scope.title = dateFilter(this.activeDate, this.formatMonthTitle);
36240 scope.rows = this.split(months, 3);
36243 this.compare = function(date1, date2) {
36244 var _date1 = new Date(date1.getFullYear(), date1.getMonth());
36245 var _date2 = new Date(date2.getFullYear(), date2.getMonth());
36246 _date1.setFullYear(date1.getFullYear());
36247 _date2.setFullYear(date2.getFullYear());
36248 return _date1 - _date2;
36251 this.handleKeyDown = function(key, evt) {
36252 var date = this.activeDate.getMonth();
36254 if (key === 'left') {
36256 } else if (key === 'up') {
36258 } else if (key === 'right') {
36260 } else if (key === 'down') {
36262 } else if (key === 'pageup' || key === 'pagedown') {
36263 var year = this.activeDate.getFullYear() + (key === 'pageup' ? - 1 : 1);
36264 this.activeDate.setFullYear(year);
36265 } else if (key === 'home') {
36267 } else if (key === 'end') {
36270 this.activeDate.setMonth(date);
36274 .controller('UibYearpickerController', ['$scope', '$element', 'dateFilter', function(scope, $element, dateFilter) {
36275 var columns, range;
36276 this.element = $element;
36278 function getStartingYear(year) {
36279 return parseInt((year - 1) / range, 10) * range + 1;
36282 this.yearpickerInit = function() {
36283 columns = this.yearColumns;
36284 range = this.yearRows * columns;
36285 this.step = { years: range };
36288 this._refreshView = function() {
36289 var years = new Array(range), date;
36291 for (var i = 0, start = getStartingYear(this.activeDate.getFullYear()); i < range; i++) {
36292 date = new Date(this.activeDate);
36293 date.setFullYear(start + i, 0, 1);
36294 years[i] = angular.extend(this.createDateObject(date, this.formatYear), {
36295 uid: scope.uniqueId + '-' + i
36299 scope.title = [years[0].label, years[range - 1].label].join(' - ');
36300 scope.rows = this.split(years, columns);
36301 scope.columns = columns;
36304 this.compare = function(date1, date2) {
36305 return date1.getFullYear() - date2.getFullYear();
36308 this.handleKeyDown = function(key, evt) {
36309 var date = this.activeDate.getFullYear();
36311 if (key === 'left') {
36313 } else if (key === 'up') {
36314 date = date - columns;
36315 } else if (key === 'right') {
36317 } else if (key === 'down') {
36318 date = date + columns;
36319 } else if (key === 'pageup' || key === 'pagedown') {
36320 date += (key === 'pageup' ? - 1 : 1) * range;
36321 } else if (key === 'home') {
36322 date = getStartingYear(this.activeDate.getFullYear());
36323 } else if (key === 'end') {
36324 date = getStartingYear(this.activeDate.getFullYear()) + range - 1;
36326 this.activeDate.setFullYear(date);
36330 .directive('uibDatepicker', function() {
36333 templateUrl: function(element, attrs) {
36334 return attrs.templateUrl || 'uib/template/datepicker/datepicker.html';
36337 datepickerMode: '=?',
36340 shortcutPropagation: '&?'
36342 require: ['uibDatepicker', '^ngModel'],
36343 controller: 'UibDatepickerController',
36344 controllerAs: 'datepicker',
36345 link: function(scope, element, attrs, ctrls) {
36346 var datepickerCtrl = ctrls[0], ngModelCtrl = ctrls[1];
36348 datepickerCtrl.init(ngModelCtrl);
36353 .directive('uibDaypicker', function() {
36356 templateUrl: function(element, attrs) {
36357 return attrs.templateUrl || 'uib/template/datepicker/day.html';
36359 require: ['^uibDatepicker', 'uibDaypicker'],
36360 controller: 'UibDaypickerController',
36361 link: function(scope, element, attrs, ctrls) {
36362 var datepickerCtrl = ctrls[0],
36363 daypickerCtrl = ctrls[1];
36365 daypickerCtrl.init(datepickerCtrl);
36370 .directive('uibMonthpicker', function() {
36373 templateUrl: function(element, attrs) {
36374 return attrs.templateUrl || 'uib/template/datepicker/month.html';
36376 require: ['^uibDatepicker', 'uibMonthpicker'],
36377 controller: 'UibMonthpickerController',
36378 link: function(scope, element, attrs, ctrls) {
36379 var datepickerCtrl = ctrls[0],
36380 monthpickerCtrl = ctrls[1];
36382 monthpickerCtrl.init(datepickerCtrl);
36387 .directive('uibYearpicker', function() {
36390 templateUrl: function(element, attrs) {
36391 return attrs.templateUrl || 'uib/template/datepicker/year.html';
36393 require: ['^uibDatepicker', 'uibYearpicker'],
36394 controller: 'UibYearpickerController',
36395 link: function(scope, element, attrs, ctrls) {
36396 var ctrl = ctrls[0];
36397 angular.extend(ctrl, ctrls[1]);
36398 ctrl.yearpickerInit();
36400 ctrl.refreshView();
36405 .constant('uibDatepickerPopupConfig', {
36406 datepickerPopup: 'yyyy-MM-dd',
36407 datepickerPopupTemplateUrl: 'uib/template/datepicker/popup.html',
36408 datepickerTemplateUrl: 'uib/template/datepicker/datepicker.html',
36410 date: 'yyyy-MM-dd',
36411 'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss',
36414 currentText: 'Today',
36415 clearText: 'Clear',
36417 closeOnDateSelection: true,
36418 appendToBody: false,
36419 showButtonBar: true,
36421 altInputFormats: []
36424 .controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig',
36425 function(scope, element, attrs, $compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig) {
36428 isHtml5DateInput = false;
36429 var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus,
36430 datepickerPopupTemplateUrl, datepickerTemplateUrl, popupEl, datepickerEl,
36431 ngModel, ngModelOptions, $popup, altInputFormats;
36433 scope.watchData = {};
36435 this.init = function(_ngModel_) {
36436 ngModel = _ngModel_;
36437 ngModelOptions = _ngModel_.$options || datepickerConfig.ngModelOptions;
36438 closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? scope.$parent.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection;
36439 appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? scope.$parent.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
36440 onOpenFocus = angular.isDefined(attrs.onOpenFocus) ? scope.$parent.$eval(attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus;
36441 datepickerPopupTemplateUrl = angular.isDefined(attrs.datepickerPopupTemplateUrl) ? attrs.datepickerPopupTemplateUrl : datepickerPopupConfig.datepickerPopupTemplateUrl;
36442 datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ? attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
36443 altInputFormats = angular.isDefined(attrs.altInputFormats) ? scope.$parent.$eval(attrs.altInputFormats) : datepickerPopupConfig.altInputFormats;
36445 scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;
36447 if (datepickerPopupConfig.html5Types[attrs.type]) {
36448 dateFormat = datepickerPopupConfig.html5Types[attrs.type];
36449 isHtml5DateInput = true;
36451 dateFormat = attrs.uibDatepickerPopup || datepickerPopupConfig.datepickerPopup;
36452 attrs.$observe('uibDatepickerPopup', function(value, oldValue) {
36453 var newDateFormat = value || datepickerPopupConfig.datepickerPopup;
36454 // Invalidate the $modelValue to ensure that formatters re-run
36455 // FIXME: Refactor when PR is merged: https://github.com/angular/angular.js/pull/10764
36456 if (newDateFormat !== dateFormat) {
36457 dateFormat = newDateFormat;
36458 ngModel.$modelValue = null;
36461 throw new Error('uibDatepickerPopup must have a date format specified.');
36468 throw new Error('uibDatepickerPopup must have a date format specified.');
36471 if (isHtml5DateInput && attrs.uibDatepickerPopup) {
36472 throw new Error('HTML5 date input types do not support custom formats.');
36475 // popup element used to display calendar
36476 popupEl = angular.element('<div uib-datepicker-popup-wrap><div uib-datepicker></div></div>');
36477 scope.ngModelOptions = angular.copy(ngModelOptions);
36478 scope.ngModelOptions.timezone = null;
36480 'ng-model': 'date',
36481 'ng-model-options': 'ngModelOptions',
36482 'ng-change': 'dateSelection(date)',
36483 'template-url': datepickerPopupTemplateUrl
36486 // datepicker element
36487 datepickerEl = angular.element(popupEl.children()[0]);
36488 datepickerEl.attr('template-url', datepickerTemplateUrl);
36490 if (isHtml5DateInput) {
36491 if (attrs.type === 'month') {
36492 datepickerEl.attr('datepicker-mode', '"month"');
36493 datepickerEl.attr('min-mode', 'month');
36497 if (attrs.datepickerOptions) {
36498 var options = scope.$parent.$eval(attrs.datepickerOptions);
36499 if (options && options.initDate) {
36500 scope.initDate = dateParser.fromTimezone(options.initDate, ngModelOptions.timezone);
36501 datepickerEl.attr('init-date', 'initDate');
36502 delete options.initDate;
36504 angular.forEach(options, function(value, option) {
36505 datepickerEl.attr(cameltoDash(option), value);
36509 angular.forEach(['minMode', 'maxMode'], function(key) {
36511 scope.$parent.$watch(function() { return attrs[key]; }, function(value) {
36512 scope.watchData[key] = value;
36514 datepickerEl.attr(cameltoDash(key), 'watchData.' + key);
36518 angular.forEach(['datepickerMode', 'shortcutPropagation'], function(key) {
36520 var getAttribute = $parse(attrs[key]);
36523 return getAttribute(scope.$parent);
36527 datepickerEl.attr(cameltoDash(key), 'watchData.' + key);
36529 // Propagate changes from datepicker to outside
36530 if (key === 'datepickerMode') {
36531 var setAttribute = getAttribute.assign;
36532 propConfig.set = function(v) {
36533 setAttribute(scope.$parent, v);
36537 Object.defineProperty(scope.watchData, key, propConfig);
36541 angular.forEach(['minDate', 'maxDate', 'initDate'], function(key) {
36543 var getAttribute = $parse(attrs[key]);
36545 scope.$parent.$watch(getAttribute, function(value) {
36546 if (key === 'minDate' || key === 'maxDate') {
36547 cache[key] = angular.isDate(value) ? dateParser.fromTimezone(new Date(value), ngModelOptions.timezone) : new Date(dateFilter(value, 'medium'));
36550 scope.watchData[key] = cache[key] || dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
36553 datepickerEl.attr(cameltoDash(key), 'watchData.' + key);
36557 if (attrs.dateDisabled) {
36558 datepickerEl.attr('date-disabled', 'dateDisabled({ date: date, mode: mode })');
36561 angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle', 'showWeeks', 'startingDay', 'yearRows', 'yearColumns'], function(key) {
36562 if (angular.isDefined(attrs[key])) {
36563 datepickerEl.attr(cameltoDash(key), attrs[key]);
36567 if (attrs.customClass) {
36568 datepickerEl.attr('custom-class', 'customClass({ date: date, mode: mode })');
36571 if (!isHtml5DateInput) {
36572 // Internal API to maintain the correct ng-invalid-[key] class
36573 ngModel.$$parserName = 'date';
36574 ngModel.$validators.date = validator;
36575 ngModel.$parsers.unshift(parseDate);
36576 ngModel.$formatters.push(function(value) {
36577 if (ngModel.$isEmpty(value)) {
36578 scope.date = value;
36581 scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);
36582 return dateFilter(scope.date, dateFormat);
36585 ngModel.$formatters.push(function(value) {
36586 scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);
36591 // Detect changes in the view from the text box
36592 ngModel.$viewChangeListeners.push(function() {
36593 scope.date = parseDateString(ngModel.$viewValue);
36596 element.bind('keydown', inputKeydownBind);
36598 $popup = $compile(popupEl)(scope);
36599 // Prevent jQuery cache memory leak (template is now redundant after linking)
36602 if (appendToBody) {
36603 $document.find('body').append($popup);
36605 element.after($popup);
36608 scope.$on('$destroy', function() {
36609 if (scope.isOpen === true) {
36610 if (!$rootScope.$$phase) {
36611 scope.$apply(function() {
36612 scope.isOpen = false;
36618 element.unbind('keydown', inputKeydownBind);
36619 $document.unbind('click', documentClickBind);
36623 scope.getText = function(key) {
36624 return scope[key + 'Text'] || datepickerPopupConfig[key + 'Text'];
36627 scope.isDisabled = function(date) {
36628 if (date === 'today') {
36632 return scope.watchData.minDate && scope.compare(date, cache.minDate) < 0 ||
36633 scope.watchData.maxDate && scope.compare(date, cache.maxDate) > 0;
36636 scope.compare = function(date1, date2) {
36637 return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()) - new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
36641 scope.dateSelection = function(dt) {
36642 if (angular.isDefined(dt)) {
36645 var date = scope.date ? dateFilter(scope.date, dateFormat) : null; // Setting to NULL is necessary for form validators to function
36647 ngModel.$setViewValue(date);
36649 if (closeOnDateSelection) {
36650 scope.isOpen = false;
36651 element[0].focus();
36655 scope.keydown = function(evt) {
36656 if (evt.which === 27) {
36657 evt.stopPropagation();
36658 scope.isOpen = false;
36659 element[0].focus();
36663 scope.select = function(date) {
36664 if (date === 'today') {
36665 var today = new Date();
36666 if (angular.isDate(scope.date)) {
36667 date = new Date(scope.date);
36668 date.setFullYear(today.getFullYear(), today.getMonth(), today.getDate());
36670 date = new Date(today.setHours(0, 0, 0, 0));
36673 scope.dateSelection(date);
36676 scope.close = function() {
36677 scope.isOpen = false;
36678 element[0].focus();
36681 scope.disabled = angular.isDefined(attrs.disabled) || false;
36682 if (attrs.ngDisabled) {
36683 scope.$parent.$watch($parse(attrs.ngDisabled), function(disabled) {
36684 scope.disabled = disabled;
36688 scope.$watch('isOpen', function(value) {
36690 if (!scope.disabled) {
36691 scope.position = appendToBody ? $position.offset(element) : $position.position(element);
36692 scope.position.top = scope.position.top + element.prop('offsetHeight');
36694 $timeout(function() {
36696 scope.$broadcast('uib:datepicker.focus');
36698 $document.bind('click', documentClickBind);
36701 scope.isOpen = false;
36704 $document.unbind('click', documentClickBind);
36708 function cameltoDash(string) {
36709 return string.replace(/([A-Z])/g, function($1) { return '-' + $1.toLowerCase(); });
36712 function parseDateString(viewValue) {
36713 var date = dateParser.parse(viewValue, dateFormat, scope.date);
36715 for (var i = 0; i < altInputFormats.length; i++) {
36716 date = dateParser.parse(viewValue, altInputFormats[i], scope.date);
36717 if (!isNaN(date)) {
36725 function parseDate(viewValue) {
36726 if (angular.isNumber(viewValue)) {
36727 // presumably timestamp to date object
36728 viewValue = new Date(viewValue);
36735 if (angular.isDate(viewValue) && !isNaN(viewValue)) {
36739 if (angular.isString(viewValue)) {
36740 var date = parseDateString(viewValue);
36741 if (!isNaN(date)) {
36742 return dateParser.toTimezone(date, ngModelOptions.timezone);
36746 return ngModel.$options && ngModel.$options.allowInvalid ? viewValue : undefined;
36749 function validator(modelValue, viewValue) {
36750 var value = modelValue || viewValue;
36752 if (!attrs.ngRequired && !value) {
36756 if (angular.isNumber(value)) {
36757 value = new Date(value);
36764 if (angular.isDate(value) && !isNaN(value)) {
36768 if (angular.isString(value)) {
36769 return !isNaN(parseDateString(viewValue));
36775 function documentClickBind(event) {
36776 if (!scope.isOpen && scope.disabled) {
36780 var popup = $popup[0];
36781 var dpContainsTarget = element[0].contains(event.target);
36782 // The popup node may not be an element node
36783 // In some browsers (IE) only element nodes have the 'contains' function
36784 var popupContainsTarget = popup.contains !== undefined && popup.contains(event.target);
36785 if (scope.isOpen && !(dpContainsTarget || popupContainsTarget)) {
36786 scope.$apply(function() {
36787 scope.isOpen = false;
36792 function inputKeydownBind(evt) {
36793 if (evt.which === 27 && scope.isOpen) {
36794 evt.preventDefault();
36795 evt.stopPropagation();
36796 scope.$apply(function() {
36797 scope.isOpen = false;
36799 element[0].focus();
36800 } else if (evt.which === 40 && !scope.isOpen) {
36801 evt.preventDefault();
36802 evt.stopPropagation();
36803 scope.$apply(function() {
36804 scope.isOpen = true;
36810 .directive('uibDatepickerPopup', function() {
36812 require: ['ngModel', 'uibDatepickerPopup'],
36813 controller: 'UibDatepickerPopupController',
36822 link: function(scope, element, attrs, ctrls) {
36823 var ngModel = ctrls[0],
36826 ctrl.init(ngModel);
36831 .directive('uibDatepickerPopupWrap', function() {
36835 templateUrl: function(element, attrs) {
36836 return attrs.templateUrl || 'uib/template/datepicker/popup.html';
36841 angular.module('ui.bootstrap.debounce', [])
36843 * A helper, internal service that debounces a function
36845 .factory('$$debounce', ['$timeout', function($timeout) {
36846 return function(callback, debounceTime) {
36847 var timeoutPromise;
36849 return function() {
36851 var args = Array.prototype.slice.call(arguments);
36852 if (timeoutPromise) {
36853 $timeout.cancel(timeoutPromise);
36856 timeoutPromise = $timeout(function() {
36857 callback.apply(self, args);
36863 angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position'])
36865 .constant('uibDropdownConfig', {
36866 appendToOpenClass: 'uib-dropdown-open',
36870 .service('uibDropdownService', ['$document', '$rootScope', function($document, $rootScope) {
36871 var openScope = null;
36873 this.open = function(dropdownScope) {
36875 $document.on('click', closeDropdown);
36876 $document.on('keydown', keybindFilter);
36879 if (openScope && openScope !== dropdownScope) {
36880 openScope.isOpen = false;
36883 openScope = dropdownScope;
36886 this.close = function(dropdownScope) {
36887 if (openScope === dropdownScope) {
36889 $document.off('click', closeDropdown);
36890 $document.off('keydown', keybindFilter);
36894 var closeDropdown = function(evt) {
36895 // This method may still be called during the same mouse event that
36896 // unbound this event handler. So check openScope before proceeding.
36897 if (!openScope) { return; }
36899 if (evt && openScope.getAutoClose() === 'disabled') { return; }
36901 if (evt && evt.which === 3) { return; }
36903 var toggleElement = openScope.getToggleElement();
36904 if (evt && toggleElement && toggleElement[0].contains(evt.target)) {
36908 var dropdownElement = openScope.getDropdownElement();
36909 if (evt && openScope.getAutoClose() === 'outsideClick' &&
36910 dropdownElement && dropdownElement[0].contains(evt.target)) {
36914 openScope.isOpen = false;
36916 if (!$rootScope.$$phase) {
36917 openScope.$apply();
36921 var keybindFilter = function(evt) {
36922 if (evt.which === 27) {
36923 openScope.focusToggleElement();
36925 } else if (openScope.isKeynavEnabled() && [38, 40].indexOf(evt.which) !== -1 && openScope.isOpen) {
36926 evt.preventDefault();
36927 evt.stopPropagation();
36928 openScope.focusDropdownEntry(evt.which);
36933 .controller('UibDropdownController', ['$scope', '$element', '$attrs', '$parse', 'uibDropdownConfig', 'uibDropdownService', '$animate', '$uibPosition', '$document', '$compile', '$templateRequest', function($scope, $element, $attrs, $parse, dropdownConfig, uibDropdownService, $animate, $position, $document, $compile, $templateRequest) {
36935 scope = $scope.$new(), // create a child scope so we are not polluting original one
36937 appendToOpenClass = dropdownConfig.appendToOpenClass,
36938 openClass = dropdownConfig.openClass,
36940 setIsOpen = angular.noop,
36941 toggleInvoker = $attrs.onToggle ? $parse($attrs.onToggle) : angular.noop,
36942 appendToBody = false,
36944 keynavEnabled = false,
36945 selectedOption = null,
36946 body = $document.find('body');
36948 $element.addClass('dropdown');
36950 this.init = function() {
36951 if ($attrs.isOpen) {
36952 getIsOpen = $parse($attrs.isOpen);
36953 setIsOpen = getIsOpen.assign;
36955 $scope.$watch(getIsOpen, function(value) {
36956 scope.isOpen = !!value;
36960 if (angular.isDefined($attrs.dropdownAppendTo)) {
36961 var appendToEl = $parse($attrs.dropdownAppendTo)(scope);
36963 appendTo = angular.element(appendToEl);
36967 appendToBody = angular.isDefined($attrs.dropdownAppendToBody);
36968 keynavEnabled = angular.isDefined($attrs.keyboardNav);
36970 if (appendToBody && !appendTo) {
36974 if (appendTo && self.dropdownMenu) {
36975 appendTo.append(self.dropdownMenu);
36976 $element.on('$destroy', function handleDestroyEvent() {
36977 self.dropdownMenu.remove();
36982 this.toggle = function(open) {
36983 return scope.isOpen = arguments.length ? !!open : !scope.isOpen;
36986 // Allow other directives to watch status
36987 this.isOpen = function() {
36988 return scope.isOpen;
36991 scope.getToggleElement = function() {
36992 return self.toggleElement;
36995 scope.getAutoClose = function() {
36996 return $attrs.autoClose || 'always'; //or 'outsideClick' or 'disabled'
36999 scope.getElement = function() {
37003 scope.isKeynavEnabled = function() {
37004 return keynavEnabled;
37007 scope.focusDropdownEntry = function(keyCode) {
37008 var elems = self.dropdownMenu ? //If append to body is used.
37009 angular.element(self.dropdownMenu).find('a') :
37010 $element.find('ul').eq(0).find('a');
37014 if (!angular.isNumber(self.selectedOption)) {
37015 self.selectedOption = 0;
37017 self.selectedOption = self.selectedOption === elems.length - 1 ?
37018 self.selectedOption :
37019 self.selectedOption + 1;
37024 if (!angular.isNumber(self.selectedOption)) {
37025 self.selectedOption = elems.length - 1;
37027 self.selectedOption = self.selectedOption === 0 ?
37028 0 : self.selectedOption - 1;
37033 elems[self.selectedOption].focus();
37036 scope.getDropdownElement = function() {
37037 return self.dropdownMenu;
37040 scope.focusToggleElement = function() {
37041 if (self.toggleElement) {
37042 self.toggleElement[0].focus();
37046 scope.$watch('isOpen', function(isOpen, wasOpen) {
37047 if (appendTo && self.dropdownMenu) {
37048 var pos = $position.positionElements($element, self.dropdownMenu, 'bottom-left', true),
37053 top: pos.top + 'px',
37054 display: isOpen ? 'block' : 'none'
37057 rightalign = self.dropdownMenu.hasClass('dropdown-menu-right');
37059 css.left = pos.left + 'px';
37060 css.right = 'auto';
37063 css.right = window.innerWidth -
37064 (pos.left + $element.prop('offsetWidth')) + 'px';
37067 // Need to adjust our positioning to be relative to the appendTo container
37068 // if it's not the body element
37069 if (!appendToBody) {
37070 var appendOffset = $position.offset(appendTo);
37072 css.top = pos.top - appendOffset.top + 'px';
37075 css.left = pos.left - appendOffset.left + 'px';
37077 css.right = window.innerWidth -
37078 (pos.left - appendOffset.left + $element.prop('offsetWidth')) + 'px';
37082 self.dropdownMenu.css(css);
37085 var openContainer = appendTo ? appendTo : $element;
37087 $animate[isOpen ? 'addClass' : 'removeClass'](openContainer, appendTo ? appendToOpenClass : openClass).then(function() {
37088 if (angular.isDefined(isOpen) && isOpen !== wasOpen) {
37089 toggleInvoker($scope, { open: !!isOpen });
37094 if (self.dropdownMenuTemplateUrl) {
37095 $templateRequest(self.dropdownMenuTemplateUrl).then(function(tplContent) {
37096 templateScope = scope.$new();
37097 $compile(tplContent.trim())(templateScope, function(dropdownElement) {
37098 var newEl = dropdownElement;
37099 self.dropdownMenu.replaceWith(newEl);
37100 self.dropdownMenu = newEl;
37105 scope.focusToggleElement();
37106 uibDropdownService.open(scope);
37108 if (self.dropdownMenuTemplateUrl) {
37109 if (templateScope) {
37110 templateScope.$destroy();
37112 var newEl = angular.element('<ul class="dropdown-menu"></ul>');
37113 self.dropdownMenu.replaceWith(newEl);
37114 self.dropdownMenu = newEl;
37117 uibDropdownService.close(scope);
37118 self.selectedOption = null;
37121 if (angular.isFunction(setIsOpen)) {
37122 setIsOpen($scope, isOpen);
37126 $scope.$on('$locationChangeSuccess', function() {
37127 if (scope.getAutoClose() !== 'disabled') {
37128 scope.isOpen = false;
37133 .directive('uibDropdown', function() {
37135 controller: 'UibDropdownController',
37136 link: function(scope, element, attrs, dropdownCtrl) {
37137 dropdownCtrl.init();
37142 .directive('uibDropdownMenu', function() {
37145 require: '?^uibDropdown',
37146 link: function(scope, element, attrs, dropdownCtrl) {
37147 if (!dropdownCtrl || angular.isDefined(attrs.dropdownNested)) {
37151 element.addClass('dropdown-menu');
37153 var tplUrl = attrs.templateUrl;
37155 dropdownCtrl.dropdownMenuTemplateUrl = tplUrl;
37158 if (!dropdownCtrl.dropdownMenu) {
37159 dropdownCtrl.dropdownMenu = element;
37165 .directive('uibDropdownToggle', function() {
37167 require: '?^uibDropdown',
37168 link: function(scope, element, attrs, dropdownCtrl) {
37169 if (!dropdownCtrl) {
37173 element.addClass('dropdown-toggle');
37175 dropdownCtrl.toggleElement = element;
37177 var toggleDropdown = function(event) {
37178 event.preventDefault();
37180 if (!element.hasClass('disabled') && !attrs.disabled) {
37181 scope.$apply(function() {
37182 dropdownCtrl.toggle();
37187 element.bind('click', toggleDropdown);
37190 element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
37191 scope.$watch(dropdownCtrl.isOpen, function(isOpen) {
37192 element.attr('aria-expanded', !!isOpen);
37195 scope.$on('$destroy', function() {
37196 element.unbind('click', toggleDropdown);
37202 angular.module('ui.bootstrap.stackedMap', [])
37204 * A helper, internal data structure that acts as a map but also allows getting / removing
37205 * elements in the LIFO order
37207 .factory('$$stackedMap', function() {
37209 createNew: function() {
37213 add: function(key, value) {
37219 get: function(key) {
37220 for (var i = 0; i < stack.length; i++) {
37221 if (key === stack[i].key) {
37228 for (var i = 0; i < stack.length; i++) {
37229 keys.push(stack[i].key);
37234 return stack[stack.length - 1];
37236 remove: function(key) {
37238 for (var i = 0; i < stack.length; i++) {
37239 if (key === stack[i].key) {
37244 return stack.splice(idx, 1)[0];
37246 removeTop: function() {
37247 return stack.splice(stack.length - 1, 1)[0];
37249 length: function() {
37250 return stack.length;
37256 angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
37258 * A helper, internal data structure that stores all references attached to key
37260 .factory('$$multiMap', function() {
37262 createNew: function() {
37266 entries: function() {
37267 return Object.keys(map).map(function(key) {
37274 get: function(key) {
37277 hasKey: function(key) {
37281 return Object.keys(map);
37283 put: function(key, value) {
37288 map[key].push(value);
37290 remove: function(key, value) {
37291 var values = map[key];
37297 var idx = values.indexOf(value);
37300 values.splice(idx, 1);
37303 if (!values.length) {
37313 * Pluggable resolve mechanism for the modal resolve resolution
37314 * Supports UI Router's $resolve service
37316 .provider('$uibResolve', function() {
37317 var resolve = this;
37318 this.resolver = null;
37320 this.setResolver = function(resolver) {
37321 this.resolver = resolver;
37324 this.$get = ['$injector', '$q', function($injector, $q) {
37325 var resolver = resolve.resolver ? $injector.get(resolve.resolver) : null;
37327 resolve: function(invocables, locals, parent, self) {
37329 return resolver.resolve(invocables, locals, parent, self);
37334 angular.forEach(invocables, function(value) {
37335 if (angular.isFunction(value) || angular.isArray(value)) {
37336 promises.push($q.resolve($injector.invoke(value)));
37337 } else if (angular.isString(value)) {
37338 promises.push($q.resolve($injector.get(value)));
37340 promises.push($q.resolve(value));
37344 return $q.all(promises).then(function(resolves) {
37345 var resolveObj = {};
37346 var resolveIter = 0;
37347 angular.forEach(invocables, function(value, key) {
37348 resolveObj[key] = resolves[resolveIter++];
37359 * A helper directive for the $modal service. It creates a backdrop element.
37361 .directive('uibModalBackdrop', ['$animateCss', '$injector', '$uibModalStack',
37362 function($animateCss, $injector, $modalStack) {
37365 templateUrl: 'uib/template/modal/backdrop.html',
37366 compile: function(tElement, tAttrs) {
37367 tElement.addClass(tAttrs.backdropClass);
37372 function linkFn(scope, element, attrs) {
37373 if (attrs.modalInClass) {
37374 $animateCss(element, {
37375 addClass: attrs.modalInClass
37378 scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
37379 var done = setIsAsync();
37380 if (scope.modalOptions.animation) {
37381 $animateCss(element, {
37382 removeClass: attrs.modalInClass
37383 }).start().then(done);
37392 .directive('uibModalWindow', ['$uibModalStack', '$q', '$animate', '$animateCss', '$document',
37393 function($modalStack, $q, $animate, $animateCss, $document) {
37400 templateUrl: function(tElement, tAttrs) {
37401 return tAttrs.templateUrl || 'uib/template/modal/window.html';
37403 link: function(scope, element, attrs) {
37404 element.addClass(attrs.windowClass || '');
37405 element.addClass(attrs.windowTopClass || '');
37406 scope.size = attrs.size;
37408 scope.close = function(evt) {
37409 var modal = $modalStack.getTop();
37410 if (modal && modal.value.backdrop &&
37411 modal.value.backdrop !== 'static' &&
37412 evt.target === evt.currentTarget) {
37413 evt.preventDefault();
37414 evt.stopPropagation();
37415 $modalStack.dismiss(modal.key, 'backdrop click');
37419 // moved from template to fix issue #2280
37420 element.on('click', scope.close);
37422 // This property is only added to the scope for the purpose of detecting when this directive is rendered.
37423 // We can detect that by using this property in the template associated with this directive and then use
37424 // {@link Attribute#$observe} on it. For more details please see {@link TableColumnResize}.
37425 scope.$isRendered = true;
37427 // Deferred object that will be resolved when this modal is render.
37428 var modalRenderDeferObj = $q.defer();
37429 // Observe function will be called on next digest cycle after compilation, ensuring that the DOM is ready.
37430 // In order to use this way of finding whether DOM is ready, we need to observe a scope property used in modal's template.
37431 attrs.$observe('modalRender', function(value) {
37432 if (value === 'true') {
37433 modalRenderDeferObj.resolve();
37437 modalRenderDeferObj.promise.then(function() {
37438 var animationPromise = null;
37440 if (attrs.modalInClass) {
37441 animationPromise = $animateCss(element, {
37442 addClass: attrs.modalInClass
37445 scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
37446 var done = setIsAsync();
37448 $animateCss(element, {
37449 removeClass: attrs.modalInClass
37450 }).start().then(done);
37452 $animate.removeClass(element, attrs.modalInClass).then(done);
37458 $q.when(animationPromise).then(function() {
37460 * If something within the freshly-opened modal already has focus (perhaps via a
37461 * directive that causes focus). then no need to try and focus anything.
37463 if (!($document[0].activeElement && element[0].contains($document[0].activeElement))) {
37464 var inputWithAutofocus = element[0].querySelector('[autofocus]');
37466 * Auto-focusing of a freshly-opened modal element causes any child elements
37467 * with the autofocus attribute to lose focus. This is an issue on touch
37468 * based devices which will show and then hide the onscreen keyboard.
37469 * Attempts to refocus the autofocus element via JavaScript will not reopen
37470 * the onscreen keyboard. Fixed by updated the focusing logic to only autofocus
37471 * the modal element if the modal does not contain an autofocus element.
37473 if (inputWithAutofocus) {
37474 inputWithAutofocus.focus();
37476 element[0].focus();
37481 // Notify {@link $modalStack} that modal is rendered.
37482 var modal = $modalStack.getTop();
37484 $modalStack.modalRendered(modal.key);
37491 .directive('uibModalAnimationClass', function() {
37493 compile: function(tElement, tAttrs) {
37494 if (tAttrs.modalAnimation) {
37495 tElement.addClass(tAttrs.uibModalAnimationClass);
37501 .directive('uibModalTransclude', function() {
37503 link: function(scope, element, attrs, controller, transclude) {
37504 transclude(scope.$parent, function(clone) {
37506 element.append(clone);
37512 .factory('$uibModalStack', ['$animate', '$animateCss', '$document',
37513 '$compile', '$rootScope', '$q', '$$multiMap', '$$stackedMap',
37514 function($animate, $animateCss, $document, $compile, $rootScope, $q, $$multiMap, $$stackedMap) {
37515 var OPENED_MODAL_CLASS = 'modal-open';
37517 var backdropDomEl, backdropScope;
37518 var openedWindows = $$stackedMap.createNew();
37519 var openedClasses = $$multiMap.createNew();
37520 var $modalStack = {
37521 NOW_CLOSING_EVENT: 'modal.stack.now-closing'
37524 //Modal focus behavior
37525 var focusableElementList;
37526 var focusIndex = 0;
37527 var tababbleSelector = 'a[href], area[href], input:not([disabled]), ' +
37528 'button:not([disabled]),select:not([disabled]), textarea:not([disabled]), ' +
37529 'iframe, object, embed, *[tabindex], *[contenteditable=true]';
37531 function backdropIndex() {
37532 var topBackdropIndex = -1;
37533 var opened = openedWindows.keys();
37534 for (var i = 0; i < opened.length; i++) {
37535 if (openedWindows.get(opened[i]).value.backdrop) {
37536 topBackdropIndex = i;
37539 return topBackdropIndex;
37542 $rootScope.$watch(backdropIndex, function(newBackdropIndex) {
37543 if (backdropScope) {
37544 backdropScope.index = newBackdropIndex;
37548 function removeModalWindow(modalInstance, elementToReceiveFocus) {
37549 var modalWindow = openedWindows.get(modalInstance).value;
37550 var appendToElement = modalWindow.appendTo;
37552 //clean up the stack
37553 openedWindows.remove(modalInstance);
37555 removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, function() {
37556 var modalBodyClass = modalWindow.openedClass || OPENED_MODAL_CLASS;
37557 openedClasses.remove(modalBodyClass, modalInstance);
37558 appendToElement.toggleClass(modalBodyClass, openedClasses.hasKey(modalBodyClass));
37559 toggleTopWindowClass(true);
37561 checkRemoveBackdrop();
37563 //move focus to specified element if available, or else to body
37564 if (elementToReceiveFocus && elementToReceiveFocus.focus) {
37565 elementToReceiveFocus.focus();
37566 } else if (appendToElement.focus) {
37567 appendToElement.focus();
37571 // Add or remove "windowTopClass" from the top window in the stack
37572 function toggleTopWindowClass(toggleSwitch) {
37575 if (openedWindows.length() > 0) {
37576 modalWindow = openedWindows.top().value;
37577 modalWindow.modalDomEl.toggleClass(modalWindow.windowTopClass || '', toggleSwitch);
37581 function checkRemoveBackdrop() {
37582 //remove backdrop if no longer needed
37583 if (backdropDomEl && backdropIndex() === -1) {
37584 var backdropScopeRef = backdropScope;
37585 removeAfterAnimate(backdropDomEl, backdropScope, function() {
37586 backdropScopeRef = null;
37588 backdropDomEl = undefined;
37589 backdropScope = undefined;
37593 function removeAfterAnimate(domEl, scope, done, closedDeferred) {
37595 var asyncPromise = null;
37596 var setIsAsync = function() {
37597 if (!asyncDeferred) {
37598 asyncDeferred = $q.defer();
37599 asyncPromise = asyncDeferred.promise;
37602 return function asyncDone() {
37603 asyncDeferred.resolve();
37606 scope.$broadcast($modalStack.NOW_CLOSING_EVENT, setIsAsync);
37608 // Note that it's intentional that asyncPromise might be null.
37609 // That's when setIsAsync has not been called during the
37610 // NOW_CLOSING_EVENT broadcast.
37611 return $q.when(asyncPromise).then(afterAnimating);
37613 function afterAnimating() {
37614 if (afterAnimating.done) {
37617 afterAnimating.done = true;
37619 $animateCss(domEl, {
37621 }).start().then(function() {
37623 if (closedDeferred) {
37624 closedDeferred.resolve();
37635 $document.on('keydown', keydownListener);
37637 $rootScope.$on('$destroy', function() {
37638 $document.off('keydown', keydownListener);
37641 function keydownListener(evt) {
37642 if (evt.isDefaultPrevented()) {
37646 var modal = openedWindows.top();
37648 switch (evt.which) {
37650 if (modal.value.keyboard) {
37651 evt.preventDefault();
37652 $rootScope.$apply(function() {
37653 $modalStack.dismiss(modal.key, 'escape key press');
37659 $modalStack.loadFocusElementList(modal);
37660 var focusChanged = false;
37661 if (evt.shiftKey) {
37662 if ($modalStack.isFocusInFirstItem(evt)) {
37663 focusChanged = $modalStack.focusLastFocusableElement();
37666 if ($modalStack.isFocusInLastItem(evt)) {
37667 focusChanged = $modalStack.focusFirstFocusableElement();
37671 if (focusChanged) {
37672 evt.preventDefault();
37673 evt.stopPropagation();
37681 $modalStack.open = function(modalInstance, modal) {
37682 var modalOpener = $document[0].activeElement,
37683 modalBodyClass = modal.openedClass || OPENED_MODAL_CLASS;
37685 toggleTopWindowClass(false);
37687 openedWindows.add(modalInstance, {
37688 deferred: modal.deferred,
37689 renderDeferred: modal.renderDeferred,
37690 closedDeferred: modal.closedDeferred,
37691 modalScope: modal.scope,
37692 backdrop: modal.backdrop,
37693 keyboard: modal.keyboard,
37694 openedClass: modal.openedClass,
37695 windowTopClass: modal.windowTopClass,
37696 animation: modal.animation,
37697 appendTo: modal.appendTo
37700 openedClasses.put(modalBodyClass, modalInstance);
37702 var appendToElement = modal.appendTo,
37703 currBackdropIndex = backdropIndex();
37705 if (!appendToElement.length) {
37706 throw new Error('appendTo element not found. Make sure that the element passed is in DOM.');
37709 if (currBackdropIndex >= 0 && !backdropDomEl) {
37710 backdropScope = $rootScope.$new(true);
37711 backdropScope.modalOptions = modal;
37712 backdropScope.index = currBackdropIndex;
37713 backdropDomEl = angular.element('<div uib-modal-backdrop="modal-backdrop"></div>');
37714 backdropDomEl.attr('backdrop-class', modal.backdropClass);
37715 if (modal.animation) {
37716 backdropDomEl.attr('modal-animation', 'true');
37718 $compile(backdropDomEl)(backdropScope);
37719 $animate.enter(backdropDomEl, appendToElement);
37722 var angularDomEl = angular.element('<div uib-modal-window="modal-window"></div>');
37723 angularDomEl.attr({
37724 'template-url': modal.windowTemplateUrl,
37725 'window-class': modal.windowClass,
37726 'window-top-class': modal.windowTopClass,
37727 'size': modal.size,
37728 'index': openedWindows.length() - 1,
37729 'animate': 'animate'
37730 }).html(modal.content);
37731 if (modal.animation) {
37732 angularDomEl.attr('modal-animation', 'true');
37735 $animate.enter(angularDomEl, appendToElement)
37737 $compile(angularDomEl)(modal.scope);
37738 $animate.addClass(appendToElement, modalBodyClass);
37741 openedWindows.top().value.modalDomEl = angularDomEl;
37742 openedWindows.top().value.modalOpener = modalOpener;
37744 $modalStack.clearFocusListCache();
37747 function broadcastClosing(modalWindow, resultOrReason, closing) {
37748 return !modalWindow.value.modalScope.$broadcast('modal.closing', resultOrReason, closing).defaultPrevented;
37751 $modalStack.close = function(modalInstance, result) {
37752 var modalWindow = openedWindows.get(modalInstance);
37753 if (modalWindow && broadcastClosing(modalWindow, result, true)) {
37754 modalWindow.value.modalScope.$$uibDestructionScheduled = true;
37755 modalWindow.value.deferred.resolve(result);
37756 removeModalWindow(modalInstance, modalWindow.value.modalOpener);
37759 return !modalWindow;
37762 $modalStack.dismiss = function(modalInstance, reason) {
37763 var modalWindow = openedWindows.get(modalInstance);
37764 if (modalWindow && broadcastClosing(modalWindow, reason, false)) {
37765 modalWindow.value.modalScope.$$uibDestructionScheduled = true;
37766 modalWindow.value.deferred.reject(reason);
37767 removeModalWindow(modalInstance, modalWindow.value.modalOpener);
37770 return !modalWindow;
37773 $modalStack.dismissAll = function(reason) {
37774 var topModal = this.getTop();
37775 while (topModal && this.dismiss(topModal.key, reason)) {
37776 topModal = this.getTop();
37780 $modalStack.getTop = function() {
37781 return openedWindows.top();
37784 $modalStack.modalRendered = function(modalInstance) {
37785 var modalWindow = openedWindows.get(modalInstance);
37787 modalWindow.value.renderDeferred.resolve();
37791 $modalStack.focusFirstFocusableElement = function() {
37792 if (focusableElementList.length > 0) {
37793 focusableElementList[0].focus();
37798 $modalStack.focusLastFocusableElement = function() {
37799 if (focusableElementList.length > 0) {
37800 focusableElementList[focusableElementList.length - 1].focus();
37806 $modalStack.isFocusInFirstItem = function(evt) {
37807 if (focusableElementList.length > 0) {
37808 return (evt.target || evt.srcElement) === focusableElementList[0];
37813 $modalStack.isFocusInLastItem = function(evt) {
37814 if (focusableElementList.length > 0) {
37815 return (evt.target || evt.srcElement) === focusableElementList[focusableElementList.length - 1];
37820 $modalStack.clearFocusListCache = function() {
37821 focusableElementList = [];
37825 $modalStack.loadFocusElementList = function(modalWindow) {
37826 if (focusableElementList === undefined || !focusableElementList.length) {
37828 var modalDomE1 = modalWindow.value.modalDomEl;
37829 if (modalDomE1 && modalDomE1.length) {
37830 focusableElementList = modalDomE1[0].querySelectorAll(tababbleSelector);
37836 return $modalStack;
37839 .provider('$uibModal', function() {
37840 var $modalProvider = {
37843 backdrop: true, //can also be false or 'static'
37846 $get: ['$rootScope', '$q', '$document', '$templateRequest', '$controller', '$uibResolve', '$uibModalStack',
37847 function ($rootScope, $q, $document, $templateRequest, $controller, $uibResolve, $modalStack) {
37850 function getTemplatePromise(options) {
37851 return options.template ? $q.when(options.template) :
37852 $templateRequest(angular.isFunction(options.templateUrl) ?
37853 options.templateUrl() : options.templateUrl);
37856 var promiseChain = null;
37857 $modal.getPromiseChain = function() {
37858 return promiseChain;
37861 $modal.open = function(modalOptions) {
37862 var modalResultDeferred = $q.defer();
37863 var modalOpenedDeferred = $q.defer();
37864 var modalClosedDeferred = $q.defer();
37865 var modalRenderDeferred = $q.defer();
37867 //prepare an instance of a modal to be injected into controllers and returned to a caller
37868 var modalInstance = {
37869 result: modalResultDeferred.promise,
37870 opened: modalOpenedDeferred.promise,
37871 closed: modalClosedDeferred.promise,
37872 rendered: modalRenderDeferred.promise,
37873 close: function (result) {
37874 return $modalStack.close(modalInstance, result);
37876 dismiss: function (reason) {
37877 return $modalStack.dismiss(modalInstance, reason);
37881 //merge and clean up options
37882 modalOptions = angular.extend({}, $modalProvider.options, modalOptions);
37883 modalOptions.resolve = modalOptions.resolve || {};
37884 modalOptions.appendTo = modalOptions.appendTo || $document.find('body').eq(0);
37887 if (!modalOptions.template && !modalOptions.templateUrl) {
37888 throw new Error('One of template or templateUrl options is required.');
37891 var templateAndResolvePromise =
37892 $q.all([getTemplatePromise(modalOptions), $uibResolve.resolve(modalOptions.resolve, {}, null, null)]);
37894 function resolveWithTemplate() {
37895 return templateAndResolvePromise;
37898 // Wait for the resolution of the existing promise chain.
37899 // Then switch to our own combined promise dependency (regardless of how the previous modal fared).
37900 // Then add to $modalStack and resolve opened.
37901 // Finally clean up the chain variable if no subsequent modal has overwritten it.
37903 samePromise = promiseChain = $q.all([promiseChain])
37904 .then(resolveWithTemplate, resolveWithTemplate)
37905 .then(function resolveSuccess(tplAndVars) {
37906 var providedScope = modalOptions.scope || $rootScope;
37908 var modalScope = providedScope.$new();
37909 modalScope.$close = modalInstance.close;
37910 modalScope.$dismiss = modalInstance.dismiss;
37912 modalScope.$on('$destroy', function() {
37913 if (!modalScope.$$uibDestructionScheduled) {
37914 modalScope.$dismiss('$uibUnscheduledDestruction');
37918 var ctrlInstance, ctrlLocals = {};
37921 if (modalOptions.controller) {
37922 ctrlLocals.$scope = modalScope;
37923 ctrlLocals.$uibModalInstance = modalInstance;
37924 angular.forEach(tplAndVars[1], function(value, key) {
37925 ctrlLocals[key] = value;
37928 ctrlInstance = $controller(modalOptions.controller, ctrlLocals);
37929 if (modalOptions.controllerAs) {
37930 if (modalOptions.bindToController) {
37931 ctrlInstance.$close = modalScope.$close;
37932 ctrlInstance.$dismiss = modalScope.$dismiss;
37933 angular.extend(ctrlInstance, providedScope);
37936 modalScope[modalOptions.controllerAs] = ctrlInstance;
37940 $modalStack.open(modalInstance, {
37942 deferred: modalResultDeferred,
37943 renderDeferred: modalRenderDeferred,
37944 closedDeferred: modalClosedDeferred,
37945 content: tplAndVars[0],
37946 animation: modalOptions.animation,
37947 backdrop: modalOptions.backdrop,
37948 keyboard: modalOptions.keyboard,
37949 backdropClass: modalOptions.backdropClass,
37950 windowTopClass: modalOptions.windowTopClass,
37951 windowClass: modalOptions.windowClass,
37952 windowTemplateUrl: modalOptions.windowTemplateUrl,
37953 size: modalOptions.size,
37954 openedClass: modalOptions.openedClass,
37955 appendTo: modalOptions.appendTo
37957 modalOpenedDeferred.resolve(true);
37959 }, function resolveError(reason) {
37960 modalOpenedDeferred.reject(reason);
37961 modalResultDeferred.reject(reason);
37962 })['finally'](function() {
37963 if (promiseChain === samePromise) {
37964 promiseChain = null;
37968 return modalInstance;
37976 return $modalProvider;
37979 angular.module('ui.bootstrap.paging', [])
37981 * Helper internal service for generating common controller code between the
37982 * pager and pagination components
37984 .factory('uibPaging', ['$parse', function($parse) {
37986 create: function(ctrl, $scope, $attrs) {
37987 ctrl.setNumPages = $attrs.numPages ? $parse($attrs.numPages).assign : angular.noop;
37988 ctrl.ngModelCtrl = { $setViewValue: angular.noop }; // nullModelCtrl
37990 ctrl.init = function(ngModelCtrl, config) {
37991 ctrl.ngModelCtrl = ngModelCtrl;
37992 ctrl.config = config;
37994 ngModelCtrl.$render = function() {
37998 if ($attrs.itemsPerPage) {
37999 $scope.$parent.$watch($parse($attrs.itemsPerPage), function(value) {
38000 ctrl.itemsPerPage = parseInt(value, 10);
38001 $scope.totalPages = ctrl.calculateTotalPages();
38005 ctrl.itemsPerPage = config.itemsPerPage;
38008 $scope.$watch('totalItems', function(newTotal, oldTotal) {
38009 if (angular.isDefined(newTotal) || newTotal !== oldTotal) {
38010 $scope.totalPages = ctrl.calculateTotalPages();
38016 ctrl.calculateTotalPages = function() {
38017 var totalPages = ctrl.itemsPerPage < 1 ? 1 : Math.ceil($scope.totalItems / ctrl.itemsPerPage);
38018 return Math.max(totalPages || 0, 1);
38021 ctrl.render = function() {
38022 $scope.page = parseInt(ctrl.ngModelCtrl.$viewValue, 10) || 1;
38025 $scope.selectPage = function(page, evt) {
38027 evt.preventDefault();
38030 var clickAllowed = !$scope.ngDisabled || !evt;
38031 if (clickAllowed && $scope.page !== page && page > 0 && page <= $scope.totalPages) {
38032 if (evt && evt.target) {
38035 ctrl.ngModelCtrl.$setViewValue(page);
38036 ctrl.ngModelCtrl.$render();
38040 $scope.getText = function(key) {
38041 return $scope[key + 'Text'] || ctrl.config[key + 'Text'];
38044 $scope.noPrevious = function() {
38045 return $scope.page === 1;
38048 $scope.noNext = function() {
38049 return $scope.page === $scope.totalPages;
38052 ctrl.updatePage = function() {
38053 ctrl.setNumPages($scope.$parent, $scope.totalPages); // Readonly variable
38055 if ($scope.page > $scope.totalPages) {
38056 $scope.selectPage($scope.totalPages);
38058 ctrl.ngModelCtrl.$render();
38065 angular.module('ui.bootstrap.pager', ['ui.bootstrap.paging'])
38067 .controller('UibPagerController', ['$scope', '$attrs', 'uibPaging', 'uibPagerConfig', function($scope, $attrs, uibPaging, uibPagerConfig) {
38068 $scope.align = angular.isDefined($attrs.align) ? $scope.$parent.$eval($attrs.align) : uibPagerConfig.align;
38070 uibPaging.create(this, $scope, $attrs);
38073 .constant('uibPagerConfig', {
38075 previousText: '« Previous',
38076 nextText: 'Next »',
38080 .directive('uibPager', ['uibPagerConfig', function(uibPagerConfig) {
38088 require: ['uibPager', '?ngModel'],
38089 controller: 'UibPagerController',
38090 controllerAs: 'pager',
38091 templateUrl: function(element, attrs) {
38092 return attrs.templateUrl || 'uib/template/pager/pager.html';
38095 link: function(scope, element, attrs, ctrls) {
38096 var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
38098 if (!ngModelCtrl) {
38099 return; // do nothing if no ng-model
38102 paginationCtrl.init(ngModelCtrl, uibPagerConfig);
38107 angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging'])
38108 .controller('UibPaginationController', ['$scope', '$attrs', '$parse', 'uibPaging', 'uibPaginationConfig', function($scope, $attrs, $parse, uibPaging, uibPaginationConfig) {
38110 // Setup configuration parameters
38111 var maxSize = angular.isDefined($attrs.maxSize) ? $scope.$parent.$eval($attrs.maxSize) : uibPaginationConfig.maxSize,
38112 rotate = angular.isDefined($attrs.rotate) ? $scope.$parent.$eval($attrs.rotate) : uibPaginationConfig.rotate,
38113 forceEllipses = angular.isDefined($attrs.forceEllipses) ? $scope.$parent.$eval($attrs.forceEllipses) : uibPaginationConfig.forceEllipses,
38114 boundaryLinkNumbers = angular.isDefined($attrs.boundaryLinkNumbers) ? $scope.$parent.$eval($attrs.boundaryLinkNumbers) : uibPaginationConfig.boundaryLinkNumbers;
38115 $scope.boundaryLinks = angular.isDefined($attrs.boundaryLinks) ? $scope.$parent.$eval($attrs.boundaryLinks) : uibPaginationConfig.boundaryLinks;
38116 $scope.directionLinks = angular.isDefined($attrs.directionLinks) ? $scope.$parent.$eval($attrs.directionLinks) : uibPaginationConfig.directionLinks;
38118 uibPaging.create(this, $scope, $attrs);
38120 if ($attrs.maxSize) {
38121 $scope.$parent.$watch($parse($attrs.maxSize), function(value) {
38122 maxSize = parseInt(value, 10);
38127 // Create page object used in template
38128 function makePage(number, text, isActive) {
38136 function getPages(currentPage, totalPages) {
38139 // Default page limits
38140 var startPage = 1, endPage = totalPages;
38141 var isMaxSized = angular.isDefined(maxSize) && maxSize < totalPages;
38143 // recompute if maxSize
38146 // Current page is displayed in the middle of the visible ones
38147 startPage = Math.max(currentPage - Math.floor(maxSize / 2), 1);
38148 endPage = startPage + maxSize - 1;
38150 // Adjust if limit is exceeded
38151 if (endPage > totalPages) {
38152 endPage = totalPages;
38153 startPage = endPage - maxSize + 1;
38156 // Visible pages are paginated with maxSize
38157 startPage = (Math.ceil(currentPage / maxSize) - 1) * maxSize + 1;
38159 // Adjust last page if limit is exceeded
38160 endPage = Math.min(startPage + maxSize - 1, totalPages);
38164 // Add page number links
38165 for (var number = startPage; number <= endPage; number++) {
38166 var page = makePage(number, number, number === currentPage);
38170 // Add links to move between page sets
38171 if (isMaxSized && maxSize > 0 && (!rotate || forceEllipses || boundaryLinkNumbers)) {
38172 if (startPage > 1) {
38173 if (!boundaryLinkNumbers || startPage > 3) { //need ellipsis for all options unless range is too close to beginning
38174 var previousPageSet = makePage(startPage - 1, '...', false);
38175 pages.unshift(previousPageSet);
38177 if (boundaryLinkNumbers) {
38178 if (startPage === 3) { //need to replace ellipsis when the buttons would be sequential
38179 var secondPageLink = makePage(2, '2', false);
38180 pages.unshift(secondPageLink);
38182 //add the first page
38183 var firstPageLink = makePage(1, '1', false);
38184 pages.unshift(firstPageLink);
38188 if (endPage < totalPages) {
38189 if (!boundaryLinkNumbers || endPage < totalPages - 2) { //need ellipsis for all options unless range is too close to end
38190 var nextPageSet = makePage(endPage + 1, '...', false);
38191 pages.push(nextPageSet);
38193 if (boundaryLinkNumbers) {
38194 if (endPage === totalPages - 2) { //need to replace ellipsis when the buttons would be sequential
38195 var secondToLastPageLink = makePage(totalPages - 1, totalPages - 1, false);
38196 pages.push(secondToLastPageLink);
38198 //add the last page
38199 var lastPageLink = makePage(totalPages, totalPages, false);
38200 pages.push(lastPageLink);
38207 var originalRender = this.render;
38208 this.render = function() {
38210 if ($scope.page > 0 && $scope.page <= $scope.totalPages) {
38211 $scope.pages = getPages($scope.page, $scope.totalPages);
38216 .constant('uibPaginationConfig', {
38218 boundaryLinks: false,
38219 boundaryLinkNumbers: false,
38220 directionLinks: true,
38221 firstText: 'First',
38222 previousText: 'Previous',
38226 forceEllipses: false
38229 .directive('uibPagination', ['$parse', 'uibPaginationConfig', function($parse, uibPaginationConfig) {
38239 require: ['uibPagination', '?ngModel'],
38240 controller: 'UibPaginationController',
38241 controllerAs: 'pagination',
38242 templateUrl: function(element, attrs) {
38243 return attrs.templateUrl || 'uib/template/pagination/pagination.html';
38246 link: function(scope, element, attrs, ctrls) {
38247 var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
38249 if (!ngModelCtrl) {
38250 return; // do nothing if no ng-model
38253 paginationCtrl.init(ngModelCtrl, uibPaginationConfig);
38259 * The following features are still outstanding: animation as a
38260 * function, placement as a function, inside, support for more triggers than
38261 * just mouse enter/leave, html tooltips, and selector delegation.
38263 angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.stackedMap'])
38266 * The $tooltip service creates tooltip- and popover-like directives as well as
38267 * houses global options for them.
38269 .provider('$uibTooltip', function() {
38270 // The default options tooltip and popover.
38271 var defaultOptions = {
38273 placementClassPrefix: '',
38276 popupCloseDelay: 0,
38277 useContentExp: false
38280 // Default hide triggers for each show trigger
38282 'mouseenter': 'mouseleave',
38284 'outsideClick': 'outsideClick',
38289 // The options specified to the provider globally.
38290 var globalOptions = {};
38293 * `options({})` allows global configuration of all tooltips in the
38296 * var app = angular.module( 'App', ['ui.bootstrap.tooltip'], function( $tooltipProvider ) {
38297 * // place tooltips left instead of top by default
38298 * $tooltipProvider.options( { placement: 'left' } );
38301 this.options = function(value) {
38302 angular.extend(globalOptions, value);
38306 * This allows you to extend the set of trigger mappings available. E.g.:
38308 * $tooltipProvider.setTriggers( 'openTrigger': 'closeTrigger' );
38310 this.setTriggers = function setTriggers(triggers) {
38311 angular.extend(triggerMap, triggers);
38315 * This is a helper function for translating camel-case to snake_case.
38317 function snake_case(name) {
38318 var regexp = /[A-Z]/g;
38319 var separator = '-';
38320 return name.replace(regexp, function(letter, pos) {
38321 return (pos ? separator : '') + letter.toLowerCase();
38326 * Returns the actual instance of the $tooltip service.
38327 * TODO support multiple triggers
38329 this.$get = ['$window', '$compile', '$timeout', '$document', '$uibPosition', '$interpolate', '$rootScope', '$parse', '$$stackedMap', function($window, $compile, $timeout, $document, $position, $interpolate, $rootScope, $parse, $$stackedMap) {
38330 var openedTooltips = $$stackedMap.createNew();
38331 $document.on('keypress', keypressListener);
38333 $rootScope.$on('$destroy', function() {
38334 $document.off('keypress', keypressListener);
38337 function keypressListener(e) {
38338 if (e.which === 27) {
38339 var last = openedTooltips.top();
38341 last.value.close();
38342 openedTooltips.removeTop();
38348 return function $tooltip(ttType, prefix, defaultTriggerShow, options) {
38349 options = angular.extend({}, defaultOptions, globalOptions, options);
38352 * Returns an object of show and hide triggers.
38354 * If a trigger is supplied,
38355 * it is used to show the tooltip; otherwise, it will use the `trigger`
38356 * option passed to the `$tooltipProvider.options` method; else it will
38357 * default to the trigger supplied to this directive factory.
38359 * The hide trigger is based on the show trigger. If the `trigger` option
38360 * was passed to the `$tooltipProvider.options` method, it will use the
38361 * mapped trigger from `triggerMap` or the passed trigger if the map is
38362 * undefined; otherwise, it uses the `triggerMap` value of the show
38363 * trigger; else it will just use the show trigger.
38365 function getTriggers(trigger) {
38366 var show = (trigger || options.trigger || defaultTriggerShow).split(' ');
38367 var hide = show.map(function(trigger) {
38368 return triggerMap[trigger] || trigger;
38376 var directiveName = snake_case(ttType);
38378 var startSym = $interpolate.startSymbol();
38379 var endSym = $interpolate.endSymbol();
38381 '<div '+ directiveName + '-popup '+
38382 'title="' + startSym + 'title' + endSym + '" '+
38383 (options.useContentExp ?
38384 'content-exp="contentExp()" ' :
38385 'content="' + startSym + 'content' + endSym + '" ') +
38386 'placement="' + startSym + 'placement' + endSym + '" '+
38387 'popup-class="' + startSym + 'popupClass' + endSym + '" '+
38388 'animation="animation" ' +
38389 'is-open="isOpen"' +
38390 'origin-scope="origScope" ' +
38391 'style="visibility: hidden; display: block; top: -9999px; left: -9999px;"' +
38396 compile: function(tElem, tAttrs) {
38397 var tooltipLinker = $compile(template);
38399 return function link(scope, element, attrs, tooltipCtrl) {
38401 var tooltipLinkedScope;
38402 var transitionTimeout;
38405 var positionTimeout;
38406 var appendToBody = angular.isDefined(options.appendToBody) ? options.appendToBody : false;
38407 var triggers = getTriggers(undefined);
38408 var hasEnableExp = angular.isDefined(attrs[prefix + 'Enable']);
38409 var ttScope = scope.$new(true);
38410 var repositionScheduled = false;
38411 var isOpenParse = angular.isDefined(attrs[prefix + 'IsOpen']) ? $parse(attrs[prefix + 'IsOpen']) : false;
38412 var contentParse = options.useContentExp ? $parse(attrs[ttType]) : false;
38413 var observers = [];
38415 var positionTooltip = function() {
38416 // check if tooltip exists and is not empty
38417 if (!tooltip || !tooltip.html()) { return; }
38419 if (!positionTimeout) {
38420 positionTimeout = $timeout(function() {
38421 // Reset the positioning.
38422 tooltip.css({ top: 0, left: 0 });
38424 // Now set the calculated positioning.
38425 var ttPosition = $position.positionElements(element, tooltip, ttScope.placement, appendToBody);
38426 tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px', visibility: 'visible' });
38428 // If the placement class is prefixed, still need
38429 // to remove the TWBS standard class.
38430 if (options.placementClassPrefix) {
38431 tooltip.removeClass('top bottom left right');
38434 tooltip.removeClass(
38435 options.placementClassPrefix + 'top ' +
38436 options.placementClassPrefix + 'top-left ' +
38437 options.placementClassPrefix + 'top-right ' +
38438 options.placementClassPrefix + 'bottom ' +
38439 options.placementClassPrefix + 'bottom-left ' +
38440 options.placementClassPrefix + 'bottom-right ' +
38441 options.placementClassPrefix + 'left ' +
38442 options.placementClassPrefix + 'left-top ' +
38443 options.placementClassPrefix + 'left-bottom ' +
38444 options.placementClassPrefix + 'right ' +
38445 options.placementClassPrefix + 'right-top ' +
38446 options.placementClassPrefix + 'right-bottom');
38448 var placement = ttPosition.placement.split('-');
38449 tooltip.addClass(placement[0], options.placementClassPrefix + ttPosition.placement);
38450 $position.positionArrow(tooltip, ttPosition.placement);
38452 positionTimeout = null;
38457 // Set up the correct scope to allow transclusion later
38458 ttScope.origScope = scope;
38460 // By default, the tooltip is not open.
38461 // TODO add ability to start tooltip opened
38462 ttScope.isOpen = false;
38463 openedTooltips.add(ttScope, {
38467 function toggleTooltipBind() {
38468 if (!ttScope.isOpen) {
38475 // Show the tooltip with delay if specified, otherwise show it immediately
38476 function showTooltipBind() {
38477 if (hasEnableExp && !scope.$eval(attrs[prefix + 'Enable'])) {
38484 if (ttScope.popupDelay) {
38485 // Do nothing if the tooltip was already scheduled to pop-up.
38486 // This happens if show is triggered multiple times before any hide is triggered.
38487 if (!showTimeout) {
38488 showTimeout = $timeout(show, ttScope.popupDelay, false);
38495 function hideTooltipBind() {
38498 if (ttScope.popupCloseDelay) {
38499 if (!hideTimeout) {
38500 hideTimeout = $timeout(hide, ttScope.popupCloseDelay, false);
38507 // Show the tooltip popup element.
38512 // Don't show empty tooltips.
38513 if (!ttScope.content) {
38514 return angular.noop;
38519 // And show the tooltip.
38520 ttScope.$evalAsync(function() {
38521 ttScope.isOpen = true;
38522 assignIsOpen(true);
38527 function cancelShow() {
38529 $timeout.cancel(showTimeout);
38530 showTimeout = null;
38533 if (positionTimeout) {
38534 $timeout.cancel(positionTimeout);
38535 positionTimeout = null;
38539 // Hide the tooltip popup element.
38545 // First things first: we don't show it anymore.
38546 ttScope.$evalAsync(function() {
38547 ttScope.isOpen = false;
38548 assignIsOpen(false);
38549 // And now we remove it from the DOM. However, if we have animation, we
38550 // need to wait for it to expire beforehand.
38551 // FIXME: this is a placeholder for a port of the transitions library.
38552 // The fade transition in TWBS is 150ms.
38553 if (ttScope.animation) {
38554 if (!transitionTimeout) {
38555 transitionTimeout = $timeout(removeTooltip, 150, false);
38563 function cancelHide() {
38565 $timeout.cancel(hideTimeout);
38566 hideTimeout = null;
38568 if (transitionTimeout) {
38569 $timeout.cancel(transitionTimeout);
38570 transitionTimeout = null;
38574 function createTooltip() {
38575 // There can only be one tooltip element per directive shown at once.
38580 tooltipLinkedScope = ttScope.$new();
38581 tooltip = tooltipLinker(tooltipLinkedScope, function(tooltip) {
38582 if (appendToBody) {
38583 $document.find('body').append(tooltip);
38585 element.after(tooltip);
38592 function removeTooltip() {
38595 unregisterObservers();
38601 if (tooltipLinkedScope) {
38602 tooltipLinkedScope.$destroy();
38603 tooltipLinkedScope = null;
38608 * Set the initial scope values. Once
38609 * the tooltip is created, the observers
38610 * will be added to keep things in sync.
38612 function prepareTooltip() {
38613 ttScope.title = attrs[prefix + 'Title'];
38614 if (contentParse) {
38615 ttScope.content = contentParse(scope);
38617 ttScope.content = attrs[ttType];
38620 ttScope.popupClass = attrs[prefix + 'Class'];
38621 ttScope.placement = angular.isDefined(attrs[prefix + 'Placement']) ? attrs[prefix + 'Placement'] : options.placement;
38623 var delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
38624 var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
38625 ttScope.popupDelay = !isNaN(delay) ? delay : options.popupDelay;
38626 ttScope.popupCloseDelay = !isNaN(closeDelay) ? closeDelay : options.popupCloseDelay;
38629 function assignIsOpen(isOpen) {
38630 if (isOpenParse && angular.isFunction(isOpenParse.assign)) {
38631 isOpenParse.assign(scope, isOpen);
38635 ttScope.contentExp = function() {
38636 return ttScope.content;
38640 * Observe the relevant attributes.
38642 attrs.$observe('disabled', function(val) {
38647 if (val && ttScope.isOpen) {
38653 scope.$watch(isOpenParse, function(val) {
38654 if (ttScope && !val === ttScope.isOpen) {
38655 toggleTooltipBind();
38660 function prepObservers() {
38661 observers.length = 0;
38663 if (contentParse) {
38665 scope.$watch(contentParse, function(val) {
38666 ttScope.content = val;
38667 if (!val && ttScope.isOpen) {
38674 tooltipLinkedScope.$watch(function() {
38675 if (!repositionScheduled) {
38676 repositionScheduled = true;
38677 tooltipLinkedScope.$$postDigest(function() {
38678 repositionScheduled = false;
38679 if (ttScope && ttScope.isOpen) {
38688 attrs.$observe(ttType, function(val) {
38689 ttScope.content = val;
38690 if (!val && ttScope.isOpen) {
38700 attrs.$observe(prefix + 'Title', function(val) {
38701 ttScope.title = val;
38702 if (ttScope.isOpen) {
38709 attrs.$observe(prefix + 'Placement', function(val) {
38710 ttScope.placement = val ? val : options.placement;
38711 if (ttScope.isOpen) {
38718 function unregisterObservers() {
38719 if (observers.length) {
38720 angular.forEach(observers, function(observer) {
38723 observers.length = 0;
38727 // hide tooltips/popovers for outsideClick trigger
38728 function bodyHideTooltipBind(e) {
38729 if (!ttScope || !ttScope.isOpen || !tooltip) {
38732 // make sure the tooltip/popover link or tool tooltip/popover itself were not clicked
38733 if (!element[0].contains(e.target) && !tooltip[0].contains(e.target)) {
38738 var unregisterTriggers = function() {
38739 triggers.show.forEach(function(trigger) {
38740 if (trigger === 'outsideClick') {
38741 element.off('click', toggleTooltipBind);
38743 element.off(trigger, showTooltipBind);
38744 element.off(trigger, toggleTooltipBind);
38747 triggers.hide.forEach(function(trigger) {
38748 if (trigger === 'outsideClick') {
38749 $document.off('click', bodyHideTooltipBind);
38751 element.off(trigger, hideTooltipBind);
38756 function prepTriggers() {
38757 var val = attrs[prefix + 'Trigger'];
38758 unregisterTriggers();
38760 triggers = getTriggers(val);
38762 if (triggers.show !== 'none') {
38763 triggers.show.forEach(function(trigger, idx) {
38764 if (trigger === 'outsideClick') {
38765 element.on('click', toggleTooltipBind);
38766 $document.on('click', bodyHideTooltipBind);
38767 } else if (trigger === triggers.hide[idx]) {
38768 element.on(trigger, toggleTooltipBind);
38769 } else if (trigger) {
38770 element.on(trigger, showTooltipBind);
38771 element.on(triggers.hide[idx], hideTooltipBind);
38774 element.on('keypress', function(e) {
38775 if (e.which === 27) {
38785 var animation = scope.$eval(attrs[prefix + 'Animation']);
38786 ttScope.animation = angular.isDefined(animation) ? !!animation : options.animation;
38788 var appendToBodyVal;
38789 var appendKey = prefix + 'AppendToBody';
38790 if (appendKey in attrs && attrs[appendKey] === undefined) {
38791 appendToBodyVal = true;
38793 appendToBodyVal = scope.$eval(attrs[appendKey]);
38796 appendToBody = angular.isDefined(appendToBodyVal) ? appendToBodyVal : appendToBody;
38798 // if a tooltip is attached to <body> we need to remove it on
38799 // location change as its parent scope will probably not be destroyed
38801 if (appendToBody) {
38802 scope.$on('$locationChangeSuccess', function closeTooltipOnLocationChangeSuccess() {
38803 if (ttScope.isOpen) {
38809 // Make sure tooltip is destroyed and removed.
38810 scope.$on('$destroy', function onDestroyTooltip() {
38811 unregisterTriggers();
38813 openedTooltips.remove(ttScope);
38823 // This is mostly ngInclude code but with a custom scope
38824 .directive('uibTooltipTemplateTransclude', [
38825 '$animate', '$sce', '$compile', '$templateRequest',
38826 function ($animate, $sce, $compile, $templateRequest) {
38828 link: function(scope, elem, attrs) {
38829 var origScope = scope.$eval(attrs.tooltipTemplateTranscludeScope);
38831 var changeCounter = 0,
38836 var cleanupLastIncludeContent = function() {
38837 if (previousElement) {
38838 previousElement.remove();
38839 previousElement = null;
38842 if (currentScope) {
38843 currentScope.$destroy();
38844 currentScope = null;
38847 if (currentElement) {
38848 $animate.leave(currentElement).then(function() {
38849 previousElement = null;
38851 previousElement = currentElement;
38852 currentElement = null;
38856 scope.$watch($sce.parseAsResourceUrl(attrs.uibTooltipTemplateTransclude), function(src) {
38857 var thisChangeId = ++changeCounter;
38860 //set the 2nd param to true to ignore the template request error so that the inner
38861 //contents and scope can be cleaned up.
38862 $templateRequest(src, true).then(function(response) {
38863 if (thisChangeId !== changeCounter) { return; }
38864 var newScope = origScope.$new();
38865 var template = response;
38867 var clone = $compile(template)(newScope, function(clone) {
38868 cleanupLastIncludeContent();
38869 $animate.enter(clone, elem);
38872 currentScope = newScope;
38873 currentElement = clone;
38875 currentScope.$emit('$includeContentLoaded', src);
38877 if (thisChangeId === changeCounter) {
38878 cleanupLastIncludeContent();
38879 scope.$emit('$includeContentError', src);
38882 scope.$emit('$includeContentRequested', src);
38884 cleanupLastIncludeContent();
38888 scope.$on('$destroy', cleanupLastIncludeContent);
38894 * Note that it's intentional that these classes are *not* applied through $animate.
38895 * They must not be animated as they're expected to be present on the tooltip on
38898 .directive('uibTooltipClasses', ['$uibPosition', function($uibPosition) {
38901 link: function(scope, element, attrs) {
38902 // need to set the primary position so the
38903 // arrow has space during position measure.
38904 // tooltip.positionTooltip()
38905 if (scope.placement) {
38906 // // There are no top-left etc... classes
38907 // // in TWBS, so we need the primary position.
38908 var position = $uibPosition.parsePlacement(scope.placement);
38909 element.addClass(position[0]);
38911 element.addClass('top');
38914 if (scope.popupClass) {
38915 element.addClass(scope.popupClass);
38918 if (scope.animation()) {
38919 element.addClass(attrs.tooltipAnimationClass);
38925 .directive('uibTooltipPopup', function() {
38928 scope: { content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
38929 templateUrl: 'uib/template/tooltip/tooltip-popup.html'
38933 .directive('uibTooltip', [ '$uibTooltip', function($uibTooltip) {
38934 return $uibTooltip('uibTooltip', 'tooltip', 'mouseenter');
38937 .directive('uibTooltipTemplatePopup', function() {
38940 scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
38941 originScope: '&' },
38942 templateUrl: 'uib/template/tooltip/tooltip-template-popup.html'
38946 .directive('uibTooltipTemplate', ['$uibTooltip', function($uibTooltip) {
38947 return $uibTooltip('uibTooltipTemplate', 'tooltip', 'mouseenter', {
38948 useContentExp: true
38952 .directive('uibTooltipHtmlPopup', function() {
38955 scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
38956 templateUrl: 'uib/template/tooltip/tooltip-html-popup.html'
38960 .directive('uibTooltipHtml', ['$uibTooltip', function($uibTooltip) {
38961 return $uibTooltip('uibTooltipHtml', 'tooltip', 'mouseenter', {
38962 useContentExp: true
38967 * The following features are still outstanding: popup delay, animation as a
38968 * function, placement as a function, inside, support for more triggers than
38969 * just mouse enter/leave, and selector delegatation.
38971 angular.module('ui.bootstrap.popover', ['ui.bootstrap.tooltip'])
38973 .directive('uibPopoverTemplatePopup', function() {
38976 scope: { title: '@', contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
38977 originScope: '&' },
38978 templateUrl: 'uib/template/popover/popover-template.html'
38982 .directive('uibPopoverTemplate', ['$uibTooltip', function($uibTooltip) {
38983 return $uibTooltip('uibPopoverTemplate', 'popover', 'click', {
38984 useContentExp: true
38988 .directive('uibPopoverHtmlPopup', function() {
38991 scope: { contentExp: '&', title: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
38992 templateUrl: 'uib/template/popover/popover-html.html'
38996 .directive('uibPopoverHtml', ['$uibTooltip', function($uibTooltip) {
38997 return $uibTooltip('uibPopoverHtml', 'popover', 'click', {
38998 useContentExp: true
39002 .directive('uibPopoverPopup', function() {
39005 scope: { title: '@', content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
39006 templateUrl: 'uib/template/popover/popover.html'
39010 .directive('uibPopover', ['$uibTooltip', function($uibTooltip) {
39011 return $uibTooltip('uibPopover', 'popover', 'click');
39014 angular.module('ui.bootstrap.progressbar', [])
39016 .constant('uibProgressConfig', {
39021 .controller('UibProgressController', ['$scope', '$attrs', 'uibProgressConfig', function($scope, $attrs, progressConfig) {
39023 animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;
39026 $scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
39028 this.addBar = function(bar, element, attrs) {
39030 element.css({'transition': 'none'});
39033 this.bars.push(bar);
39035 bar.max = $scope.max;
39036 bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';
39038 bar.$watch('value', function(value) {
39039 bar.recalculatePercentage();
39042 bar.recalculatePercentage = function() {
39043 var totalPercentage = self.bars.reduce(function(total, bar) {
39044 bar.percent = +(100 * bar.value / bar.max).toFixed(2);
39045 return total + bar.percent;
39048 if (totalPercentage > 100) {
39049 bar.percent -= totalPercentage - 100;
39053 bar.$on('$destroy', function() {
39055 self.removeBar(bar);
39059 this.removeBar = function(bar) {
39060 this.bars.splice(this.bars.indexOf(bar), 1);
39061 this.bars.forEach(function (bar) {
39062 bar.recalculatePercentage();
39066 $scope.$watch('max', function(max) {
39067 self.bars.forEach(function(bar) {
39068 bar.max = $scope.max;
39069 bar.recalculatePercentage();
39074 .directive('uibProgress', function() {
39078 controller: 'UibProgressController',
39079 require: 'uibProgress',
39083 templateUrl: 'uib/template/progressbar/progress.html'
39087 .directive('uibBar', function() {
39091 require: '^uibProgress',
39096 templateUrl: 'uib/template/progressbar/bar.html',
39097 link: function(scope, element, attrs, progressCtrl) {
39098 progressCtrl.addBar(scope, element, attrs);
39103 .directive('uibProgressbar', function() {
39107 controller: 'UibProgressController',
39113 templateUrl: 'uib/template/progressbar/progressbar.html',
39114 link: function(scope, element, attrs, progressCtrl) {
39115 progressCtrl.addBar(scope, angular.element(element.children()[0]), {title: attrs.title});
39120 angular.module('ui.bootstrap.rating', [])
39122 .constant('uibRatingConfig', {
39126 titles : ['one', 'two', 'three', 'four', 'five']
39129 .controller('UibRatingController', ['$scope', '$attrs', 'uibRatingConfig', function($scope, $attrs, ratingConfig) {
39130 var ngModelCtrl = { $setViewValue: angular.noop };
39132 this.init = function(ngModelCtrl_) {
39133 ngModelCtrl = ngModelCtrl_;
39134 ngModelCtrl.$render = this.render;
39136 ngModelCtrl.$formatters.push(function(value) {
39137 if (angular.isNumber(value) && value << 0 !== value) {
39138 value = Math.round(value);
39144 this.stateOn = angular.isDefined($attrs.stateOn) ? $scope.$parent.$eval($attrs.stateOn) : ratingConfig.stateOn;
39145 this.stateOff = angular.isDefined($attrs.stateOff) ? $scope.$parent.$eval($attrs.stateOff) : ratingConfig.stateOff;
39146 var tmpTitles = angular.isDefined($attrs.titles) ? $scope.$parent.$eval($attrs.titles) : ratingConfig.titles ;
39147 this.titles = angular.isArray(tmpTitles) && tmpTitles.length > 0 ?
39148 tmpTitles : ratingConfig.titles;
39150 var ratingStates = angular.isDefined($attrs.ratingStates) ?
39151 $scope.$parent.$eval($attrs.ratingStates) :
39152 new Array(angular.isDefined($attrs.max) ? $scope.$parent.$eval($attrs.max) : ratingConfig.max);
39153 $scope.range = this.buildTemplateObjects(ratingStates);
39156 this.buildTemplateObjects = function(states) {
39157 for (var i = 0, n = states.length; i < n; i++) {
39158 states[i] = angular.extend({ index: i }, { stateOn: this.stateOn, stateOff: this.stateOff, title: this.getTitle(i) }, states[i]);
39163 this.getTitle = function(index) {
39164 if (index >= this.titles.length) {
39168 return this.titles[index];
39171 $scope.rate = function(value) {
39172 if (!$scope.readonly && value >= 0 && value <= $scope.range.length) {
39173 ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue === value ? 0 : value);
39174 ngModelCtrl.$render();
39178 $scope.enter = function(value) {
39179 if (!$scope.readonly) {
39180 $scope.value = value;
39182 $scope.onHover({value: value});
39185 $scope.reset = function() {
39186 $scope.value = ngModelCtrl.$viewValue;
39190 $scope.onKeydown = function(evt) {
39191 if (/(37|38|39|40)/.test(evt.which)) {
39192 evt.preventDefault();
39193 evt.stopPropagation();
39194 $scope.rate($scope.value + (evt.which === 38 || evt.which === 39 ? 1 : -1));
39198 this.render = function() {
39199 $scope.value = ngModelCtrl.$viewValue;
39203 .directive('uibRating', function() {
39205 require: ['uibRating', 'ngModel'],
39211 controller: 'UibRatingController',
39212 templateUrl: 'uib/template/rating/rating.html',
39214 link: function(scope, element, attrs, ctrls) {
39215 var ratingCtrl = ctrls[0], ngModelCtrl = ctrls[1];
39216 ratingCtrl.init(ngModelCtrl);
39221 angular.module('ui.bootstrap.tabs', [])
39223 .controller('UibTabsetController', ['$scope', function ($scope) {
39225 tabs = ctrl.tabs = $scope.tabs = [];
39227 ctrl.select = function(selectedTab) {
39228 angular.forEach(tabs, function(tab) {
39229 if (tab.active && tab !== selectedTab) {
39230 tab.active = false;
39232 selectedTab.selectCalled = false;
39235 selectedTab.active = true;
39236 // only call select if it has not already been called
39237 if (!selectedTab.selectCalled) {
39238 selectedTab.onSelect();
39239 selectedTab.selectCalled = true;
39243 ctrl.addTab = function addTab(tab) {
39245 // we can't run the select function on the first tab
39246 // since that would select it twice
39247 if (tabs.length === 1 && tab.active !== false) {
39249 } else if (tab.active) {
39252 tab.active = false;
39256 ctrl.removeTab = function removeTab(tab) {
39257 var index = tabs.indexOf(tab);
39258 //Select a new tab if the tab to be removed is selected and not destroyed
39259 if (tab.active && tabs.length > 1 && !destroyed) {
39260 //If this is the last tab, select the previous tab. else, the next tab.
39261 var newActiveIndex = index === tabs.length - 1 ? index - 1 : index + 1;
39262 ctrl.select(tabs[newActiveIndex]);
39264 tabs.splice(index, 1);
39268 $scope.$on('$destroy', function() {
39273 .directive('uibTabset', function() {
39280 controller: 'UibTabsetController',
39281 templateUrl: 'uib/template/tabs/tabset.html',
39282 link: function(scope, element, attrs) {
39283 scope.vertical = angular.isDefined(attrs.vertical) ? scope.$parent.$eval(attrs.vertical) : false;
39284 scope.justified = angular.isDefined(attrs.justified) ? scope.$parent.$eval(attrs.justified) : false;
39289 .directive('uibTab', ['$parse', function($parse) {
39291 require: '^uibTabset',
39293 templateUrl: 'uib/template/tabs/tab.html',
39298 onSelect: '&select', //This callback is called in contentHeadingTransclude
39299 //once it inserts the tab's content into the dom
39300 onDeselect: '&deselect'
39302 controller: function() {
39303 //Empty controller so other directives can require being 'under' a tab
39305 controllerAs: 'tab',
39306 link: function(scope, elm, attrs, tabsetCtrl, transclude) {
39307 scope.$watch('active', function(active) {
39309 tabsetCtrl.select(scope);
39313 scope.disabled = false;
39314 if (attrs.disable) {
39315 scope.$parent.$watch($parse(attrs.disable), function(value) {
39316 scope.disabled = !! value;
39320 scope.select = function() {
39321 if (!scope.disabled) {
39322 scope.active = true;
39326 tabsetCtrl.addTab(scope);
39327 scope.$on('$destroy', function() {
39328 tabsetCtrl.removeTab(scope);
39331 //We need to transclude later, once the content container is ready.
39332 //when this link happens, we're inside a tab heading.
39333 scope.$transcludeFn = transclude;
39338 .directive('uibTabHeadingTransclude', function() {
39341 require: '^uibTab',
39342 link: function(scope, elm) {
39343 scope.$watch('headingElement', function updateHeadingElement(heading) {
39346 elm.append(heading);
39353 .directive('uibTabContentTransclude', function() {
39356 require: '^uibTabset',
39357 link: function(scope, elm, attrs) {
39358 var tab = scope.$eval(attrs.uibTabContentTransclude);
39360 //Now our tab is ready to be transcluded: both the tab heading area
39361 //and the tab content area are loaded. Transclude 'em both.
39362 tab.$transcludeFn(tab.$parent, function(contents) {
39363 angular.forEach(contents, function(node) {
39364 if (isTabHeading(node)) {
39365 //Let tabHeadingTransclude know.
39366 tab.headingElement = node;
39375 function isTabHeading(node) {
39376 return node.tagName && (
39377 node.hasAttribute('uib-tab-heading') ||
39378 node.hasAttribute('data-uib-tab-heading') ||
39379 node.hasAttribute('x-uib-tab-heading') ||
39380 node.tagName.toLowerCase() === 'uib-tab-heading' ||
39381 node.tagName.toLowerCase() === 'data-uib-tab-heading' ||
39382 node.tagName.toLowerCase() === 'x-uib-tab-heading'
39387 angular.module('ui.bootstrap.timepicker', [])
39389 .constant('uibTimepickerConfig', {
39393 showMeridian: true,
39394 showSeconds: false,
39396 readonlyInput: false,
39402 .controller('UibTimepickerController', ['$scope', '$element', '$attrs', '$parse', '$log', '$locale', 'uibTimepickerConfig', function($scope, $element, $attrs, $parse, $log, $locale, timepickerConfig) {
39403 var selected = new Date(),
39404 ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl
39405 meridians = angular.isDefined($attrs.meridians) ? $scope.$parent.$eval($attrs.meridians) : timepickerConfig.meridians || $locale.DATETIME_FORMATS.AMPMS;
39407 $scope.tabindex = angular.isDefined($attrs.tabindex) ? $attrs.tabindex : 0;
39408 $element.removeAttr('tabindex');
39410 this.init = function(ngModelCtrl_, inputs) {
39411 ngModelCtrl = ngModelCtrl_;
39412 ngModelCtrl.$render = this.render;
39414 ngModelCtrl.$formatters.unshift(function(modelValue) {
39415 return modelValue ? new Date(modelValue) : null;
39418 var hoursInputEl = inputs.eq(0),
39419 minutesInputEl = inputs.eq(1),
39420 secondsInputEl = inputs.eq(2);
39422 var mousewheel = angular.isDefined($attrs.mousewheel) ? $scope.$parent.$eval($attrs.mousewheel) : timepickerConfig.mousewheel;
39425 this.setupMousewheelEvents(hoursInputEl, minutesInputEl, secondsInputEl);
39428 var arrowkeys = angular.isDefined($attrs.arrowkeys) ? $scope.$parent.$eval($attrs.arrowkeys) : timepickerConfig.arrowkeys;
39430 this.setupArrowkeyEvents(hoursInputEl, minutesInputEl, secondsInputEl);
39433 $scope.readonlyInput = angular.isDefined($attrs.readonlyInput) ? $scope.$parent.$eval($attrs.readonlyInput) : timepickerConfig.readonlyInput;
39434 this.setupInputEvents(hoursInputEl, minutesInputEl, secondsInputEl);
39437 var hourStep = timepickerConfig.hourStep;
39438 if ($attrs.hourStep) {
39439 $scope.$parent.$watch($parse($attrs.hourStep), function(value) {
39440 hourStep = parseInt(value, 10);
39444 var minuteStep = timepickerConfig.minuteStep;
39445 if ($attrs.minuteStep) {
39446 $scope.$parent.$watch($parse($attrs.minuteStep), function(value) {
39447 minuteStep = parseInt(value, 10);
39452 $scope.$parent.$watch($parse($attrs.min), function(value) {
39453 var dt = new Date(value);
39454 min = isNaN(dt) ? undefined : dt;
39458 $scope.$parent.$watch($parse($attrs.max), function(value) {
39459 var dt = new Date(value);
39460 max = isNaN(dt) ? undefined : dt;
39463 var disabled = false;
39464 if ($attrs.ngDisabled) {
39465 $scope.$parent.$watch($parse($attrs.ngDisabled), function(value) {
39470 $scope.noIncrementHours = function() {
39471 var incrementedSelected = addMinutes(selected, hourStep * 60);
39472 return disabled || incrementedSelected > max ||
39473 incrementedSelected < selected && incrementedSelected < min;
39476 $scope.noDecrementHours = function() {
39477 var decrementedSelected = addMinutes(selected, -hourStep * 60);
39478 return disabled || decrementedSelected < min ||
39479 decrementedSelected > selected && decrementedSelected > max;
39482 $scope.noIncrementMinutes = function() {
39483 var incrementedSelected = addMinutes(selected, minuteStep);
39484 return disabled || incrementedSelected > max ||
39485 incrementedSelected < selected && incrementedSelected < min;
39488 $scope.noDecrementMinutes = function() {
39489 var decrementedSelected = addMinutes(selected, -minuteStep);
39490 return disabled || decrementedSelected < min ||
39491 decrementedSelected > selected && decrementedSelected > max;
39494 $scope.noIncrementSeconds = function() {
39495 var incrementedSelected = addSeconds(selected, secondStep);
39496 return disabled || incrementedSelected > max ||
39497 incrementedSelected < selected && incrementedSelected < min;
39500 $scope.noDecrementSeconds = function() {
39501 var decrementedSelected = addSeconds(selected, -secondStep);
39502 return disabled || decrementedSelected < min ||
39503 decrementedSelected > selected && decrementedSelected > max;
39506 $scope.noToggleMeridian = function() {
39507 if (selected.getHours() < 12) {
39508 return disabled || addMinutes(selected, 12 * 60) > max;
39511 return disabled || addMinutes(selected, -12 * 60) < min;
39514 var secondStep = timepickerConfig.secondStep;
39515 if ($attrs.secondStep) {
39516 $scope.$parent.$watch($parse($attrs.secondStep), function(value) {
39517 secondStep = parseInt(value, 10);
39521 $scope.showSeconds = timepickerConfig.showSeconds;
39522 if ($attrs.showSeconds) {
39523 $scope.$parent.$watch($parse($attrs.showSeconds), function(value) {
39524 $scope.showSeconds = !!value;
39529 $scope.showMeridian = timepickerConfig.showMeridian;
39530 if ($attrs.showMeridian) {
39531 $scope.$parent.$watch($parse($attrs.showMeridian), function(value) {
39532 $scope.showMeridian = !!value;
39534 if (ngModelCtrl.$error.time) {
39535 // Evaluate from template
39536 var hours = getHoursFromTemplate(), minutes = getMinutesFromTemplate();
39537 if (angular.isDefined(hours) && angular.isDefined(minutes)) {
39538 selected.setHours(hours);
39547 // Get $scope.hours in 24H mode if valid
39548 function getHoursFromTemplate() {
39549 var hours = parseInt($scope.hours, 10);
39550 var valid = $scope.showMeridian ? hours > 0 && hours < 13 :
39551 hours >= 0 && hours < 24;
39556 if ($scope.showMeridian) {
39557 if (hours === 12) {
39560 if ($scope.meridian === meridians[1]) {
39561 hours = hours + 12;
39567 function getMinutesFromTemplate() {
39568 var minutes = parseInt($scope.minutes, 10);
39569 return minutes >= 0 && minutes < 60 ? minutes : undefined;
39572 function getSecondsFromTemplate() {
39573 var seconds = parseInt($scope.seconds, 10);
39574 return seconds >= 0 && seconds < 60 ? seconds : undefined;
39577 function pad(value) {
39578 if (value === null) {
39582 return angular.isDefined(value) && value.toString().length < 2 ?
39583 '0' + value : value.toString();
39586 // Respond on mousewheel spin
39587 this.setupMousewheelEvents = function(hoursInputEl, minutesInputEl, secondsInputEl) {
39588 var isScrollingUp = function(e) {
39589 if (e.originalEvent) {
39590 e = e.originalEvent;
39592 //pick correct delta variable depending on event
39593 var delta = e.wheelDelta ? e.wheelDelta : -e.deltaY;
39594 return e.detail || delta > 0;
39597 hoursInputEl.bind('mousewheel wheel', function(e) {
39599 $scope.$apply(isScrollingUp(e) ? $scope.incrementHours() : $scope.decrementHours());
39601 e.preventDefault();
39604 minutesInputEl.bind('mousewheel wheel', function(e) {
39606 $scope.$apply(isScrollingUp(e) ? $scope.incrementMinutes() : $scope.decrementMinutes());
39608 e.preventDefault();
39611 secondsInputEl.bind('mousewheel wheel', function(e) {
39613 $scope.$apply(isScrollingUp(e) ? $scope.incrementSeconds() : $scope.decrementSeconds());
39615 e.preventDefault();
39619 // Respond on up/down arrowkeys
39620 this.setupArrowkeyEvents = function(hoursInputEl, minutesInputEl, secondsInputEl) {
39621 hoursInputEl.bind('keydown', function(e) {
39623 if (e.which === 38) { // up
39624 e.preventDefault();
39625 $scope.incrementHours();
39627 } else if (e.which === 40) { // down
39628 e.preventDefault();
39629 $scope.decrementHours();
39635 minutesInputEl.bind('keydown', function(e) {
39637 if (e.which === 38) { // up
39638 e.preventDefault();
39639 $scope.incrementMinutes();
39641 } else if (e.which === 40) { // down
39642 e.preventDefault();
39643 $scope.decrementMinutes();
39649 secondsInputEl.bind('keydown', function(e) {
39651 if (e.which === 38) { // up
39652 e.preventDefault();
39653 $scope.incrementSeconds();
39655 } else if (e.which === 40) { // down
39656 e.preventDefault();
39657 $scope.decrementSeconds();
39664 this.setupInputEvents = function(hoursInputEl, minutesInputEl, secondsInputEl) {
39665 if ($scope.readonlyInput) {
39666 $scope.updateHours = angular.noop;
39667 $scope.updateMinutes = angular.noop;
39668 $scope.updateSeconds = angular.noop;
39672 var invalidate = function(invalidHours, invalidMinutes, invalidSeconds) {
39673 ngModelCtrl.$setViewValue(null);
39674 ngModelCtrl.$setValidity('time', false);
39675 if (angular.isDefined(invalidHours)) {
39676 $scope.invalidHours = invalidHours;
39679 if (angular.isDefined(invalidMinutes)) {
39680 $scope.invalidMinutes = invalidMinutes;
39683 if (angular.isDefined(invalidSeconds)) {
39684 $scope.invalidSeconds = invalidSeconds;
39688 $scope.updateHours = function() {
39689 var hours = getHoursFromTemplate(),
39690 minutes = getMinutesFromTemplate();
39692 ngModelCtrl.$setDirty();
39694 if (angular.isDefined(hours) && angular.isDefined(minutes)) {
39695 selected.setHours(hours);
39696 selected.setMinutes(minutes);
39697 if (selected < min || selected > max) {
39707 hoursInputEl.bind('blur', function(e) {
39708 ngModelCtrl.$setTouched();
39709 if ($scope.hours === null || $scope.hours === '') {
39711 } else if (!$scope.invalidHours && $scope.hours < 10) {
39712 $scope.$apply(function() {
39713 $scope.hours = pad($scope.hours);
39718 $scope.updateMinutes = function() {
39719 var minutes = getMinutesFromTemplate(),
39720 hours = getHoursFromTemplate();
39722 ngModelCtrl.$setDirty();
39724 if (angular.isDefined(minutes) && angular.isDefined(hours)) {
39725 selected.setHours(hours);
39726 selected.setMinutes(minutes);
39727 if (selected < min || selected > max) {
39728 invalidate(undefined, true);
39733 invalidate(undefined, true);
39737 minutesInputEl.bind('blur', function(e) {
39738 ngModelCtrl.$setTouched();
39739 if ($scope.minutes === null) {
39740 invalidate(undefined, true);
39741 } else if (!$scope.invalidMinutes && $scope.minutes < 10) {
39742 $scope.$apply(function() {
39743 $scope.minutes = pad($scope.minutes);
39748 $scope.updateSeconds = function() {
39749 var seconds = getSecondsFromTemplate();
39751 ngModelCtrl.$setDirty();
39753 if (angular.isDefined(seconds)) {
39754 selected.setSeconds(seconds);
39757 invalidate(undefined, undefined, true);
39761 secondsInputEl.bind('blur', function(e) {
39762 if (!$scope.invalidSeconds && $scope.seconds < 10) {
39763 $scope.$apply( function() {
39764 $scope.seconds = pad($scope.seconds);
39771 this.render = function() {
39772 var date = ngModelCtrl.$viewValue;
39775 ngModelCtrl.$setValidity('time', false);
39776 $log.error('Timepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.');
39782 if (selected < min || selected > max) {
39783 ngModelCtrl.$setValidity('time', false);
39784 $scope.invalidHours = true;
39785 $scope.invalidMinutes = true;
39793 // Call internally when we know that model is valid.
39794 function refresh(keyboardChange) {
39796 ngModelCtrl.$setViewValue(new Date(selected));
39797 updateTemplate(keyboardChange);
39800 function makeValid() {
39801 ngModelCtrl.$setValidity('time', true);
39802 $scope.invalidHours = false;
39803 $scope.invalidMinutes = false;
39804 $scope.invalidSeconds = false;
39807 function updateTemplate(keyboardChange) {
39808 if (!ngModelCtrl.$modelValue) {
39809 $scope.hours = null;
39810 $scope.minutes = null;
39811 $scope.seconds = null;
39812 $scope.meridian = meridians[0];
39814 var hours = selected.getHours(),
39815 minutes = selected.getMinutes(),
39816 seconds = selected.getSeconds();
39818 if ($scope.showMeridian) {
39819 hours = hours === 0 || hours === 12 ? 12 : hours % 12; // Convert 24 to 12 hour system
39822 $scope.hours = keyboardChange === 'h' ? hours : pad(hours);
39823 if (keyboardChange !== 'm') {
39824 $scope.minutes = pad(minutes);
39826 $scope.meridian = selected.getHours() < 12 ? meridians[0] : meridians[1];
39828 if (keyboardChange !== 's') {
39829 $scope.seconds = pad(seconds);
39831 $scope.meridian = selected.getHours() < 12 ? meridians[0] : meridians[1];
39835 function addSecondsToSelected(seconds) {
39836 selected = addSeconds(selected, seconds);
39840 function addMinutes(selected, minutes) {
39841 return addSeconds(selected, minutes*60);
39844 function addSeconds(date, seconds) {
39845 var dt = new Date(date.getTime() + seconds * 1000);
39846 var newDate = new Date(date);
39847 newDate.setHours(dt.getHours(), dt.getMinutes(), dt.getSeconds());
39851 $scope.showSpinners = angular.isDefined($attrs.showSpinners) ?
39852 $scope.$parent.$eval($attrs.showSpinners) : timepickerConfig.showSpinners;
39854 $scope.incrementHours = function() {
39855 if (!$scope.noIncrementHours()) {
39856 addSecondsToSelected(hourStep * 60 * 60);
39860 $scope.decrementHours = function() {
39861 if (!$scope.noDecrementHours()) {
39862 addSecondsToSelected(-hourStep * 60 * 60);
39866 $scope.incrementMinutes = function() {
39867 if (!$scope.noIncrementMinutes()) {
39868 addSecondsToSelected(minuteStep * 60);
39872 $scope.decrementMinutes = function() {
39873 if (!$scope.noDecrementMinutes()) {
39874 addSecondsToSelected(-minuteStep * 60);
39878 $scope.incrementSeconds = function() {
39879 if (!$scope.noIncrementSeconds()) {
39880 addSecondsToSelected(secondStep);
39884 $scope.decrementSeconds = function() {
39885 if (!$scope.noDecrementSeconds()) {
39886 addSecondsToSelected(-secondStep);
39890 $scope.toggleMeridian = function() {
39891 var minutes = getMinutesFromTemplate(),
39892 hours = getHoursFromTemplate();
39894 if (!$scope.noToggleMeridian()) {
39895 if (angular.isDefined(minutes) && angular.isDefined(hours)) {
39896 addSecondsToSelected(12 * 60 * (selected.getHours() < 12 ? 60 : -60));
39898 $scope.meridian = $scope.meridian === meridians[0] ? meridians[1] : meridians[0];
39903 $scope.blur = function() {
39904 ngModelCtrl.$setTouched();
39908 .directive('uibTimepicker', function() {
39910 require: ['uibTimepicker', '?^ngModel'],
39911 controller: 'UibTimepickerController',
39912 controllerAs: 'timepicker',
39915 templateUrl: function(element, attrs) {
39916 return attrs.templateUrl || 'uib/template/timepicker/timepicker.html';
39918 link: function(scope, element, attrs, ctrls) {
39919 var timepickerCtrl = ctrls[0], ngModelCtrl = ctrls[1];
39922 timepickerCtrl.init(ngModelCtrl, element.find('input'));
39928 angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap.position'])
39931 * A helper service that can parse typeahead's syntax (string provided by users)
39932 * Extracted to a separate service for ease of unit testing
39934 .factory('uibTypeaheadParser', ['$parse', function($parse) {
39935 // 00000111000000000000022200000000000000003333333333333330000000000044000
39936 var TYPEAHEAD_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w\d]*))\s+in\s+([\s\S]+?)$/;
39938 parse: function(input) {
39939 var match = input.match(TYPEAHEAD_REGEXP);
39942 'Expected typeahead specification in form of "_modelValue_ (as _label_)? for _item_ in _collection_"' +
39943 ' but got "' + input + '".');
39947 itemName: match[3],
39948 source: $parse(match[4]),
39949 viewMapper: $parse(match[2] || match[1]),
39950 modelMapper: $parse(match[1])
39956 .controller('UibTypeaheadController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$q', '$timeout', '$document', '$window', '$rootScope', '$$debounce', '$uibPosition', 'uibTypeaheadParser',
39957 function(originalScope, element, attrs, $compile, $parse, $q, $timeout, $document, $window, $rootScope, $$debounce, $position, typeaheadParser) {
39958 var HOT_KEYS = [9, 13, 27, 38, 40];
39959 var eventDebounceTime = 200;
39960 var modelCtrl, ngModelOptions;
39961 //SUPPORTED ATTRIBUTES (OPTIONS)
39963 //minimal no of characters that needs to be entered before typeahead kicks-in
39964 var minLength = originalScope.$eval(attrs.typeaheadMinLength);
39965 if (!minLength && minLength !== 0) {
39969 //minimal wait time after last character typed before typeahead kicks-in
39970 var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0;
39972 //should it restrict model values to the ones selected from the popup only?
39973 var isEditable = originalScope.$eval(attrs.typeaheadEditable) !== false;
39974 originalScope.$watch(attrs.typeaheadEditable, function (newVal) {
39975 isEditable = newVal !== false;
39978 //binding to a variable that indicates if matches are being retrieved asynchronously
39979 var isLoadingSetter = $parse(attrs.typeaheadLoading).assign || angular.noop;
39981 //a callback executed when a match is selected
39982 var onSelectCallback = $parse(attrs.typeaheadOnSelect);
39984 //should it select highlighted popup value when losing focus?
39985 var isSelectOnBlur = angular.isDefined(attrs.typeaheadSelectOnBlur) ? originalScope.$eval(attrs.typeaheadSelectOnBlur) : false;
39987 //binding to a variable that indicates if there were no results after the query is completed
39988 var isNoResultsSetter = $parse(attrs.typeaheadNoResults).assign || angular.noop;
39990 var inputFormatter = attrs.typeaheadInputFormatter ? $parse(attrs.typeaheadInputFormatter) : undefined;
39992 var appendToBody = attrs.typeaheadAppendToBody ? originalScope.$eval(attrs.typeaheadAppendToBody) : false;
39994 var appendTo = attrs.typeaheadAppendTo ?
39995 originalScope.$eval(attrs.typeaheadAppendTo) : null;
39997 var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;
39999 //If input matches an item of the list exactly, select it automatically
40000 var selectOnExact = attrs.typeaheadSelectOnExact ? originalScope.$eval(attrs.typeaheadSelectOnExact) : false;
40002 //binding to a variable that indicates if dropdown is open
40003 var isOpenSetter = $parse(attrs.typeaheadIsOpen).assign || angular.noop;
40005 var showHint = originalScope.$eval(attrs.typeaheadShowHint) || false;
40007 //INTERNAL VARIABLES
40009 //model setter executed upon match selection
40010 var parsedModel = $parse(attrs.ngModel);
40011 var invokeModelSetter = $parse(attrs.ngModel + '($$$p)');
40012 var $setModelValue = function(scope, newValue) {
40013 if (angular.isFunction(parsedModel(originalScope)) &&
40014 ngModelOptions && ngModelOptions.$options && ngModelOptions.$options.getterSetter) {
40015 return invokeModelSetter(scope, {$$$p: newValue});
40018 return parsedModel.assign(scope, newValue);
40021 //expressions used by typeahead
40022 var parserResult = typeaheadParser.parse(attrs.uibTypeahead);
40026 //Used to avoid bug in iOS webview where iOS keyboard does not fire
40027 //mousedown & mouseup events
40031 //create a child scope for the typeahead directive so we are not polluting original scope
40032 //with typeahead-specific data (matches, query etc.)
40033 var scope = originalScope.$new();
40034 var offDestroy = originalScope.$on('$destroy', function() {
40037 scope.$on('$destroy', offDestroy);
40040 var popupId = 'typeahead-' + scope.$id + '-' + Math.floor(Math.random() * 10000);
40042 'aria-autocomplete': 'list',
40043 'aria-expanded': false,
40044 'aria-owns': popupId
40047 var inputsContainer, hintInputElem;
40048 //add read-only input to show hint
40050 inputsContainer = angular.element('<div></div>');
40051 inputsContainer.css('position', 'relative');
40052 element.after(inputsContainer);
40053 hintInputElem = element.clone();
40054 hintInputElem.attr('placeholder', '');
40055 hintInputElem.val('');
40056 hintInputElem.css({
40057 'position': 'absolute',
40060 'border-color': 'transparent',
40061 'box-shadow': 'none',
40063 'background': 'none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255)',
40067 'position': 'relative',
40068 'vertical-align': 'top',
40069 'background-color': 'transparent'
40071 inputsContainer.append(hintInputElem);
40072 hintInputElem.after(element);
40075 //pop-up element used to display matches
40076 var popUpEl = angular.element('<div uib-typeahead-popup></div>');
40079 matches: 'matches',
40080 active: 'activeIdx',
40081 select: 'select(activeIdx, evt)',
40082 'move-in-progress': 'moveInProgress',
40084 position: 'position',
40085 'assign-is-open': 'assignIsOpen(isOpen)',
40086 debounce: 'debounceUpdate'
40088 //custom item template
40089 if (angular.isDefined(attrs.typeaheadTemplateUrl)) {
40090 popUpEl.attr('template-url', attrs.typeaheadTemplateUrl);
40093 if (angular.isDefined(attrs.typeaheadPopupTemplateUrl)) {
40094 popUpEl.attr('popup-template-url', attrs.typeaheadPopupTemplateUrl);
40097 var resetHint = function() {
40099 hintInputElem.val('');
40103 var resetMatches = function() {
40104 scope.matches = [];
40105 scope.activeIdx = -1;
40106 element.attr('aria-expanded', false);
40110 var getMatchId = function(index) {
40111 return popupId + '-option-' + index;
40114 // Indicate that the specified match is the active (pre-selected) item in the list owned by this typeahead.
40115 // This attribute is added or removed automatically when the `activeIdx` changes.
40116 scope.$watch('activeIdx', function(index) {
40118 element.removeAttr('aria-activedescendant');
40120 element.attr('aria-activedescendant', getMatchId(index));
40124 var inputIsExactMatch = function(inputValue, index) {
40125 if (scope.matches.length > index && inputValue) {
40126 return inputValue.toUpperCase() === scope.matches[index].label.toUpperCase();
40132 var getMatchesAsync = function(inputValue, evt) {
40133 var locals = {$viewValue: inputValue};
40134 isLoadingSetter(originalScope, true);
40135 isNoResultsSetter(originalScope, false);
40136 $q.when(parserResult.source(originalScope, locals)).then(function(matches) {
40137 //it might happen that several async queries were in progress if a user were typing fast
40138 //but we are interested only in responses that correspond to the current view value
40139 var onCurrentRequest = inputValue === modelCtrl.$viewValue;
40140 if (onCurrentRequest && hasFocus) {
40141 if (matches && matches.length > 0) {
40142 scope.activeIdx = focusFirst ? 0 : -1;
40143 isNoResultsSetter(originalScope, false);
40144 scope.matches.length = 0;
40147 for (var i = 0; i < matches.length; i++) {
40148 locals[parserResult.itemName] = matches[i];
40149 scope.matches.push({
40151 label: parserResult.viewMapper(scope, locals),
40156 scope.query = inputValue;
40157 //position pop-up with matches - we need to re-calculate its position each time we are opening a window
40158 //with matches as a pop-up might be absolute-positioned and position of an input might have changed on a page
40159 //due to other elements being rendered
40160 recalculatePosition();
40162 element.attr('aria-expanded', true);
40164 //Select the single remaining option if user input matches
40165 if (selectOnExact && scope.matches.length === 1 && inputIsExactMatch(inputValue, 0)) {
40166 if (angular.isNumber(scope.debounceUpdate) || angular.isObject(scope.debounceUpdate)) {
40167 $$debounce(function() {
40168 scope.select(0, evt);
40169 }, angular.isNumber(scope.debounceUpdate) ? scope.debounceUpdate : scope.debounceUpdate['default']);
40171 scope.select(0, evt);
40176 var firstLabel = scope.matches[0].label;
40177 if (inputValue.length > 0 && firstLabel.slice(0, inputValue.length).toUpperCase() === inputValue.toUpperCase()) {
40178 hintInputElem.val(inputValue + firstLabel.slice(inputValue.length));
40181 hintInputElem.val('');
40186 isNoResultsSetter(originalScope, true);
40189 if (onCurrentRequest) {
40190 isLoadingSetter(originalScope, false);
40194 isLoadingSetter(originalScope, false);
40195 isNoResultsSetter(originalScope, true);
40199 // bind events only if appendToBody params exist - performance feature
40200 if (appendToBody) {
40201 angular.element($window).on('resize', fireRecalculating);
40202 $document.find('body').on('scroll', fireRecalculating);
40205 // Declare the debounced function outside recalculating for
40206 // proper debouncing
40207 var debouncedRecalculate = $$debounce(function() {
40208 // if popup is visible
40209 if (scope.matches.length) {
40210 recalculatePosition();
40213 scope.moveInProgress = false;
40214 }, eventDebounceTime);
40216 // Default progress type
40217 scope.moveInProgress = false;
40219 function fireRecalculating() {
40220 if (!scope.moveInProgress) {
40221 scope.moveInProgress = true;
40225 debouncedRecalculate();
40228 // recalculate actual position and set new values to scope
40229 // after digest loop is popup in right position
40230 function recalculatePosition() {
40231 scope.position = appendToBody ? $position.offset(element) : $position.position(element);
40232 scope.position.top += element.prop('offsetHeight');
40235 //we need to propagate user's query so we can higlight matches
40236 scope.query = undefined;
40238 //Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
40239 var timeoutPromise;
40241 var scheduleSearchWithTimeout = function(inputValue) {
40242 timeoutPromise = $timeout(function() {
40243 getMatchesAsync(inputValue);
40247 var cancelPreviousTimeout = function() {
40248 if (timeoutPromise) {
40249 $timeout.cancel(timeoutPromise);
40255 scope.assignIsOpen = function (isOpen) {
40256 isOpenSetter(originalScope, isOpen);
40259 scope.select = function(activeIdx, evt) {
40260 //called from within the $digest() cycle
40265 locals[parserResult.itemName] = item = scope.matches[activeIdx].model;
40266 model = parserResult.modelMapper(originalScope, locals);
40267 $setModelValue(originalScope, model);
40268 modelCtrl.$setValidity('editable', true);
40269 modelCtrl.$setValidity('parse', true);
40271 onSelectCallback(originalScope, {
40274 $label: parserResult.viewMapper(originalScope, locals),
40280 //return focus to the input element if a match was selected via a mouse click event
40281 // use timeout to avoid $rootScope:inprog error
40282 if (scope.$eval(attrs.typeaheadFocusOnSelect) !== false) {
40283 $timeout(function() { element[0].focus(); }, 0, false);
40287 //bind keyboard events: arrows up(38) / down(40), enter(13) and tab(9), esc(27)
40288 element.on('keydown', function(evt) {
40289 //typeahead is open and an "interesting" key was pressed
40290 if (scope.matches.length === 0 || HOT_KEYS.indexOf(evt.which) === -1) {
40294 // if there's nothing selected (i.e. focusFirst) and enter or tab is hit, clear the results
40295 if (scope.activeIdx === -1 && (evt.which === 9 || evt.which === 13)) {
40301 evt.preventDefault();
40303 switch (evt.which) {
40306 scope.$apply(function () {
40307 if (angular.isNumber(scope.debounceUpdate) || angular.isObject(scope.debounceUpdate)) {
40308 $$debounce(function() {
40309 scope.select(scope.activeIdx, evt);
40310 }, angular.isNumber(scope.debounceUpdate) ? scope.debounceUpdate : scope.debounceUpdate['default']);
40312 scope.select(scope.activeIdx, evt);
40317 evt.stopPropagation();
40323 scope.activeIdx = (scope.activeIdx > 0 ? scope.activeIdx : scope.matches.length) - 1;
40325 popUpEl.find('li')[scope.activeIdx].scrollIntoView(false);
40328 scope.activeIdx = (scope.activeIdx + 1) % scope.matches.length;
40330 popUpEl.find('li')[scope.activeIdx].scrollIntoView(false);
40335 element.bind('focus', function (evt) {
40337 if (minLength === 0 && !modelCtrl.$viewValue) {
40338 $timeout(function() {
40339 getMatchesAsync(modelCtrl.$viewValue, evt);
40344 element.bind('blur', function(evt) {
40345 if (isSelectOnBlur && scope.matches.length && scope.activeIdx !== -1 && !selected) {
40347 scope.$apply(function() {
40348 if (angular.isObject(scope.debounceUpdate) && angular.isNumber(scope.debounceUpdate.blur)) {
40349 $$debounce(function() {
40350 scope.select(scope.activeIdx, evt);
40351 }, scope.debounceUpdate.blur);
40353 scope.select(scope.activeIdx, evt);
40357 if (!isEditable && modelCtrl.$error.editable) {
40358 modelCtrl.$viewValue = '';
40365 // Keep reference to click handler to unbind it.
40366 var dismissClickHandler = function(evt) {
40368 // Firefox treats right click as a click on document
40369 if (element[0] !== evt.target && evt.which !== 3 && scope.matches.length !== 0) {
40371 if (!$rootScope.$$phase) {
40377 $document.on('click', dismissClickHandler);
40379 originalScope.$on('$destroy', function() {
40380 $document.off('click', dismissClickHandler);
40381 if (appendToBody || appendTo) {
40385 if (appendToBody) {
40386 angular.element($window).off('resize', fireRecalculating);
40387 $document.find('body').off('scroll', fireRecalculating);
40389 // Prevent jQuery cache memory leak
40393 inputsContainer.remove();
40397 var $popup = $compile(popUpEl)(scope);
40399 if (appendToBody) {
40400 $document.find('body').append($popup);
40401 } else if (appendTo) {
40402 angular.element(appendTo).eq(0).append($popup);
40404 element.after($popup);
40407 this.init = function(_modelCtrl, _ngModelOptions) {
40408 modelCtrl = _modelCtrl;
40409 ngModelOptions = _ngModelOptions;
40411 scope.debounceUpdate = modelCtrl.$options && $parse(modelCtrl.$options.debounce)(originalScope);
40413 //plug into $parsers pipeline to open a typeahead on view changes initiated from DOM
40414 //$parsers kick-in on all the changes coming from the view as well as manually triggered by $setViewValue
40415 modelCtrl.$parsers.unshift(function(inputValue) {
40418 if (minLength === 0 || inputValue && inputValue.length >= minLength) {
40419 if (waitTime > 0) {
40420 cancelPreviousTimeout();
40421 scheduleSearchWithTimeout(inputValue);
40423 getMatchesAsync(inputValue);
40426 isLoadingSetter(originalScope, false);
40427 cancelPreviousTimeout();
40436 // Reset in case user had typed something previously.
40437 modelCtrl.$setValidity('editable', true);
40441 modelCtrl.$setValidity('editable', false);
40445 modelCtrl.$formatters.push(function(modelValue) {
40446 var candidateViewValue, emptyViewValue;
40449 // The validity may be set to false via $parsers (see above) if
40450 // the model is restricted to selected values. If the model
40451 // is set manually it is considered to be valid.
40453 modelCtrl.$setValidity('editable', true);
40456 if (inputFormatter) {
40457 locals.$model = modelValue;
40458 return inputFormatter(originalScope, locals);
40461 //it might happen that we don't have enough info to properly render input value
40462 //we need to check for this situation and simply return model value if we can't apply custom formatting
40463 locals[parserResult.itemName] = modelValue;
40464 candidateViewValue = parserResult.viewMapper(originalScope, locals);
40465 locals[parserResult.itemName] = undefined;
40466 emptyViewValue = parserResult.viewMapper(originalScope, locals);
40468 return candidateViewValue !== emptyViewValue ? candidateViewValue : modelValue;
40473 .directive('uibTypeahead', function() {
40475 controller: 'UibTypeaheadController',
40476 require: ['ngModel', '^?ngModelOptions', 'uibTypeahead'],
40477 link: function(originalScope, element, attrs, ctrls) {
40478 ctrls[2].init(ctrls[0], ctrls[1]);
40483 .directive('uibTypeaheadPopup', ['$$debounce', function($$debounce) {
40490 moveInProgress: '=',
40496 templateUrl: function(element, attrs) {
40497 return attrs.popupTemplateUrl || 'uib/template/typeahead/typeahead-popup.html';
40499 link: function(scope, element, attrs) {
40500 scope.templateUrl = attrs.templateUrl;
40502 scope.isOpen = function() {
40503 var isDropdownOpen = scope.matches.length > 0;
40504 scope.assignIsOpen({ isOpen: isDropdownOpen });
40505 return isDropdownOpen;
40508 scope.isActive = function(matchIdx) {
40509 return scope.active === matchIdx;
40512 scope.selectActive = function(matchIdx) {
40513 scope.active = matchIdx;
40516 scope.selectMatch = function(activeIdx, evt) {
40517 var debounce = scope.debounce();
40518 if (angular.isNumber(debounce) || angular.isObject(debounce)) {
40519 $$debounce(function() {
40520 scope.select({activeIdx: activeIdx, evt: evt});
40521 }, angular.isNumber(debounce) ? debounce : debounce['default']);
40523 scope.select({activeIdx: activeIdx, evt: evt});
40530 .directive('uibTypeaheadMatch', ['$templateRequest', '$compile', '$parse', function($templateRequest, $compile, $parse) {
40537 link: function(scope, element, attrs) {
40538 var tplUrl = $parse(attrs.templateUrl)(scope.$parent) || 'uib/template/typeahead/typeahead-match.html';
40539 $templateRequest(tplUrl).then(function(tplContent) {
40540 var tplEl = angular.element(tplContent.trim());
40541 element.replaceWith(tplEl);
40542 $compile(tplEl)(scope);
40548 .filter('uibTypeaheadHighlight', ['$sce', '$injector', '$log', function($sce, $injector, $log) {
40549 var isSanitizePresent;
40550 isSanitizePresent = $injector.has('$sanitize');
40552 function escapeRegexp(queryToEscape) {
40553 // Regex: capture the whole query string and replace it with the string that will be used to match
40554 // the results, for example if the capture is "a" the result will be \a
40555 return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
40558 function containsHtml(matchItem) {
40559 return /<.*>/g.test(matchItem);
40562 return function(matchItem, query) {
40563 if (!isSanitizePresent && containsHtml(matchItem)) {
40564 $log.warn('Unsafe use of typeahead please use ngSanitize'); // Warn the user about the danger
40566 matchItem = query ? ('' + matchItem).replace(new RegExp(escapeRegexp(query), 'gi'), '<strong>$&</strong>') : matchItem; // Replaces the capture string with a the same string inside of a "strong" tag
40567 if (!isSanitizePresent) {
40568 matchItem = $sce.trustAsHtml(matchItem); // If $sanitize is not present we pack the string in a $sce object for the ng-bind-html directive
40574 angular.module("uib/template/accordion/accordion-group.html", []).run(["$templateCache", function($templateCache) {
40575 $templateCache.put("uib/template/accordion/accordion-group.html",
40576 "<div class=\"panel\" ng-class=\"panelClass || 'panel-default'\">\n" +
40577 " <div class=\"panel-heading\" ng-keypress=\"toggleOpen($event)\">\n" +
40578 " <h4 class=\"panel-title\">\n" +
40579 " <div tabindex=\"0\" class=\"accordion-toggle\" ng-click=\"toggleOpen()\" uib-accordion-transclude=\"heading\"><span ng-class=\"{'text-muted': isDisabled}\">{{heading}}</span></div>\n" +
40582 " <div class=\"panel-collapse collapse\" uib-collapse=\"!isOpen\">\n" +
40583 " <div class=\"panel-body\" ng-transclude></div>\n" +
40589 angular.module("uib/template/accordion/accordion.html", []).run(["$templateCache", function($templateCache) {
40590 $templateCache.put("uib/template/accordion/accordion.html",
40591 "<div class=\"panel-group\" ng-transclude></div>");
40594 angular.module("uib/template/alert/alert.html", []).run(["$templateCache", function($templateCache) {
40595 $templateCache.put("uib/template/alert/alert.html",
40596 "<div class=\"alert\" ng-class=\"['alert-' + (type || 'warning'), closeable ? 'alert-dismissible' : null]\" role=\"alert\">\n" +
40597 " <button ng-show=\"closeable\" type=\"button\" class=\"close\" ng-click=\"close({$event: $event})\">\n" +
40598 " <span aria-hidden=\"true\">×</span>\n" +
40599 " <span class=\"sr-only\">Close</span>\n" +
40601 " <div ng-transclude></div>\n" +
40606 angular.module("uib/template/carousel/carousel.html", []).run(["$templateCache", function($templateCache) {
40607 $templateCache.put("uib/template/carousel/carousel.html",
40608 "<div ng-mouseenter=\"pause()\" ng-mouseleave=\"play()\" class=\"carousel\" ng-swipe-right=\"prev()\" ng-swipe-left=\"next()\">\n" +
40609 " <div class=\"carousel-inner\" ng-transclude></div>\n" +
40610 " <a role=\"button\" href class=\"left carousel-control\" ng-click=\"prev()\" ng-show=\"slides.length > 1\">\n" +
40611 " <span aria-hidden=\"true\" class=\"glyphicon glyphicon-chevron-left\"></span>\n" +
40612 " <span class=\"sr-only\">previous</span>\n" +
40614 " <a role=\"button\" href class=\"right carousel-control\" ng-click=\"next()\" ng-show=\"slides.length > 1\">\n" +
40615 " <span aria-hidden=\"true\" class=\"glyphicon glyphicon-chevron-right\"></span>\n" +
40616 " <span class=\"sr-only\">next</span>\n" +
40618 " <ol class=\"carousel-indicators\" ng-show=\"slides.length > 1\">\n" +
40619 " <li ng-repeat=\"slide in slides | orderBy:indexOfSlide track by $index\" ng-class=\"{ active: isActive(slide) }\" ng-click=\"select(slide)\">\n" +
40620 " <span class=\"sr-only\">slide {{ $index + 1 }} of {{ slides.length }}<span ng-if=\"isActive(slide)\">, currently active</span></span>\n" +
40626 angular.module("uib/template/carousel/slide.html", []).run(["$templateCache", function($templateCache) {
40627 $templateCache.put("uib/template/carousel/slide.html",
40628 "<div ng-class=\"{\n" +
40629 " 'active': active\n" +
40630 " }\" class=\"item text-center\" ng-transclude></div>\n" +
40634 angular.module("uib/template/datepicker/datepicker.html", []).run(["$templateCache", function($templateCache) {
40635 $templateCache.put("uib/template/datepicker/datepicker.html",
40636 "<div class=\"uib-datepicker\" ng-switch=\"datepickerMode\" role=\"application\" ng-keydown=\"keydown($event)\">\n" +
40637 " <uib-daypicker ng-switch-when=\"day\" tabindex=\"0\"></uib-daypicker>\n" +
40638 " <uib-monthpicker ng-switch-when=\"month\" tabindex=\"0\"></uib-monthpicker>\n" +
40639 " <uib-yearpicker ng-switch-when=\"year\" tabindex=\"0\"></uib-yearpicker>\n" +
40643 angular.module("uib/template/datepicker/day.html", []).run(["$templateCache", function($templateCache) {
40644 $templateCache.put("uib/template/datepicker/day.html",
40645 "<table class=\"uib-daypicker\" role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
40648 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-left\"></i></button></th>\n" +
40649 " <th colspan=\"{{::5 + showWeeks}}\"><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\" style=\"width:100%;\"><strong>{{title}}</strong></button></th>\n" +
40650 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-right\"></i></button></th>\n" +
40653 " <th ng-if=\"showWeeks\" class=\"text-center\"></th>\n" +
40654 " <th ng-repeat=\"label in ::labels track by $index\" class=\"text-center\"><small aria-label=\"{{::label.full}}\">{{::label.abbr}}</small></th>\n" +
40658 " <tr class=\"uib-weeks\" ng-repeat=\"row in rows track by $index\">\n" +
40659 " <td ng-if=\"showWeeks\" class=\"text-center h6\"><em>{{ weekNumbers[$index] }}</em></td>\n" +
40660 " <td ng-repeat=\"dt in row\" class=\"uib-day text-center\" role=\"gridcell\"\n" +
40661 " id=\"{{::dt.uid}}\"\n" +
40662 " ng-class=\"::dt.customClass\">\n" +
40663 " <button type=\"button\" style=\"min-width:100%;\" class=\"btn btn-default btn-sm\"\n" +
40664 " uib-is-class=\"\n" +
40665 " 'btn-info' for selectedDt,\n" +
40666 " 'active' for activeDt\n" +
40668 " ng-click=\"select(dt.date)\"\n" +
40669 " ng-disabled=\"::dt.disabled\"\n" +
40670 " tabindex=\"-1\"><span ng-class=\"::{'text-muted': dt.secondary, 'text-info': dt.current}\">{{::dt.label}}</span></button>\n" +
40678 angular.module("uib/template/datepicker/month.html", []).run(["$templateCache", function($templateCache) {
40679 $templateCache.put("uib/template/datepicker/month.html",
40680 "<table class=\"uib-monthpicker\" role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
40683 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-left\"></i></button></th>\n" +
40684 " <th><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\" style=\"width:100%;\"><strong>{{title}}</strong></button></th>\n" +
40685 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-right\"></i></button></th>\n" +
40689 " <tr class=\"uib-months\" ng-repeat=\"row in rows track by $index\">\n" +
40690 " <td ng-repeat=\"dt in row\" class=\"uib-month text-center\" role=\"gridcell\"\n" +
40691 " id=\"{{::dt.uid}}\"\n" +
40692 " ng-class=\"::dt.customClass\">\n" +
40693 " <button type=\"button\" style=\"min-width:100%;\" class=\"btn btn-default\"\n" +
40694 " uib-is-class=\"\n" +
40695 " 'btn-info' for selectedDt,\n" +
40696 " 'active' for activeDt\n" +
40698 " ng-click=\"select(dt.date)\"\n" +
40699 " ng-disabled=\"::dt.disabled\"\n" +
40700 " tabindex=\"-1\"><span ng-class=\"::{'text-info': dt.current}\">{{::dt.label}}</span></button>\n" +
40708 angular.module("uib/template/datepicker/popup.html", []).run(["$templateCache", function($templateCache) {
40709 $templateCache.put("uib/template/datepicker/popup.html",
40710 "<ul class=\"uib-datepicker-popup dropdown-menu\" dropdown-nested ng-if=\"isOpen\" style=\"display: block\" ng-style=\"{top: position.top+'px', left: position.left+'px'}\" ng-keydown=\"keydown($event)\" ng-click=\"$event.stopPropagation()\">\n" +
40711 " <li ng-transclude></li>\n" +
40712 " <li ng-if=\"showButtonBar\" style=\"padding:10px 9px 2px\" class=\"uib-button-bar\">\n" +
40713 " <span class=\"btn-group pull-left\">\n" +
40714 " <button type=\"button\" class=\"btn btn-sm btn-info uib-datepicker-current\" ng-click=\"select('today')\" ng-disabled=\"isDisabled('today')\">{{ getText('current') }}</button>\n" +
40715 " <button type=\"button\" class=\"btn btn-sm btn-danger uib-clear\" ng-click=\"select(null)\">{{ getText('clear') }}</button>\n" +
40717 " <button type=\"button\" class=\"btn btn-sm btn-success pull-right uib-close\" ng-click=\"close()\">{{ getText('close') }}</button>\n" +
40723 angular.module("uib/template/datepicker/year.html", []).run(["$templateCache", function($templateCache) {
40724 $templateCache.put("uib/template/datepicker/year.html",
40725 "<table class=\"uib-yearpicker\" role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
40728 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-left\"></i></button></th>\n" +
40729 " <th colspan=\"{{::columns - 2}}\"><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\" style=\"width:100%;\"><strong>{{title}}</strong></button></th>\n" +
40730 " <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-right\"></i></button></th>\n" +
40734 " <tr class=\"uib-years\" ng-repeat=\"row in rows track by $index\">\n" +
40735 " <td ng-repeat=\"dt in row\" class=\"uib-year text-center\" role=\"gridcell\"\n" +
40736 " id=\"{{::dt.uid}}\"\n" +
40737 " ng-class=\"::dt.customClass\">\n" +
40738 " <button type=\"button\" style=\"min-width:100%;\" class=\"btn btn-default\"\n" +
40739 " uib-is-class=\"\n" +
40740 " 'btn-info' for selectedDt,\n" +
40741 " 'active' for activeDt\n" +
40743 " ng-click=\"select(dt.date)\"\n" +
40744 " ng-disabled=\"::dt.disabled\"\n" +
40745 " tabindex=\"-1\"><span ng-class=\"::{'text-info': dt.current}\">{{::dt.label}}</span></button>\n" +
40753 angular.module("uib/template/modal/backdrop.html", []).run(["$templateCache", function($templateCache) {
40754 $templateCache.put("uib/template/modal/backdrop.html",
40755 "<div class=\"modal-backdrop\"\n" +
40756 " uib-modal-animation-class=\"fade\"\n" +
40757 " modal-in-class=\"in\"\n" +
40758 " ng-style=\"{'z-index': 1040 + (index && 1 || 0) + index*10}\"\n" +
40763 angular.module("uib/template/modal/window.html", []).run(["$templateCache", function($templateCache) {
40764 $templateCache.put("uib/template/modal/window.html",
40765 "<div modal-render=\"{{$isRendered}}\" tabindex=\"-1\" role=\"dialog\" class=\"modal\"\n" +
40766 " uib-modal-animation-class=\"fade\"\n" +
40767 " modal-in-class=\"in\"\n" +
40768 " ng-style=\"{'z-index': 1050 + index*10, display: 'block'}\">\n" +
40769 " <div class=\"modal-dialog\" ng-class=\"size ? 'modal-' + size : ''\"><div class=\"modal-content\" uib-modal-transclude></div></div>\n" +
40774 angular.module("uib/template/pager/pager.html", []).run(["$templateCache", function($templateCache) {
40775 $templateCache.put("uib/template/pager/pager.html",
40776 "<ul class=\"pager\">\n" +
40777 " <li ng-class=\"{disabled: noPrevious()||ngDisabled, previous: align}\"><a href ng-click=\"selectPage(page - 1, $event)\">{{::getText('previous')}}</a></li>\n" +
40778 " <li ng-class=\"{disabled: noNext()||ngDisabled, next: align}\"><a href ng-click=\"selectPage(page + 1, $event)\">{{::getText('next')}}</a></li>\n" +
40783 angular.module("uib/template/pagination/pager.html", []).run(["$templateCache", function($templateCache) {
40784 $templateCache.put("uib/template/pagination/pager.html",
40785 "<ul class=\"pager\">\n" +
40786 " <li ng-class=\"{disabled: noPrevious()||ngDisabled, previous: align}\"><a href ng-click=\"selectPage(page - 1, $event)\">{{::getText('previous')}}</a></li>\n" +
40787 " <li ng-class=\"{disabled: noNext()||ngDisabled, next: align}\"><a href ng-click=\"selectPage(page + 1, $event)\">{{::getText('next')}}</a></li>\n" +
40792 angular.module("uib/template/pagination/pagination.html", []).run(["$templateCache", function($templateCache) {
40793 $templateCache.put("uib/template/pagination/pagination.html",
40794 "<ul class=\"pagination\">\n" +
40795 " <li ng-if=\"::boundaryLinks\" ng-class=\"{disabled: noPrevious()||ngDisabled}\" class=\"pagination-first\"><a href ng-click=\"selectPage(1, $event)\">{{::getText('first')}}</a></li>\n" +
40796 " <li ng-if=\"::directionLinks\" ng-class=\"{disabled: noPrevious()||ngDisabled}\" class=\"pagination-prev\"><a href ng-click=\"selectPage(page - 1, $event)\">{{::getText('previous')}}</a></li>\n" +
40797 " <li ng-repeat=\"page in pages track by $index\" ng-class=\"{active: page.active,disabled: ngDisabled&&!page.active}\" class=\"pagination-page\"><a href ng-click=\"selectPage(page.number, $event)\">{{page.text}}</a></li>\n" +
40798 " <li ng-if=\"::directionLinks\" ng-class=\"{disabled: noNext()||ngDisabled}\" class=\"pagination-next\"><a href ng-click=\"selectPage(page + 1, $event)\">{{::getText('next')}}</a></li>\n" +
40799 " <li ng-if=\"::boundaryLinks\" ng-class=\"{disabled: noNext()||ngDisabled}\" class=\"pagination-last\"><a href ng-click=\"selectPage(totalPages, $event)\">{{::getText('last')}}</a></li>\n" +
40804 angular.module("uib/template/tooltip/tooltip-html-popup.html", []).run(["$templateCache", function($templateCache) {
40805 $templateCache.put("uib/template/tooltip/tooltip-html-popup.html",
40806 "<div class=\"tooltip\"\n" +
40807 " tooltip-animation-class=\"fade\"\n" +
40808 " uib-tooltip-classes\n" +
40809 " ng-class=\"{ in: isOpen() }\">\n" +
40810 " <div class=\"tooltip-arrow\"></div>\n" +
40811 " <div class=\"tooltip-inner\" ng-bind-html=\"contentExp()\"></div>\n" +
40816 angular.module("uib/template/tooltip/tooltip-popup.html", []).run(["$templateCache", function($templateCache) {
40817 $templateCache.put("uib/template/tooltip/tooltip-popup.html",
40818 "<div class=\"tooltip\"\n" +
40819 " tooltip-animation-class=\"fade\"\n" +
40820 " uib-tooltip-classes\n" +
40821 " ng-class=\"{ in: isOpen() }\">\n" +
40822 " <div class=\"tooltip-arrow\"></div>\n" +
40823 " <div class=\"tooltip-inner\" ng-bind=\"content\"></div>\n" +
40828 angular.module("uib/template/tooltip/tooltip-template-popup.html", []).run(["$templateCache", function($templateCache) {
40829 $templateCache.put("uib/template/tooltip/tooltip-template-popup.html",
40830 "<div class=\"tooltip\"\n" +
40831 " tooltip-animation-class=\"fade\"\n" +
40832 " uib-tooltip-classes\n" +
40833 " ng-class=\"{ in: isOpen() }\">\n" +
40834 " <div class=\"tooltip-arrow\"></div>\n" +
40835 " <div class=\"tooltip-inner\"\n" +
40836 " uib-tooltip-template-transclude=\"contentExp()\"\n" +
40837 " tooltip-template-transclude-scope=\"originScope()\"></div>\n" +
40842 angular.module("uib/template/popover/popover-html.html", []).run(["$templateCache", function($templateCache) {
40843 $templateCache.put("uib/template/popover/popover-html.html",
40844 "<div class=\"popover\"\n" +
40845 " tooltip-animation-class=\"fade\"\n" +
40846 " uib-tooltip-classes\n" +
40847 " ng-class=\"{ in: isOpen() }\">\n" +
40848 " <div class=\"arrow\"></div>\n" +
40850 " <div class=\"popover-inner\">\n" +
40851 " <h3 class=\"popover-title\" ng-bind=\"title\" ng-if=\"title\"></h3>\n" +
40852 " <div class=\"popover-content\" ng-bind-html=\"contentExp()\"></div>\n" +
40858 angular.module("uib/template/popover/popover-template.html", []).run(["$templateCache", function($templateCache) {
40859 $templateCache.put("uib/template/popover/popover-template.html",
40860 "<div class=\"popover\"\n" +
40861 " tooltip-animation-class=\"fade\"\n" +
40862 " uib-tooltip-classes\n" +
40863 " ng-class=\"{ in: isOpen() }\">\n" +
40864 " <div class=\"arrow\"></div>\n" +
40866 " <div class=\"popover-inner\">\n" +
40867 " <h3 class=\"popover-title\" ng-bind=\"title\" ng-if=\"title\"></h3>\n" +
40868 " <div class=\"popover-content\"\n" +
40869 " uib-tooltip-template-transclude=\"contentExp()\"\n" +
40870 " tooltip-template-transclude-scope=\"originScope()\"></div>\n" +
40876 angular.module("uib/template/popover/popover.html", []).run(["$templateCache", function($templateCache) {
40877 $templateCache.put("uib/template/popover/popover.html",
40878 "<div class=\"popover\"\n" +
40879 " tooltip-animation-class=\"fade\"\n" +
40880 " uib-tooltip-classes\n" +
40881 " ng-class=\"{ in: isOpen() }\">\n" +
40882 " <div class=\"arrow\"></div>\n" +
40884 " <div class=\"popover-inner\">\n" +
40885 " <h3 class=\"popover-title\" ng-bind=\"title\" ng-if=\"title\"></h3>\n" +
40886 " <div class=\"popover-content\" ng-bind=\"content\"></div>\n" +
40892 angular.module("uib/template/progressbar/bar.html", []).run(["$templateCache", function($templateCache) {
40893 $templateCache.put("uib/template/progressbar/bar.html",
40894 "<div class=\"progress-bar\" ng-class=\"type && 'progress-bar-' + type\" role=\"progressbar\" aria-valuenow=\"{{value}}\" aria-valuemin=\"0\" aria-valuemax=\"{{max}}\" ng-style=\"{width: (percent < 100 ? percent : 100) + '%'}\" aria-valuetext=\"{{percent | number:0}}%\" aria-labelledby=\"{{::title}}\" ng-transclude></div>\n" +
40898 angular.module("uib/template/progressbar/progress.html", []).run(["$templateCache", function($templateCache) {
40899 $templateCache.put("uib/template/progressbar/progress.html",
40900 "<div class=\"progress\" ng-transclude aria-labelledby=\"{{::title}}\"></div>");
40903 angular.module("uib/template/progressbar/progressbar.html", []).run(["$templateCache", function($templateCache) {
40904 $templateCache.put("uib/template/progressbar/progressbar.html",
40905 "<div class=\"progress\">\n" +
40906 " <div class=\"progress-bar\" ng-class=\"type && 'progress-bar-' + type\" role=\"progressbar\" aria-valuenow=\"{{value}}\" aria-valuemin=\"0\" aria-valuemax=\"{{max}}\" ng-style=\"{width: (percent < 100 ? percent : 100) + '%'}\" aria-valuetext=\"{{percent | number:0}}%\" aria-labelledby=\"{{::title}}\" ng-transclude></div>\n" +
40911 angular.module("uib/template/rating/rating.html", []).run(["$templateCache", function($templateCache) {
40912 $templateCache.put("uib/template/rating/rating.html",
40913 "<span ng-mouseleave=\"reset()\" ng-keydown=\"onKeydown($event)\" tabindex=\"0\" role=\"slider\" aria-valuemin=\"0\" aria-valuemax=\"{{range.length}}\" aria-valuenow=\"{{value}}\">\n" +
40914 " <span ng-repeat-start=\"r in range track by $index\" class=\"sr-only\">({{ $index < value ? '*' : ' ' }})</span>\n" +
40915 " <i ng-repeat-end ng-mouseenter=\"enter($index + 1)\" ng-click=\"rate($index + 1)\" class=\"glyphicon\" ng-class=\"$index < value && (r.stateOn || 'glyphicon-star') || (r.stateOff || 'glyphicon-star-empty')\" ng-attr-title=\"{{r.title}}\" aria-valuetext=\"{{r.title}}\"></i>\n" +
40920 angular.module("uib/template/tabs/tab.html", []).run(["$templateCache", function($templateCache) {
40921 $templateCache.put("uib/template/tabs/tab.html",
40922 "<li ng-class=\"{active: active, disabled: disabled}\" class=\"uib-tab\">\n" +
40923 " <div ng-click=\"select()\" uib-tab-heading-transclude>{{heading}}</div>\n" +
40928 angular.module("uib/template/tabs/tabset.html", []).run(["$templateCache", function($templateCache) {
40929 $templateCache.put("uib/template/tabs/tabset.html",
40931 " <ul class=\"nav nav-{{type || 'tabs'}}\" ng-class=\"{'nav-stacked': vertical, 'nav-justified': justified}\" ng-transclude></ul>\n" +
40932 " <div class=\"tab-content\">\n" +
40933 " <div class=\"tab-pane\" \n" +
40934 " ng-repeat=\"tab in tabs\" \n" +
40935 " ng-class=\"{active: tab.active}\"\n" +
40936 " uib-tab-content-transclude=\"tab\">\n" +
40943 angular.module("uib/template/timepicker/timepicker.html", []).run(["$templateCache", function($templateCache) {
40944 $templateCache.put("uib/template/timepicker/timepicker.html",
40945 "<table class=\"uib-timepicker\">\n" +
40947 " <tr class=\"text-center\" ng-show=\"::showSpinners\">\n" +
40948 " <td class=\"uib-increment hours\"><a ng-click=\"incrementHours()\" ng-class=\"{disabled: noIncrementHours()}\" class=\"btn btn-link\" ng-disabled=\"noIncrementHours()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-up\"></span></a></td>\n" +
40949 " <td> </td>\n" +
40950 " <td class=\"uib-increment minutes\"><a ng-click=\"incrementMinutes()\" ng-class=\"{disabled: noIncrementMinutes()}\" class=\"btn btn-link\" ng-disabled=\"noIncrementMinutes()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-up\"></span></a></td>\n" +
40951 " <td ng-show=\"showSeconds\"> </td>\n" +
40952 " <td ng-show=\"showSeconds\" class=\"uib-increment seconds\"><a ng-click=\"incrementSeconds()\" ng-class=\"{disabled: noIncrementSeconds()}\" class=\"btn btn-link\" ng-disabled=\"noIncrementSeconds()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-up\"></span></a></td>\n" +
40953 " <td ng-show=\"showMeridian\"></td>\n" +
40956 " <td class=\"form-group uib-time hours\" ng-class=\"{'has-error': invalidHours}\">\n" +
40957 " <input style=\"width:50px;\" type=\"text\" placeholder=\"HH\" ng-model=\"hours\" ng-change=\"updateHours()\" class=\"form-control text-center\" ng-readonly=\"::readonlyInput\" maxlength=\"2\" tabindex=\"{{::tabindex}}\" ng-disabled=\"disabled\" ng-blur=\"blur()\">\n" +
40959 " <td class=\"uib-separator\">:</td>\n" +
40960 " <td class=\"form-group uib-time minutes\" ng-class=\"{'has-error': invalidMinutes}\">\n" +
40961 " <input style=\"width:50px;\" type=\"text\" placeholder=\"MM\" ng-model=\"minutes\" ng-change=\"updateMinutes()\" class=\"form-control text-center\" ng-readonly=\"::readonlyInput\" maxlength=\"2\" tabindex=\"{{::tabindex}}\" ng-disabled=\"disabled\" ng-blur=\"blur()\">\n" +
40963 " <td ng-show=\"showSeconds\" class=\"uib-separator\">:</td>\n" +
40964 " <td class=\"form-group uib-time seconds\" ng-class=\"{'has-error': invalidSeconds}\" ng-show=\"showSeconds\">\n" +
40965 " <input style=\"width:50px;\" type=\"text\" ng-model=\"seconds\" ng-change=\"updateSeconds()\" class=\"form-control text-center\" ng-readonly=\"readonlyInput\" maxlength=\"2\" tabindex=\"{{::tabindex}}\" ng-disabled=\"disabled\" ng-blur=\"blur()\">\n" +
40967 " <td ng-show=\"showMeridian\" class=\"uib-time am-pm\"><button type=\"button\" ng-class=\"{disabled: noToggleMeridian()}\" class=\"btn btn-default text-center\" ng-click=\"toggleMeridian()\" ng-disabled=\"noToggleMeridian()\" tabindex=\"{{::tabindex}}\">{{meridian}}</button></td>\n" +
40969 " <tr class=\"text-center\" ng-show=\"::showSpinners\">\n" +
40970 " <td class=\"uib-decrement hours\"><a ng-click=\"decrementHours()\" ng-class=\"{disabled: noDecrementHours()}\" class=\"btn btn-link\" ng-disabled=\"noDecrementHours()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-down\"></span></a></td>\n" +
40971 " <td> </td>\n" +
40972 " <td class=\"uib-decrement minutes\"><a ng-click=\"decrementMinutes()\" ng-class=\"{disabled: noDecrementMinutes()}\" class=\"btn btn-link\" ng-disabled=\"noDecrementMinutes()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-down\"></span></a></td>\n" +
40973 " <td ng-show=\"showSeconds\"> </td>\n" +
40974 " <td ng-show=\"showSeconds\" class=\"uib-decrement seconds\"><a ng-click=\"decrementSeconds()\" ng-class=\"{disabled: noDecrementSeconds()}\" class=\"btn btn-link\" ng-disabled=\"noDecrementSeconds()\" tabindex=\"{{::tabindex}}\"><span class=\"glyphicon glyphicon-chevron-down\"></span></a></td>\n" +
40975 " <td ng-show=\"showMeridian\"></td>\n" +
40982 angular.module("uib/template/typeahead/typeahead-match.html", []).run(["$templateCache", function($templateCache) {
40983 $templateCache.put("uib/template/typeahead/typeahead-match.html",
40984 "<a href tabindex=\"-1\" ng-bind-html=\"match.label | uibTypeaheadHighlight:query\"></a>\n" +
40988 angular.module("uib/template/typeahead/typeahead-popup.html", []).run(["$templateCache", function($templateCache) {
40989 $templateCache.put("uib/template/typeahead/typeahead-popup.html",
40990 "<ul class=\"dropdown-menu\" ng-show=\"isOpen() && !moveInProgress\" ng-style=\"{top: position().top+'px', left: position().left+'px'}\" style=\"display: block;\" role=\"listbox\" aria-hidden=\"{{!isOpen()}}\">\n" +
40991 " <li ng-repeat=\"match in matches track by $index\" ng-class=\"{active: isActive($index) }\" ng-mouseenter=\"selectActive($index)\" ng-click=\"selectMatch($index, $event)\" role=\"option\" id=\"{{::match.id}}\">\n" +
40992 " <div uib-typeahead-match index=\"$index\" match=\"match\" query=\"query\" template-url=\"templateUrl\"></div>\n" +
40997 angular.module('ui.bootstrap.carousel').run(function() {!angular.$$csp() && angular.element(document).find('head').prepend('<style type="text/css">.ng-animate.item:not(.left):not(.right){-webkit-transition:0s ease-in-out left;transition:0s ease-in-out left}</style>'); })
41001 /***/ function(module, exports) {
41006 (function (declares) {
41007 var CommandInfo = (function () {
41008 function CommandInfo(name) {
41011 return CommandInfo;
41013 declares.CommandInfo = CommandInfo;
41014 })(declares = app.declares || (app.declares = {}));
41015 })(app || (app = {}));
41019 (function (services) {
41020 var APIEndPoint = (function () {
41021 function APIEndPoint($resource, $http) {
41022 this.$resource = $resource;
41023 this.$http = $http;
41025 APIEndPoint.prototype.resource = function (endPoint, data) {
41026 var customAction = {
41032 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
41034 return this.$resource(endPoint, {}, { execute: execute });
41036 APIEndPoint.prototype.getOptionControlFile = function (command) {
41037 var endPoint = '/api/v1/optionControlFile/' + command;
41038 return this.resource(endPoint, {}).get();
41040 APIEndPoint.prototype.getFiles = function (fileId) {
41041 var endPoint = '/api/v1/workspace';
41043 endPoint += '/' + fileId;
41045 return this.resource(endPoint, {}).get();
41047 APIEndPoint.prototype.getDirectories = function () {
41048 var endPoint = '/api/v1/all/workspace/directory';
41049 return this.resource(endPoint, {}).get();
41051 APIEndPoint.prototype.getTags = function () {
41052 var endPoint = '/api/v1/tagList';
41053 return this.resource(endPoint, {}).get();
41055 APIEndPoint.prototype.getCommands = function () {
41056 var endPoint = '/api/v1/commandList';
41057 return this.resource(endPoint, {}).get();
41059 APIEndPoint.prototype.execute = function (data) {
41060 var endPoint = '/api/v1/execution';
41061 var fd = new FormData();
41062 fd.append('data', data);
41063 return this.$http.post(endPoint, fd, {
41064 headers: { 'Content-Type': undefined },
41065 transformRequest: angular.identity
41068 return APIEndPoint;
41070 services.APIEndPoint = APIEndPoint;
41071 })(services = app.services || (app.services = {}));
41072 })(app || (app = {}));
41076 (function (services) {
41077 var MyModal = (function () {
41078 function MyModal($uibModal) {
41079 this.$uibModal = $uibModal;
41080 this.modalOption = {
41087 MyModal.prototype.open = function (modalName) {
41088 if (modalName === 'SelectCommand') {
41089 this.modalOption.templateUrl = 'templates/select-command.html';
41090 this.modalOption.size = 'lg';
41092 return this.$uibModal.open(this.modalOption);
41094 MyModal.prototype.selectCommand = function () {
41095 this.modalOption.templateUrl = 'templates/select-command.html';
41096 this.modalOption.controller = 'selectCommandController';
41097 this.modalOption.controllerAs = 'c';
41098 this.modalOption.size = 'lg';
41099 return this.$uibModal.open(this.modalOption);
41101 MyModal.prototype.preview = function () {
41102 this.modalOption.templateUrl = 'templates/preview.html';
41103 this.modalOption.controller = 'previewController';
41104 this.modalOption.controllerAs = 'c';
41105 this.modalOption.size = 'lg';
41106 return this.$uibModal.open(this.modalOption);
41108 MyModal.$inject = ['$uibModal'];
41111 services.MyModal = MyModal;
41112 })(services = app.services || (app.services = {}));
41113 })(app || (app = {}));
41117 (function (directives) {
41118 var Command = (function () {
41119 function Command() {
41120 this.restrict = 'E';
41121 this.replace = true;
41123 this.controller = 'commandController';
41124 this.controllerAs = 'ctrl';
41125 this.bindToController = {
41131 this.templateUrl = 'templates/command.html';
41133 Command.Factory = function () {
41134 var directive = function () {
41135 return new Command();
41137 directive.$inject = [];
41142 directives.Command = Command;
41143 var CommandController = (function () {
41144 function CommandController(APIEndPoint, $scope, MyModal) {
41145 this.APIEndPoint = APIEndPoint;
41146 this.$scope = $scope;
41147 this.MyModal = MyModal;
41148 var controller = this;
41150 .getOptionControlFile('mrcImageNoiseAdd')
41152 .then(function (result) {
41153 controller.options = result.info;
41158 .then(function (result) {
41159 controller.dirs = result.info;
41161 this.heading = "[" + this.index + "]: dcdFilePring";
41162 this.isOpen = true;
41163 this.$scope.$on('close', function () {
41164 controller.isOpen = false;
41167 CommandController.prototype.submit = function () {
41169 angular.forEach(this.options, function (option) {
41171 name: option.option,
41174 angular.forEach(option.arg, function (arg) {
41176 if (typeof arg.input === 'object') {
41177 obj.arguments.push(arg.input.name);
41180 obj.arguments.push(arg.input);
41184 if (obj.arguments.length > 0) {
41189 command: this.name,
41190 workspace: this.workspace.fileId,
41194 .execute(JSON.stringify(execObj))
41195 .then(function (result) {
41196 console.log(result);
41199 CommandController.prototype.removeMySelf = function (index) {
41200 this.remove()(index, this.list);
41202 CommandController.prototype.reloadFiles = function () {
41204 var fileId = this.workspace.fileId;
41208 .then(function (result) {
41209 var status = result.status;
41210 if (status === 'success') {
41211 _this.files = result.info;
41214 console.log(result.message);
41218 CommandController.prototype.debug = function () {
41219 this.MyModal.preview();
41221 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
41222 return CommandController;
41224 directives.CommandController = CommandController;
41225 })(directives = app.directives || (app.directives = {}));
41226 })(app || (app = {}));
41230 (function (directives) {
41231 var HeaderMenu = (function () {
41232 function HeaderMenu() {
41233 this.restrict = 'E';
41234 this.replace = true;
41235 this.templateUrl = 'templates/header-menu.html';
41237 HeaderMenu.Factory = function () {
41238 var directive = function () {
41239 return new HeaderMenu();
41245 directives.HeaderMenu = HeaderMenu;
41246 })(directives = app.directives || (app.directives = {}));
41247 })(app || (app = {}));
41251 (function (directives) {
41252 var Option = (function () {
41253 function Option() {
41254 this.restrict = 'E';
41255 this.replace = true;
41256 this.controller = 'optionController';
41257 this.bindToController = {
41262 this.templateUrl = 'templates/option.html';
41263 this.controllerAs = 'ctrl';
41265 Option.Factory = function () {
41266 var directive = function () {
41267 return new Option();
41269 directive.$inject = [];
41274 directives.Option = Option;
41275 var OptionController = (function () {
41276 function OptionController() {
41277 var controller = this;
41278 angular.forEach(controller.info.arg, function (arg) {
41279 if (arg.initialValue) {
41280 if (arg.formType === 'number') {
41281 arg.input = parseInt(arg.initialValue);
41284 arg.input = arg.initialValue;
41289 OptionController.$inject = [];
41290 return OptionController;
41292 directives.OptionController = OptionController;
41293 })(directives = app.directives || (app.directives = {}));
41294 })(app || (app = {}));
41298 (function (directives) {
41299 var Directory = (function () {
41300 function Directory() {
41301 this.restrict = 'E';
41302 this.replace = true;
41303 this.controller = 'directoryController';
41304 this.controllerAs = 'ctrl';
41305 this.bindToController = {
41311 this.templateUrl = 'templates/directory.html';
41313 Directory.Factory = function () {
41314 var directive = function () {
41315 return new Directory();
41321 directives.Directory = Directory;
41322 var DirectoryController = (function () {
41323 function DirectoryController(APIEndPoint, $scope) {
41324 this.APIEndPoint = APIEndPoint;
41325 this.$scope = $scope;
41326 var controller = this;
41328 .getFiles(this.info.fileId)
41330 .then(function (result) {
41331 if (result.status === 'success') {
41332 controller.files = result.info;
41333 angular.forEach(result.info, function (file) {
41334 if (file.fileType === '0') {
41336 if (controller.info.path === '/') {
41337 o.path = '/' + file.name;
41340 o.path = controller.info.path + '/' + file.name;
41342 controller.add()(o, controller.list);
41349 DirectoryController.$inject = ['APIEndPoint', '$scope'];
41350 return DirectoryController;
41352 directives.DirectoryController = DirectoryController;
41353 })(directives = app.directives || (app.directives = {}));
41354 })(app || (app = {}));
41358 (function (controllers) {
41359 var Execution = (function () {
41360 function Execution(MyModal, $scope) {
41361 this.MyModal = MyModal;
41362 this.$scope = $scope;
41363 this.commandInfoList = [];
41366 Execution.prototype.add = function () {
41367 this.$scope.$broadcast('close');
41368 var commandInfoList = this.commandInfoList;
41369 var commandInstance = this.MyModal.selectCommand();
41372 .then(function (command) {
41373 commandInfoList.push(new app.declares.CommandInfo(command));
41376 Execution.prototype.open = function () {
41377 var result = this.MyModal.open('SelectCommand');
41378 console.log(result);
41380 Execution.prototype.remove = function (index, list) {
41381 list.splice(index, 1);
41383 Execution.prototype.close = function () {
41384 console.log("close");
41386 Execution.$inject = ['MyModal', '$scope'];
41389 controllers.Execution = Execution;
41390 })(controllers = app.controllers || (app.controllers = {}));
41391 })(app || (app = {}));
41395 (function (controllers) {
41396 var Workspace = (function () {
41397 function Workspace($scope, APIEndPoint, MyModal) {
41398 this.$scope = $scope;
41399 this.APIEndPoint = APIEndPoint;
41400 this.MyModal = MyModal;
41401 this.directoryList = [];
41402 var controller = this;
41403 var directoryList = this.directoryList;
41405 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
41413 directoryList.push(o);
41415 Workspace.prototype.addDirectory = function (info, directoryList) {
41416 directoryList.push(info);
41418 Workspace.prototype.debug = function () {
41419 this.MyModal.preview();
41421 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
41424 controllers.Workspace = Workspace;
41425 })(controllers = app.controllers || (app.controllers = {}));
41426 })(app || (app = {}));
41430 (function (controllers) {
41431 var History = (function () {
41432 function History($scope) {
41433 this.page = "History";
41435 History.$inject = ['$scope'];
41438 controllers.History = History;
41439 })(controllers = app.controllers || (app.controllers = {}));
41440 })(app || (app = {}));
41444 (function (controllers) {
41445 var SelectCommand = (function () {
41446 function SelectCommand($scope, APIEndPoint, $modalInstance) {
41447 this.APIEndPoint = APIEndPoint;
41448 this.$modalInstance = $modalInstance;
41449 var controller = this;
41452 .$promise.then(function (result) {
41453 controller.tags = result.info;
41457 .$promise.then(function (result) {
41458 controller.commands = result.info;
41460 this.currentTag = 'all';
41462 SelectCommand.prototype.changeTag = function (tag) {
41463 this.currentTag = tag;
41465 SelectCommand.prototype.selectCommand = function (command) {
41466 this.$modalInstance.close(command);
41468 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
41469 return SelectCommand;
41471 controllers.SelectCommand = SelectCommand;
41472 })(controllers = app.controllers || (app.controllers = {}));
41473 })(app || (app = {}));
41477 (function (controllers) {
41478 var Preview = (function () {
41479 function Preview($scope, APIEndPoint, $modalInstance) {
41480 this.APIEndPoint = APIEndPoint;
41481 this.$modalInstance = $modalInstance;
41482 var controller = this;
41483 console.log('preview');
41485 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
41488 controllers.Preview = Preview;
41489 })(controllers = app.controllers || (app.controllers = {}));
41490 })(app || (app = {}));
41492 (function (filters) {
41494 return function (commands, tag) {
41496 angular.forEach(commands, function (command) {
41498 angular.forEach(command.tags, function (value) {
41503 result.push(command);
41509 })(filters || (filters = {}));
41513 var appName = 'zephyr';
41514 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
41515 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
41516 $urlRouterProvider.otherwise('/execution');
41517 $locationProvider.html5Mode({
41522 .state('execution', {
41524 templateUrl: 'templates/execution.html',
41525 controller: 'executionController',
41528 .state('workspace', {
41530 templateUrl: 'templates/workspace.html',
41531 controller: 'workspaceController',
41534 .state('history', {
41536 templateUrl: 'templates/history.html',
41537 controller: 'historyController',
41541 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
41542 app.zephyr.filter('Tag', filters.Tag);
41543 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
41544 app.zephyr.controller('previewController', app.controllers.Preview);
41545 app.zephyr.service('MyModal', app.services.MyModal);
41546 app.zephyr.controller('executionController', app.controllers.Execution);
41547 app.zephyr.controller('workspaceController', app.controllers.Workspace);
41548 app.zephyr.controller('historyController', app.controllers.History);
41549 app.zephyr.controller('commandController', app.directives.CommandController);
41550 app.zephyr.controller('optionController', app.directives.OptionController);
41551 app.zephyr.controller('directoryController', app.directives.DirectoryController);
41552 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
41553 app.zephyr.directive('command', app.directives.Command.Factory());
41554 app.zephyr.directive('option', app.directives.Option.Factory());
41555 app.zephyr.directive('directory', app.directives.Directory.Factory());
41556 })(app || (app = {}));
41561 /***/ function(module, exports) {
41566 (function (declares) {
41567 var CommandInfo = (function () {
41568 function CommandInfo(name) {
41571 return CommandInfo;
41573 declares.CommandInfo = CommandInfo;
41574 })(declares = app.declares || (app.declares = {}));
41575 })(app || (app = {}));
41579 (function (services) {
41580 var APIEndPoint = (function () {
41581 function APIEndPoint($resource, $http) {
41582 this.$resource = $resource;
41583 this.$http = $http;
41585 APIEndPoint.prototype.resource = function (endPoint, data) {
41586 var customAction = {
41592 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
41594 return this.$resource(endPoint, {}, { execute: execute });
41596 APIEndPoint.prototype.getOptionControlFile = function (command) {
41597 var endPoint = '/api/v1/optionControlFile/' + command;
41598 return this.resource(endPoint, {}).get();
41600 APIEndPoint.prototype.getFiles = function (fileId) {
41601 var endPoint = '/api/v1/workspace';
41603 endPoint += '/' + fileId;
41605 return this.resource(endPoint, {}).get();
41607 APIEndPoint.prototype.getDirectories = function () {
41608 var endPoint = '/api/v1/all/workspace/directory';
41609 return this.resource(endPoint, {}).get();
41611 APIEndPoint.prototype.getTags = function () {
41612 var endPoint = '/api/v1/tagList';
41613 return this.resource(endPoint, {}).get();
41615 APIEndPoint.prototype.getCommands = function () {
41616 var endPoint = '/api/v1/commandList';
41617 return this.resource(endPoint, {}).get();
41619 APIEndPoint.prototype.execute = function (data) {
41620 var endPoint = '/api/v1/execution';
41621 var fd = new FormData();
41622 fd.append('data', data);
41623 return this.$http.post(endPoint, fd, {
41624 headers: { 'Content-Type': undefined },
41625 transformRequest: angular.identity
41628 return APIEndPoint;
41630 services.APIEndPoint = APIEndPoint;
41631 })(services = app.services || (app.services = {}));
41632 })(app || (app = {}));
41636 (function (services) {
41637 var MyModal = (function () {
41638 function MyModal($uibModal) {
41639 this.$uibModal = $uibModal;
41640 this.modalOption = {
41647 MyModal.prototype.open = function (modalName) {
41648 if (modalName === 'SelectCommand') {
41649 this.modalOption.templateUrl = 'templates/select-command.html';
41650 this.modalOption.size = 'lg';
41652 return this.$uibModal.open(this.modalOption);
41654 MyModal.prototype.selectCommand = function () {
41655 this.modalOption.templateUrl = 'templates/select-command.html';
41656 this.modalOption.controller = 'selectCommandController';
41657 this.modalOption.controllerAs = 'c';
41658 this.modalOption.size = 'lg';
41659 return this.$uibModal.open(this.modalOption);
41661 MyModal.prototype.preview = function () {
41662 this.modalOption.templateUrl = 'templates/preview.html';
41663 this.modalOption.controller = 'previewController';
41664 this.modalOption.controllerAs = 'c';
41665 this.modalOption.size = 'lg';
41666 return this.$uibModal.open(this.modalOption);
41668 MyModal.$inject = ['$uibModal'];
41671 services.MyModal = MyModal;
41672 })(services = app.services || (app.services = {}));
41673 })(app || (app = {}));
41677 (function (directives) {
41678 var Command = (function () {
41679 function Command() {
41680 this.restrict = 'E';
41681 this.replace = true;
41683 this.controller = 'commandController';
41684 this.controllerAs = 'ctrl';
41685 this.bindToController = {
41691 this.templateUrl = 'templates/command.html';
41693 Command.Factory = function () {
41694 var directive = function () {
41695 return new Command();
41697 directive.$inject = [];
41702 directives.Command = Command;
41703 var CommandController = (function () {
41704 function CommandController(APIEndPoint, $scope, MyModal) {
41705 this.APIEndPoint = APIEndPoint;
41706 this.$scope = $scope;
41707 this.MyModal = MyModal;
41708 var controller = this;
41710 .getOptionControlFile('mrcImageNoiseAdd')
41712 .then(function (result) {
41713 controller.options = result.info;
41718 .then(function (result) {
41719 controller.dirs = result.info;
41721 this.heading = "[" + this.index + "]: dcdFilePring";
41722 this.isOpen = true;
41723 this.$scope.$on('close', function () {
41724 controller.isOpen = false;
41727 CommandController.prototype.submit = function () {
41729 angular.forEach(this.options, function (option) {
41731 name: option.option,
41734 angular.forEach(option.arg, function (arg) {
41736 if (typeof arg.input === 'object') {
41737 obj.arguments.push(arg.input.name);
41740 obj.arguments.push(arg.input);
41744 if (obj.arguments.length > 0) {
41749 command: this.name,
41750 workspace: this.workspace.fileId,
41754 .execute(JSON.stringify(execObj))
41755 .then(function (result) {
41756 console.log(result);
41759 CommandController.prototype.removeMySelf = function (index) {
41760 this.remove()(index, this.list);
41762 CommandController.prototype.reloadFiles = function () {
41764 var fileId = this.workspace.fileId;
41768 .then(function (result) {
41769 var status = result.status;
41770 if (status === 'success') {
41771 _this.files = result.info;
41774 console.log(result.message);
41778 CommandController.prototype.debug = function () {
41779 this.MyModal.preview();
41781 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
41782 return CommandController;
41784 directives.CommandController = CommandController;
41785 })(directives = app.directives || (app.directives = {}));
41786 })(app || (app = {}));
41790 (function (directives) {
41791 var HeaderMenu = (function () {
41792 function HeaderMenu() {
41793 this.restrict = 'E';
41794 this.replace = true;
41795 this.templateUrl = 'templates/header-menu.html';
41797 HeaderMenu.Factory = function () {
41798 var directive = function () {
41799 return new HeaderMenu();
41805 directives.HeaderMenu = HeaderMenu;
41806 })(directives = app.directives || (app.directives = {}));
41807 })(app || (app = {}));
41811 (function (directives) {
41812 var Option = (function () {
41813 function Option() {
41814 this.restrict = 'E';
41815 this.replace = true;
41816 this.controller = 'optionController';
41817 this.bindToController = {
41822 this.templateUrl = 'templates/option.html';
41823 this.controllerAs = 'ctrl';
41825 Option.Factory = function () {
41826 var directive = function () {
41827 return new Option();
41829 directive.$inject = [];
41834 directives.Option = Option;
41835 var OptionController = (function () {
41836 function OptionController() {
41837 var controller = this;
41838 angular.forEach(controller.info.arg, function (arg) {
41839 if (arg.initialValue) {
41840 if (arg.formType === 'number') {
41841 arg.input = parseInt(arg.initialValue);
41844 arg.input = arg.initialValue;
41849 OptionController.$inject = [];
41850 return OptionController;
41852 directives.OptionController = OptionController;
41853 })(directives = app.directives || (app.directives = {}));
41854 })(app || (app = {}));
41858 (function (directives) {
41859 var Directory = (function () {
41860 function Directory() {
41861 this.restrict = 'E';
41862 this.replace = true;
41863 this.controller = 'directoryController';
41864 this.controllerAs = 'ctrl';
41865 this.bindToController = {
41871 this.templateUrl = 'templates/directory.html';
41873 Directory.Factory = function () {
41874 var directive = function () {
41875 return new Directory();
41881 directives.Directory = Directory;
41882 var DirectoryController = (function () {
41883 function DirectoryController(APIEndPoint, $scope) {
41884 this.APIEndPoint = APIEndPoint;
41885 this.$scope = $scope;
41886 var controller = this;
41888 .getFiles(this.info.fileId)
41890 .then(function (result) {
41891 if (result.status === 'success') {
41892 controller.files = result.info;
41893 angular.forEach(result.info, function (file) {
41894 if (file.fileType === '0') {
41896 if (controller.info.path === '/') {
41897 o.path = '/' + file.name;
41900 o.path = controller.info.path + '/' + file.name;
41902 controller.add()(o, controller.list);
41909 DirectoryController.$inject = ['APIEndPoint', '$scope'];
41910 return DirectoryController;
41912 directives.DirectoryController = DirectoryController;
41913 })(directives = app.directives || (app.directives = {}));
41914 })(app || (app = {}));
41918 (function (controllers) {
41919 var Execution = (function () {
41920 function Execution(MyModal, $scope) {
41921 this.MyModal = MyModal;
41922 this.$scope = $scope;
41923 this.commandInfoList = [];
41926 Execution.prototype.add = function () {
41927 this.$scope.$broadcast('close');
41928 var commandInfoList = this.commandInfoList;
41929 var commandInstance = this.MyModal.selectCommand();
41932 .then(function (command) {
41933 commandInfoList.push(new app.declares.CommandInfo(command));
41936 Execution.prototype.open = function () {
41937 var result = this.MyModal.open('SelectCommand');
41938 console.log(result);
41940 Execution.prototype.remove = function (index, list) {
41941 list.splice(index, 1);
41943 Execution.prototype.close = function () {
41944 console.log("close");
41946 Execution.$inject = ['MyModal', '$scope'];
41949 controllers.Execution = Execution;
41950 })(controllers = app.controllers || (app.controllers = {}));
41951 })(app || (app = {}));
41955 (function (controllers) {
41956 var Workspace = (function () {
41957 function Workspace($scope, APIEndPoint, MyModal) {
41958 this.$scope = $scope;
41959 this.APIEndPoint = APIEndPoint;
41960 this.MyModal = MyModal;
41961 this.directoryList = [];
41962 var controller = this;
41963 var directoryList = this.directoryList;
41965 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
41973 directoryList.push(o);
41975 Workspace.prototype.addDirectory = function (info, directoryList) {
41976 directoryList.push(info);
41978 Workspace.prototype.debug = function () {
41979 this.MyModal.preview();
41981 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
41984 controllers.Workspace = Workspace;
41985 })(controllers = app.controllers || (app.controllers = {}));
41986 })(app || (app = {}));
41990 (function (controllers) {
41991 var History = (function () {
41992 function History($scope) {
41993 this.page = "History";
41995 History.$inject = ['$scope'];
41998 controllers.History = History;
41999 })(controllers = app.controllers || (app.controllers = {}));
42000 })(app || (app = {}));
42004 (function (controllers) {
42005 var SelectCommand = (function () {
42006 function SelectCommand($scope, APIEndPoint, $modalInstance) {
42007 this.APIEndPoint = APIEndPoint;
42008 this.$modalInstance = $modalInstance;
42009 var controller = this;
42012 .$promise.then(function (result) {
42013 controller.tags = result.info;
42017 .$promise.then(function (result) {
42018 controller.commands = result.info;
42020 this.currentTag = 'all';
42022 SelectCommand.prototype.changeTag = function (tag) {
42023 this.currentTag = tag;
42025 SelectCommand.prototype.selectCommand = function (command) {
42026 this.$modalInstance.close(command);
42028 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
42029 return SelectCommand;
42031 controllers.SelectCommand = SelectCommand;
42032 })(controllers = app.controllers || (app.controllers = {}));
42033 })(app || (app = {}));
42037 (function (controllers) {
42038 var Preview = (function () {
42039 function Preview($scope, APIEndPoint, $modalInstance) {
42040 this.APIEndPoint = APIEndPoint;
42041 this.$modalInstance = $modalInstance;
42042 var controller = this;
42043 console.log('preview');
42045 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
42048 controllers.Preview = Preview;
42049 })(controllers = app.controllers || (app.controllers = {}));
42050 })(app || (app = {}));
42052 (function (filters) {
42054 return function (commands, tag) {
42056 angular.forEach(commands, function (command) {
42058 angular.forEach(command.tags, function (value) {
42063 result.push(command);
42069 })(filters || (filters = {}));
42073 var appName = 'zephyr';
42074 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
42075 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
42076 $urlRouterProvider.otherwise('/execution');
42077 $locationProvider.html5Mode({
42082 .state('execution', {
42084 templateUrl: 'templates/execution.html',
42085 controller: 'executionController',
42088 .state('workspace', {
42090 templateUrl: 'templates/workspace.html',
42091 controller: 'workspaceController',
42094 .state('history', {
42096 templateUrl: 'templates/history.html',
42097 controller: 'historyController',
42101 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
42102 app.zephyr.filter('Tag', filters.Tag);
42103 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
42104 app.zephyr.controller('previewController', app.controllers.Preview);
42105 app.zephyr.service('MyModal', app.services.MyModal);
42106 app.zephyr.controller('executionController', app.controllers.Execution);
42107 app.zephyr.controller('workspaceController', app.controllers.Workspace);
42108 app.zephyr.controller('historyController', app.controllers.History);
42109 app.zephyr.controller('commandController', app.directives.CommandController);
42110 app.zephyr.controller('optionController', app.directives.OptionController);
42111 app.zephyr.controller('directoryController', app.directives.DirectoryController);
42112 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
42113 app.zephyr.directive('command', app.directives.Command.Factory());
42114 app.zephyr.directive('option', app.directives.Option.Factory());
42115 app.zephyr.directive('directory', app.directives.Directory.Factory());
42116 })(app || (app = {}));
42121 /***/ function(module, exports) {
42126 (function (declares) {
42127 var CommandInfo = (function () {
42128 function CommandInfo(name) {
42131 return CommandInfo;
42133 declares.CommandInfo = CommandInfo;
42134 })(declares = app.declares || (app.declares = {}));
42135 })(app || (app = {}));
42139 (function (services) {
42140 var APIEndPoint = (function () {
42141 function APIEndPoint($resource, $http) {
42142 this.$resource = $resource;
42143 this.$http = $http;
42145 APIEndPoint.prototype.resource = function (endPoint, data) {
42146 var customAction = {
42152 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
42154 return this.$resource(endPoint, {}, { execute: execute });
42156 APIEndPoint.prototype.getOptionControlFile = function (command) {
42157 var endPoint = '/api/v1/optionControlFile/' + command;
42158 return this.resource(endPoint, {}).get();
42160 APIEndPoint.prototype.getFiles = function (fileId) {
42161 var endPoint = '/api/v1/workspace';
42163 endPoint += '/' + fileId;
42165 return this.resource(endPoint, {}).get();
42167 APIEndPoint.prototype.getDirectories = function () {
42168 var endPoint = '/api/v1/all/workspace/directory';
42169 return this.resource(endPoint, {}).get();
42171 APIEndPoint.prototype.getTags = function () {
42172 var endPoint = '/api/v1/tagList';
42173 return this.resource(endPoint, {}).get();
42175 APIEndPoint.prototype.getCommands = function () {
42176 var endPoint = '/api/v1/commandList';
42177 return this.resource(endPoint, {}).get();
42179 APIEndPoint.prototype.execute = function (data) {
42180 var endPoint = '/api/v1/execution';
42181 var fd = new FormData();
42182 fd.append('data', data);
42183 return this.$http.post(endPoint, fd, {
42184 headers: { 'Content-Type': undefined },
42185 transformRequest: angular.identity
42188 return APIEndPoint;
42190 services.APIEndPoint = APIEndPoint;
42191 })(services = app.services || (app.services = {}));
42192 })(app || (app = {}));
42196 (function (services) {
42197 var MyModal = (function () {
42198 function MyModal($uibModal) {
42199 this.$uibModal = $uibModal;
42200 this.modalOption = {
42207 MyModal.prototype.open = function (modalName) {
42208 if (modalName === 'SelectCommand') {
42209 this.modalOption.templateUrl = 'templates/select-command.html';
42210 this.modalOption.size = 'lg';
42212 return this.$uibModal.open(this.modalOption);
42214 MyModal.prototype.selectCommand = function () {
42215 this.modalOption.templateUrl = 'templates/select-command.html';
42216 this.modalOption.controller = 'selectCommandController';
42217 this.modalOption.controllerAs = 'c';
42218 this.modalOption.size = 'lg';
42219 return this.$uibModal.open(this.modalOption);
42221 MyModal.prototype.preview = function () {
42222 this.modalOption.templateUrl = 'templates/preview.html';
42223 this.modalOption.controller = 'previewController';
42224 this.modalOption.controllerAs = 'c';
42225 this.modalOption.size = 'lg';
42226 return this.$uibModal.open(this.modalOption);
42228 MyModal.$inject = ['$uibModal'];
42231 services.MyModal = MyModal;
42232 })(services = app.services || (app.services = {}));
42233 })(app || (app = {}));
42237 (function (directives) {
42238 var Command = (function () {
42239 function Command() {
42240 this.restrict = 'E';
42241 this.replace = true;
42243 this.controller = 'commandController';
42244 this.controllerAs = 'ctrl';
42245 this.bindToController = {
42251 this.templateUrl = 'templates/command.html';
42253 Command.Factory = function () {
42254 var directive = function () {
42255 return new Command();
42257 directive.$inject = [];
42262 directives.Command = Command;
42263 var CommandController = (function () {
42264 function CommandController(APIEndPoint, $scope, MyModal) {
42265 this.APIEndPoint = APIEndPoint;
42266 this.$scope = $scope;
42267 this.MyModal = MyModal;
42268 var controller = this;
42270 .getOptionControlFile('mrcImageNoiseAdd')
42272 .then(function (result) {
42273 controller.options = result.info;
42278 .then(function (result) {
42279 controller.dirs = result.info;
42281 this.heading = "[" + this.index + "]: dcdFilePring";
42282 this.isOpen = true;
42283 this.$scope.$on('close', function () {
42284 controller.isOpen = false;
42287 CommandController.prototype.submit = function () {
42289 angular.forEach(this.options, function (option) {
42291 name: option.option,
42294 angular.forEach(option.arg, function (arg) {
42296 if (typeof arg.input === 'object') {
42297 obj.arguments.push(arg.input.name);
42300 obj.arguments.push(arg.input);
42304 if (obj.arguments.length > 0) {
42309 command: this.name,
42310 workspace: this.workspace.fileId,
42314 .execute(JSON.stringify(execObj))
42315 .then(function (result) {
42316 console.log(result);
42319 CommandController.prototype.removeMySelf = function (index) {
42320 this.remove()(index, this.list);
42322 CommandController.prototype.reloadFiles = function () {
42324 var fileId = this.workspace.fileId;
42328 .then(function (result) {
42329 var status = result.status;
42330 if (status === 'success') {
42331 _this.files = result.info;
42334 console.log(result.message);
42338 CommandController.prototype.debug = function () {
42339 this.MyModal.preview();
42341 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
42342 return CommandController;
42344 directives.CommandController = CommandController;
42345 })(directives = app.directives || (app.directives = {}));
42346 })(app || (app = {}));
42350 (function (directives) {
42351 var HeaderMenu = (function () {
42352 function HeaderMenu() {
42353 this.restrict = 'E';
42354 this.replace = true;
42355 this.templateUrl = 'templates/header-menu.html';
42357 HeaderMenu.Factory = function () {
42358 var directive = function () {
42359 return new HeaderMenu();
42365 directives.HeaderMenu = HeaderMenu;
42366 })(directives = app.directives || (app.directives = {}));
42367 })(app || (app = {}));
42371 (function (directives) {
42372 var Option = (function () {
42373 function Option() {
42374 this.restrict = 'E';
42375 this.replace = true;
42376 this.controller = 'optionController';
42377 this.bindToController = {
42382 this.templateUrl = 'templates/option.html';
42383 this.controllerAs = 'ctrl';
42385 Option.Factory = function () {
42386 var directive = function () {
42387 return new Option();
42389 directive.$inject = [];
42394 directives.Option = Option;
42395 var OptionController = (function () {
42396 function OptionController() {
42397 var controller = this;
42398 angular.forEach(controller.info.arg, function (arg) {
42399 if (arg.initialValue) {
42400 if (arg.formType === 'number') {
42401 arg.input = parseInt(arg.initialValue);
42404 arg.input = arg.initialValue;
42409 OptionController.$inject = [];
42410 return OptionController;
42412 directives.OptionController = OptionController;
42413 })(directives = app.directives || (app.directives = {}));
42414 })(app || (app = {}));
42418 (function (directives) {
42419 var Directory = (function () {
42420 function Directory() {
42421 this.restrict = 'E';
42422 this.replace = true;
42423 this.controller = 'directoryController';
42424 this.controllerAs = 'ctrl';
42425 this.bindToController = {
42431 this.templateUrl = 'templates/directory.html';
42433 Directory.Factory = function () {
42434 var directive = function () {
42435 return new Directory();
42441 directives.Directory = Directory;
42442 var DirectoryController = (function () {
42443 function DirectoryController(APIEndPoint, $scope) {
42444 this.APIEndPoint = APIEndPoint;
42445 this.$scope = $scope;
42446 var controller = this;
42448 .getFiles(this.info.fileId)
42450 .then(function (result) {
42451 if (result.status === 'success') {
42452 controller.files = result.info;
42453 angular.forEach(result.info, function (file) {
42454 if (file.fileType === '0') {
42456 if (controller.info.path === '/') {
42457 o.path = '/' + file.name;
42460 o.path = controller.info.path + '/' + file.name;
42462 controller.add()(o, controller.list);
42469 DirectoryController.$inject = ['APIEndPoint', '$scope'];
42470 return DirectoryController;
42472 directives.DirectoryController = DirectoryController;
42473 })(directives = app.directives || (app.directives = {}));
42474 })(app || (app = {}));
42478 (function (controllers) {
42479 var Execution = (function () {
42480 function Execution(MyModal, $scope) {
42481 this.MyModal = MyModal;
42482 this.$scope = $scope;
42483 this.commandInfoList = [];
42486 Execution.prototype.add = function () {
42487 this.$scope.$broadcast('close');
42488 var commandInfoList = this.commandInfoList;
42489 var commandInstance = this.MyModal.selectCommand();
42492 .then(function (command) {
42493 commandInfoList.push(new app.declares.CommandInfo(command));
42496 Execution.prototype.open = function () {
42497 var result = this.MyModal.open('SelectCommand');
42498 console.log(result);
42500 Execution.prototype.remove = function (index, list) {
42501 list.splice(index, 1);
42503 Execution.prototype.close = function () {
42504 console.log("close");
42506 Execution.$inject = ['MyModal', '$scope'];
42509 controllers.Execution = Execution;
42510 })(controllers = app.controllers || (app.controllers = {}));
42511 })(app || (app = {}));
42515 (function (controllers) {
42516 var Workspace = (function () {
42517 function Workspace($scope, APIEndPoint, MyModal) {
42518 this.$scope = $scope;
42519 this.APIEndPoint = APIEndPoint;
42520 this.MyModal = MyModal;
42521 this.directoryList = [];
42522 var controller = this;
42523 var directoryList = this.directoryList;
42525 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
42533 directoryList.push(o);
42535 Workspace.prototype.addDirectory = function (info, directoryList) {
42536 directoryList.push(info);
42538 Workspace.prototype.debug = function () {
42539 this.MyModal.preview();
42541 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
42544 controllers.Workspace = Workspace;
42545 })(controllers = app.controllers || (app.controllers = {}));
42546 })(app || (app = {}));
42550 (function (controllers) {
42551 var History = (function () {
42552 function History($scope) {
42553 this.page = "History";
42555 History.$inject = ['$scope'];
42558 controllers.History = History;
42559 })(controllers = app.controllers || (app.controllers = {}));
42560 })(app || (app = {}));
42564 (function (controllers) {
42565 var SelectCommand = (function () {
42566 function SelectCommand($scope, APIEndPoint, $modalInstance) {
42567 this.APIEndPoint = APIEndPoint;
42568 this.$modalInstance = $modalInstance;
42569 var controller = this;
42572 .$promise.then(function (result) {
42573 controller.tags = result.info;
42577 .$promise.then(function (result) {
42578 controller.commands = result.info;
42580 this.currentTag = 'all';
42582 SelectCommand.prototype.changeTag = function (tag) {
42583 this.currentTag = tag;
42585 SelectCommand.prototype.selectCommand = function (command) {
42586 this.$modalInstance.close(command);
42588 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
42589 return SelectCommand;
42591 controllers.SelectCommand = SelectCommand;
42592 })(controllers = app.controllers || (app.controllers = {}));
42593 })(app || (app = {}));
42597 (function (controllers) {
42598 var Preview = (function () {
42599 function Preview($scope, APIEndPoint, $modalInstance) {
42600 this.APIEndPoint = APIEndPoint;
42601 this.$modalInstance = $modalInstance;
42602 var controller = this;
42603 console.log('preview');
42605 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
42608 controllers.Preview = Preview;
42609 })(controllers = app.controllers || (app.controllers = {}));
42610 })(app || (app = {}));
42612 (function (filters) {
42614 return function (commands, tag) {
42616 angular.forEach(commands, function (command) {
42618 angular.forEach(command.tags, function (value) {
42623 result.push(command);
42629 })(filters || (filters = {}));
42633 var appName = 'zephyr';
42634 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
42635 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
42636 $urlRouterProvider.otherwise('/execution');
42637 $locationProvider.html5Mode({
42642 .state('execution', {
42644 templateUrl: 'templates/execution.html',
42645 controller: 'executionController',
42648 .state('workspace', {
42650 templateUrl: 'templates/workspace.html',
42651 controller: 'workspaceController',
42654 .state('history', {
42656 templateUrl: 'templates/history.html',
42657 controller: 'historyController',
42661 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
42662 app.zephyr.filter('Tag', filters.Tag);
42663 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
42664 app.zephyr.controller('previewController', app.controllers.Preview);
42665 app.zephyr.service('MyModal', app.services.MyModal);
42666 app.zephyr.controller('executionController', app.controllers.Execution);
42667 app.zephyr.controller('workspaceController', app.controllers.Workspace);
42668 app.zephyr.controller('historyController', app.controllers.History);
42669 app.zephyr.controller('commandController', app.directives.CommandController);
42670 app.zephyr.controller('optionController', app.directives.OptionController);
42671 app.zephyr.controller('directoryController', app.directives.DirectoryController);
42672 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
42673 app.zephyr.directive('command', app.directives.Command.Factory());
42674 app.zephyr.directive('option', app.directives.Option.Factory());
42675 app.zephyr.directive('directory', app.directives.Directory.Factory());
42676 })(app || (app = {}));
42681 /***/ function(module, exports) {
42686 (function (declares) {
42687 var CommandInfo = (function () {
42688 function CommandInfo(name) {
42691 return CommandInfo;
42693 declares.CommandInfo = CommandInfo;
42694 })(declares = app.declares || (app.declares = {}));
42695 })(app || (app = {}));
42699 (function (services) {
42700 var APIEndPoint = (function () {
42701 function APIEndPoint($resource, $http) {
42702 this.$resource = $resource;
42703 this.$http = $http;
42705 APIEndPoint.prototype.resource = function (endPoint, data) {
42706 var customAction = {
42712 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
42714 return this.$resource(endPoint, {}, { execute: execute });
42716 APIEndPoint.prototype.getOptionControlFile = function (command) {
42717 var endPoint = '/api/v1/optionControlFile/' + command;
42718 return this.resource(endPoint, {}).get();
42720 APIEndPoint.prototype.getFiles = function (fileId) {
42721 var endPoint = '/api/v1/workspace';
42723 endPoint += '/' + fileId;
42725 return this.resource(endPoint, {}).get();
42727 APIEndPoint.prototype.getDirectories = function () {
42728 var endPoint = '/api/v1/all/workspace/directory';
42729 return this.resource(endPoint, {}).get();
42731 APIEndPoint.prototype.getTags = function () {
42732 var endPoint = '/api/v1/tagList';
42733 return this.resource(endPoint, {}).get();
42735 APIEndPoint.prototype.getCommands = function () {
42736 var endPoint = '/api/v1/commandList';
42737 return this.resource(endPoint, {}).get();
42739 APIEndPoint.prototype.execute = function (data) {
42740 var endPoint = '/api/v1/execution';
42741 var fd = new FormData();
42742 fd.append('data', data);
42743 return this.$http.post(endPoint, fd, {
42744 headers: { 'Content-Type': undefined },
42745 transformRequest: angular.identity
42748 return APIEndPoint;
42750 services.APIEndPoint = APIEndPoint;
42751 })(services = app.services || (app.services = {}));
42752 })(app || (app = {}));
42756 (function (services) {
42757 var MyModal = (function () {
42758 function MyModal($uibModal) {
42759 this.$uibModal = $uibModal;
42760 this.modalOption = {
42767 MyModal.prototype.open = function (modalName) {
42768 if (modalName === 'SelectCommand') {
42769 this.modalOption.templateUrl = 'templates/select-command.html';
42770 this.modalOption.size = 'lg';
42772 return this.$uibModal.open(this.modalOption);
42774 MyModal.prototype.selectCommand = function () {
42775 this.modalOption.templateUrl = 'templates/select-command.html';
42776 this.modalOption.controller = 'selectCommandController';
42777 this.modalOption.controllerAs = 'c';
42778 this.modalOption.size = 'lg';
42779 return this.$uibModal.open(this.modalOption);
42781 MyModal.prototype.preview = function () {
42782 this.modalOption.templateUrl = 'templates/preview.html';
42783 this.modalOption.controller = 'previewController';
42784 this.modalOption.controllerAs = 'c';
42785 this.modalOption.size = 'lg';
42786 return this.$uibModal.open(this.modalOption);
42788 MyModal.$inject = ['$uibModal'];
42791 services.MyModal = MyModal;
42792 })(services = app.services || (app.services = {}));
42793 })(app || (app = {}));
42797 (function (directives) {
42798 var Command = (function () {
42799 function Command() {
42800 this.restrict = 'E';
42801 this.replace = true;
42803 this.controller = 'commandController';
42804 this.controllerAs = 'ctrl';
42805 this.bindToController = {
42811 this.templateUrl = 'templates/command.html';
42813 Command.Factory = function () {
42814 var directive = function () {
42815 return new Command();
42817 directive.$inject = [];
42822 directives.Command = Command;
42823 var CommandController = (function () {
42824 function CommandController(APIEndPoint, $scope, MyModal) {
42825 this.APIEndPoint = APIEndPoint;
42826 this.$scope = $scope;
42827 this.MyModal = MyModal;
42828 var controller = this;
42830 .getOptionControlFile('mrcImageNoiseAdd')
42832 .then(function (result) {
42833 controller.options = result.info;
42838 .then(function (result) {
42839 controller.dirs = result.info;
42841 this.heading = "[" + this.index + "]: dcdFilePring";
42842 this.isOpen = true;
42843 this.$scope.$on('close', function () {
42844 controller.isOpen = false;
42847 CommandController.prototype.submit = function () {
42849 angular.forEach(this.options, function (option) {
42851 name: option.option,
42854 angular.forEach(option.arg, function (arg) {
42856 if (typeof arg.input === 'object') {
42857 obj.arguments.push(arg.input.name);
42860 obj.arguments.push(arg.input);
42864 if (obj.arguments.length > 0) {
42869 command: this.name,
42870 workspace: this.workspace.fileId,
42874 .execute(JSON.stringify(execObj))
42875 .then(function (result) {
42876 console.log(result);
42879 CommandController.prototype.removeMySelf = function (index) {
42880 this.remove()(index, this.list);
42882 CommandController.prototype.reloadFiles = function () {
42884 var fileId = this.workspace.fileId;
42888 .then(function (result) {
42889 var status = result.status;
42890 if (status === 'success') {
42891 _this.files = result.info;
42894 console.log(result.message);
42898 CommandController.prototype.debug = function () {
42899 this.MyModal.preview();
42901 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
42902 return CommandController;
42904 directives.CommandController = CommandController;
42905 })(directives = app.directives || (app.directives = {}));
42906 })(app || (app = {}));
42910 (function (directives) {
42911 var HeaderMenu = (function () {
42912 function HeaderMenu() {
42913 this.restrict = 'E';
42914 this.replace = true;
42915 this.templateUrl = 'templates/header-menu.html';
42917 HeaderMenu.Factory = function () {
42918 var directive = function () {
42919 return new HeaderMenu();
42925 directives.HeaderMenu = HeaderMenu;
42926 })(directives = app.directives || (app.directives = {}));
42927 })(app || (app = {}));
42931 (function (directives) {
42932 var Option = (function () {
42933 function Option() {
42934 this.restrict = 'E';
42935 this.replace = true;
42936 this.controller = 'optionController';
42937 this.bindToController = {
42942 this.templateUrl = 'templates/option.html';
42943 this.controllerAs = 'ctrl';
42945 Option.Factory = function () {
42946 var directive = function () {
42947 return new Option();
42949 directive.$inject = [];
42954 directives.Option = Option;
42955 var OptionController = (function () {
42956 function OptionController() {
42957 var controller = this;
42958 angular.forEach(controller.info.arg, function (arg) {
42959 if (arg.initialValue) {
42960 if (arg.formType === 'number') {
42961 arg.input = parseInt(arg.initialValue);
42964 arg.input = arg.initialValue;
42969 OptionController.$inject = [];
42970 return OptionController;
42972 directives.OptionController = OptionController;
42973 })(directives = app.directives || (app.directives = {}));
42974 })(app || (app = {}));
42978 (function (directives) {
42979 var Directory = (function () {
42980 function Directory() {
42981 this.restrict = 'E';
42982 this.replace = true;
42983 this.controller = 'directoryController';
42984 this.controllerAs = 'ctrl';
42985 this.bindToController = {
42991 this.templateUrl = 'templates/directory.html';
42993 Directory.Factory = function () {
42994 var directive = function () {
42995 return new Directory();
43001 directives.Directory = Directory;
43002 var DirectoryController = (function () {
43003 function DirectoryController(APIEndPoint, $scope) {
43004 this.APIEndPoint = APIEndPoint;
43005 this.$scope = $scope;
43006 var controller = this;
43008 .getFiles(this.info.fileId)
43010 .then(function (result) {
43011 if (result.status === 'success') {
43012 controller.files = result.info;
43013 angular.forEach(result.info, function (file) {
43014 if (file.fileType === '0') {
43016 if (controller.info.path === '/') {
43017 o.path = '/' + file.name;
43020 o.path = controller.info.path + '/' + file.name;
43022 controller.add()(o, controller.list);
43029 DirectoryController.$inject = ['APIEndPoint', '$scope'];
43030 return DirectoryController;
43032 directives.DirectoryController = DirectoryController;
43033 })(directives = app.directives || (app.directives = {}));
43034 })(app || (app = {}));
43038 (function (controllers) {
43039 var Execution = (function () {
43040 function Execution(MyModal, $scope) {
43041 this.MyModal = MyModal;
43042 this.$scope = $scope;
43043 this.commandInfoList = [];
43046 Execution.prototype.add = function () {
43047 this.$scope.$broadcast('close');
43048 var commandInfoList = this.commandInfoList;
43049 var commandInstance = this.MyModal.selectCommand();
43052 .then(function (command) {
43053 commandInfoList.push(new app.declares.CommandInfo(command));
43056 Execution.prototype.open = function () {
43057 var result = this.MyModal.open('SelectCommand');
43058 console.log(result);
43060 Execution.prototype.remove = function (index, list) {
43061 list.splice(index, 1);
43063 Execution.prototype.close = function () {
43064 console.log("close");
43066 Execution.$inject = ['MyModal', '$scope'];
43069 controllers.Execution = Execution;
43070 })(controllers = app.controllers || (app.controllers = {}));
43071 })(app || (app = {}));
43075 (function (controllers) {
43076 var Workspace = (function () {
43077 function Workspace($scope, APIEndPoint, MyModal) {
43078 this.$scope = $scope;
43079 this.APIEndPoint = APIEndPoint;
43080 this.MyModal = MyModal;
43081 this.directoryList = [];
43082 var controller = this;
43083 var directoryList = this.directoryList;
43085 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
43093 directoryList.push(o);
43095 Workspace.prototype.addDirectory = function (info, directoryList) {
43096 directoryList.push(info);
43098 Workspace.prototype.debug = function () {
43099 this.MyModal.preview();
43101 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
43104 controllers.Workspace = Workspace;
43105 })(controllers = app.controllers || (app.controllers = {}));
43106 })(app || (app = {}));
43110 (function (controllers) {
43111 var History = (function () {
43112 function History($scope) {
43113 this.page = "History";
43115 History.$inject = ['$scope'];
43118 controllers.History = History;
43119 })(controllers = app.controllers || (app.controllers = {}));
43120 })(app || (app = {}));
43124 (function (controllers) {
43125 var SelectCommand = (function () {
43126 function SelectCommand($scope, APIEndPoint, $modalInstance) {
43127 this.APIEndPoint = APIEndPoint;
43128 this.$modalInstance = $modalInstance;
43129 var controller = this;
43132 .$promise.then(function (result) {
43133 controller.tags = result.info;
43137 .$promise.then(function (result) {
43138 controller.commands = result.info;
43140 this.currentTag = 'all';
43142 SelectCommand.prototype.changeTag = function (tag) {
43143 this.currentTag = tag;
43145 SelectCommand.prototype.selectCommand = function (command) {
43146 this.$modalInstance.close(command);
43148 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
43149 return SelectCommand;
43151 controllers.SelectCommand = SelectCommand;
43152 })(controllers = app.controllers || (app.controllers = {}));
43153 })(app || (app = {}));
43157 (function (controllers) {
43158 var Preview = (function () {
43159 function Preview($scope, APIEndPoint, $modalInstance) {
43160 this.APIEndPoint = APIEndPoint;
43161 this.$modalInstance = $modalInstance;
43162 var controller = this;
43163 console.log('preview');
43165 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
43168 controllers.Preview = Preview;
43169 })(controllers = app.controllers || (app.controllers = {}));
43170 })(app || (app = {}));
43172 (function (filters) {
43174 return function (commands, tag) {
43176 angular.forEach(commands, function (command) {
43178 angular.forEach(command.tags, function (value) {
43183 result.push(command);
43189 })(filters || (filters = {}));
43193 var appName = 'zephyr';
43194 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
43195 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
43196 $urlRouterProvider.otherwise('/execution');
43197 $locationProvider.html5Mode({
43202 .state('execution', {
43204 templateUrl: 'templates/execution.html',
43205 controller: 'executionController',
43208 .state('workspace', {
43210 templateUrl: 'templates/workspace.html',
43211 controller: 'workspaceController',
43214 .state('history', {
43216 templateUrl: 'templates/history.html',
43217 controller: 'historyController',
43221 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
43222 app.zephyr.filter('Tag', filters.Tag);
43223 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
43224 app.zephyr.controller('previewController', app.controllers.Preview);
43225 app.zephyr.service('MyModal', app.services.MyModal);
43226 app.zephyr.controller('executionController', app.controllers.Execution);
43227 app.zephyr.controller('workspaceController', app.controllers.Workspace);
43228 app.zephyr.controller('historyController', app.controllers.History);
43229 app.zephyr.controller('commandController', app.directives.CommandController);
43230 app.zephyr.controller('optionController', app.directives.OptionController);
43231 app.zephyr.controller('directoryController', app.directives.DirectoryController);
43232 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
43233 app.zephyr.directive('command', app.directives.Command.Factory());
43234 app.zephyr.directive('option', app.directives.Option.Factory());
43235 app.zephyr.directive('directory', app.directives.Directory.Factory());
43236 })(app || (app = {}));
43241 /***/ function(module, exports) {
43246 (function (declares) {
43247 var CommandInfo = (function () {
43248 function CommandInfo(name) {
43251 return CommandInfo;
43253 declares.CommandInfo = CommandInfo;
43254 })(declares = app.declares || (app.declares = {}));
43255 })(app || (app = {}));
43259 (function (services) {
43260 var APIEndPoint = (function () {
43261 function APIEndPoint($resource, $http) {
43262 this.$resource = $resource;
43263 this.$http = $http;
43265 APIEndPoint.prototype.resource = function (endPoint, data) {
43266 var customAction = {
43272 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
43274 return this.$resource(endPoint, {}, { execute: execute });
43276 APIEndPoint.prototype.getOptionControlFile = function (command) {
43277 var endPoint = '/api/v1/optionControlFile/' + command;
43278 return this.resource(endPoint, {}).get();
43280 APIEndPoint.prototype.getFiles = function (fileId) {
43281 var endPoint = '/api/v1/workspace';
43283 endPoint += '/' + fileId;
43285 return this.resource(endPoint, {}).get();
43287 APIEndPoint.prototype.getDirectories = function () {
43288 var endPoint = '/api/v1/all/workspace/directory';
43289 return this.resource(endPoint, {}).get();
43291 APIEndPoint.prototype.getTags = function () {
43292 var endPoint = '/api/v1/tagList';
43293 return this.resource(endPoint, {}).get();
43295 APIEndPoint.prototype.getCommands = function () {
43296 var endPoint = '/api/v1/commandList';
43297 return this.resource(endPoint, {}).get();
43299 APIEndPoint.prototype.execute = function (data) {
43300 var endPoint = '/api/v1/execution';
43301 var fd = new FormData();
43302 fd.append('data', data);
43303 return this.$http.post(endPoint, fd, {
43304 headers: { 'Content-Type': undefined },
43305 transformRequest: angular.identity
43308 return APIEndPoint;
43310 services.APIEndPoint = APIEndPoint;
43311 })(services = app.services || (app.services = {}));
43312 })(app || (app = {}));
43316 (function (services) {
43317 var MyModal = (function () {
43318 function MyModal($uibModal) {
43319 this.$uibModal = $uibModal;
43320 this.modalOption = {
43327 MyModal.prototype.open = function (modalName) {
43328 if (modalName === 'SelectCommand') {
43329 this.modalOption.templateUrl = 'templates/select-command.html';
43330 this.modalOption.size = 'lg';
43332 return this.$uibModal.open(this.modalOption);
43334 MyModal.prototype.selectCommand = function () {
43335 this.modalOption.templateUrl = 'templates/select-command.html';
43336 this.modalOption.controller = 'selectCommandController';
43337 this.modalOption.controllerAs = 'c';
43338 this.modalOption.size = 'lg';
43339 return this.$uibModal.open(this.modalOption);
43341 MyModal.prototype.preview = function () {
43342 this.modalOption.templateUrl = 'templates/preview.html';
43343 this.modalOption.controller = 'previewController';
43344 this.modalOption.controllerAs = 'c';
43345 this.modalOption.size = 'lg';
43346 return this.$uibModal.open(this.modalOption);
43348 MyModal.$inject = ['$uibModal'];
43351 services.MyModal = MyModal;
43352 })(services = app.services || (app.services = {}));
43353 })(app || (app = {}));
43357 (function (directives) {
43358 var Command = (function () {
43359 function Command() {
43360 this.restrict = 'E';
43361 this.replace = true;
43363 this.controller = 'commandController';
43364 this.controllerAs = 'ctrl';
43365 this.bindToController = {
43371 this.templateUrl = 'templates/command.html';
43373 Command.Factory = function () {
43374 var directive = function () {
43375 return new Command();
43377 directive.$inject = [];
43382 directives.Command = Command;
43383 var CommandController = (function () {
43384 function CommandController(APIEndPoint, $scope, MyModal) {
43385 this.APIEndPoint = APIEndPoint;
43386 this.$scope = $scope;
43387 this.MyModal = MyModal;
43388 var controller = this;
43390 .getOptionControlFile('mrcImageNoiseAdd')
43392 .then(function (result) {
43393 controller.options = result.info;
43398 .then(function (result) {
43399 controller.dirs = result.info;
43401 this.heading = "[" + this.index + "]: dcdFilePring";
43402 this.isOpen = true;
43403 this.$scope.$on('close', function () {
43404 controller.isOpen = false;
43407 CommandController.prototype.submit = function () {
43409 angular.forEach(this.options, function (option) {
43411 name: option.option,
43414 angular.forEach(option.arg, function (arg) {
43416 if (typeof arg.input === 'object') {
43417 obj.arguments.push(arg.input.name);
43420 obj.arguments.push(arg.input);
43424 if (obj.arguments.length > 0) {
43429 command: this.name,
43430 workspace: this.workspace.fileId,
43434 .execute(JSON.stringify(execObj))
43435 .then(function (result) {
43436 console.log(result);
43439 CommandController.prototype.removeMySelf = function (index) {
43440 this.remove()(index, this.list);
43442 CommandController.prototype.reloadFiles = function () {
43444 var fileId = this.workspace.fileId;
43448 .then(function (result) {
43449 var status = result.status;
43450 if (status === 'success') {
43451 _this.files = result.info;
43454 console.log(result.message);
43458 CommandController.prototype.debug = function () {
43459 this.MyModal.preview();
43461 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
43462 return CommandController;
43464 directives.CommandController = CommandController;
43465 })(directives = app.directives || (app.directives = {}));
43466 })(app || (app = {}));
43470 (function (directives) {
43471 var HeaderMenu = (function () {
43472 function HeaderMenu() {
43473 this.restrict = 'E';
43474 this.replace = true;
43475 this.templateUrl = 'templates/header-menu.html';
43477 HeaderMenu.Factory = function () {
43478 var directive = function () {
43479 return new HeaderMenu();
43485 directives.HeaderMenu = HeaderMenu;
43486 })(directives = app.directives || (app.directives = {}));
43487 })(app || (app = {}));
43491 (function (directives) {
43492 var Option = (function () {
43493 function Option() {
43494 this.restrict = 'E';
43495 this.replace = true;
43496 this.controller = 'optionController';
43497 this.bindToController = {
43502 this.templateUrl = 'templates/option.html';
43503 this.controllerAs = 'ctrl';
43505 Option.Factory = function () {
43506 var directive = function () {
43507 return new Option();
43509 directive.$inject = [];
43514 directives.Option = Option;
43515 var OptionController = (function () {
43516 function OptionController() {
43517 var controller = this;
43518 angular.forEach(controller.info.arg, function (arg) {
43519 if (arg.initialValue) {
43520 if (arg.formType === 'number') {
43521 arg.input = parseInt(arg.initialValue);
43524 arg.input = arg.initialValue;
43529 OptionController.$inject = [];
43530 return OptionController;
43532 directives.OptionController = OptionController;
43533 })(directives = app.directives || (app.directives = {}));
43534 })(app || (app = {}));
43538 (function (directives) {
43539 var Directory = (function () {
43540 function Directory() {
43541 this.restrict = 'E';
43542 this.replace = true;
43543 this.controller = 'directoryController';
43544 this.controllerAs = 'ctrl';
43545 this.bindToController = {
43551 this.templateUrl = 'templates/directory.html';
43553 Directory.Factory = function () {
43554 var directive = function () {
43555 return new Directory();
43561 directives.Directory = Directory;
43562 var DirectoryController = (function () {
43563 function DirectoryController(APIEndPoint, $scope) {
43564 this.APIEndPoint = APIEndPoint;
43565 this.$scope = $scope;
43566 var controller = this;
43568 .getFiles(this.info.fileId)
43570 .then(function (result) {
43571 if (result.status === 'success') {
43572 controller.files = result.info;
43573 angular.forEach(result.info, function (file) {
43574 if (file.fileType === '0') {
43576 if (controller.info.path === '/') {
43577 o.path = '/' + file.name;
43580 o.path = controller.info.path + '/' + file.name;
43582 controller.add()(o, controller.list);
43589 DirectoryController.$inject = ['APIEndPoint', '$scope'];
43590 return DirectoryController;
43592 directives.DirectoryController = DirectoryController;
43593 })(directives = app.directives || (app.directives = {}));
43594 })(app || (app = {}));
43598 (function (controllers) {
43599 var Execution = (function () {
43600 function Execution(MyModal, $scope) {
43601 this.MyModal = MyModal;
43602 this.$scope = $scope;
43603 this.commandInfoList = [];
43606 Execution.prototype.add = function () {
43607 this.$scope.$broadcast('close');
43608 var commandInfoList = this.commandInfoList;
43609 var commandInstance = this.MyModal.selectCommand();
43612 .then(function (command) {
43613 commandInfoList.push(new app.declares.CommandInfo(command));
43616 Execution.prototype.open = function () {
43617 var result = this.MyModal.open('SelectCommand');
43618 console.log(result);
43620 Execution.prototype.remove = function (index, list) {
43621 list.splice(index, 1);
43623 Execution.prototype.close = function () {
43624 console.log("close");
43626 Execution.$inject = ['MyModal', '$scope'];
43629 controllers.Execution = Execution;
43630 })(controllers = app.controllers || (app.controllers = {}));
43631 })(app || (app = {}));
43635 (function (controllers) {
43636 var Workspace = (function () {
43637 function Workspace($scope, APIEndPoint, MyModal) {
43638 this.$scope = $scope;
43639 this.APIEndPoint = APIEndPoint;
43640 this.MyModal = MyModal;
43641 this.directoryList = [];
43642 var controller = this;
43643 var directoryList = this.directoryList;
43645 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
43653 directoryList.push(o);
43655 Workspace.prototype.addDirectory = function (info, directoryList) {
43656 directoryList.push(info);
43658 Workspace.prototype.debug = function () {
43659 this.MyModal.preview();
43661 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
43664 controllers.Workspace = Workspace;
43665 })(controllers = app.controllers || (app.controllers = {}));
43666 })(app || (app = {}));
43670 (function (controllers) {
43671 var History = (function () {
43672 function History($scope) {
43673 this.page = "History";
43675 History.$inject = ['$scope'];
43678 controllers.History = History;
43679 })(controllers = app.controllers || (app.controllers = {}));
43680 })(app || (app = {}));
43684 (function (controllers) {
43685 var SelectCommand = (function () {
43686 function SelectCommand($scope, APIEndPoint, $modalInstance) {
43687 this.APIEndPoint = APIEndPoint;
43688 this.$modalInstance = $modalInstance;
43689 var controller = this;
43692 .$promise.then(function (result) {
43693 controller.tags = result.info;
43697 .$promise.then(function (result) {
43698 controller.commands = result.info;
43700 this.currentTag = 'all';
43702 SelectCommand.prototype.changeTag = function (tag) {
43703 this.currentTag = tag;
43705 SelectCommand.prototype.selectCommand = function (command) {
43706 this.$modalInstance.close(command);
43708 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
43709 return SelectCommand;
43711 controllers.SelectCommand = SelectCommand;
43712 })(controllers = app.controllers || (app.controllers = {}));
43713 })(app || (app = {}));
43717 (function (controllers) {
43718 var Preview = (function () {
43719 function Preview($scope, APIEndPoint, $modalInstance) {
43720 this.APIEndPoint = APIEndPoint;
43721 this.$modalInstance = $modalInstance;
43722 var controller = this;
43723 console.log('preview');
43725 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
43728 controllers.Preview = Preview;
43729 })(controllers = app.controllers || (app.controllers = {}));
43730 })(app || (app = {}));
43732 (function (filters) {
43734 return function (commands, tag) {
43736 angular.forEach(commands, function (command) {
43738 angular.forEach(command.tags, function (value) {
43743 result.push(command);
43749 })(filters || (filters = {}));
43753 var appName = 'zephyr';
43754 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
43755 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
43756 $urlRouterProvider.otherwise('/execution');
43757 $locationProvider.html5Mode({
43762 .state('execution', {
43764 templateUrl: 'templates/execution.html',
43765 controller: 'executionController',
43768 .state('workspace', {
43770 templateUrl: 'templates/workspace.html',
43771 controller: 'workspaceController',
43774 .state('history', {
43776 templateUrl: 'templates/history.html',
43777 controller: 'historyController',
43781 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
43782 app.zephyr.filter('Tag', filters.Tag);
43783 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
43784 app.zephyr.controller('previewController', app.controllers.Preview);
43785 app.zephyr.service('MyModal', app.services.MyModal);
43786 app.zephyr.controller('executionController', app.controllers.Execution);
43787 app.zephyr.controller('workspaceController', app.controllers.Workspace);
43788 app.zephyr.controller('historyController', app.controllers.History);
43789 app.zephyr.controller('commandController', app.directives.CommandController);
43790 app.zephyr.controller('optionController', app.directives.OptionController);
43791 app.zephyr.controller('directoryController', app.directives.DirectoryController);
43792 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
43793 app.zephyr.directive('command', app.directives.Command.Factory());
43794 app.zephyr.directive('option', app.directives.Option.Factory());
43795 app.zephyr.directive('directory', app.directives.Directory.Factory());
43796 })(app || (app = {}));
43801 /***/ function(module, exports) {
43806 (function (declares) {
43807 var CommandInfo = (function () {
43808 function CommandInfo(name) {
43811 return CommandInfo;
43813 declares.CommandInfo = CommandInfo;
43814 })(declares = app.declares || (app.declares = {}));
43815 })(app || (app = {}));
43819 (function (services) {
43820 var APIEndPoint = (function () {
43821 function APIEndPoint($resource, $http) {
43822 this.$resource = $resource;
43823 this.$http = $http;
43825 APIEndPoint.prototype.resource = function (endPoint, data) {
43826 var customAction = {
43832 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
43834 return this.$resource(endPoint, {}, { execute: execute });
43836 APIEndPoint.prototype.getOptionControlFile = function (command) {
43837 var endPoint = '/api/v1/optionControlFile/' + command;
43838 return this.resource(endPoint, {}).get();
43840 APIEndPoint.prototype.getFiles = function (fileId) {
43841 var endPoint = '/api/v1/workspace';
43843 endPoint += '/' + fileId;
43845 return this.resource(endPoint, {}).get();
43847 APIEndPoint.prototype.getDirectories = function () {
43848 var endPoint = '/api/v1/all/workspace/directory';
43849 return this.resource(endPoint, {}).get();
43851 APIEndPoint.prototype.getTags = function () {
43852 var endPoint = '/api/v1/tagList';
43853 return this.resource(endPoint, {}).get();
43855 APIEndPoint.prototype.getCommands = function () {
43856 var endPoint = '/api/v1/commandList';
43857 return this.resource(endPoint, {}).get();
43859 APIEndPoint.prototype.execute = function (data) {
43860 var endPoint = '/api/v1/execution';
43861 var fd = new FormData();
43862 fd.append('data', data);
43863 return this.$http.post(endPoint, fd, {
43864 headers: { 'Content-Type': undefined },
43865 transformRequest: angular.identity
43868 return APIEndPoint;
43870 services.APIEndPoint = APIEndPoint;
43871 })(services = app.services || (app.services = {}));
43872 })(app || (app = {}));
43876 (function (services) {
43877 var MyModal = (function () {
43878 function MyModal($uibModal) {
43879 this.$uibModal = $uibModal;
43880 this.modalOption = {
43887 MyModal.prototype.open = function (modalName) {
43888 if (modalName === 'SelectCommand') {
43889 this.modalOption.templateUrl = 'templates/select-command.html';
43890 this.modalOption.size = 'lg';
43892 return this.$uibModal.open(this.modalOption);
43894 MyModal.prototype.selectCommand = function () {
43895 this.modalOption.templateUrl = 'templates/select-command.html';
43896 this.modalOption.controller = 'selectCommandController';
43897 this.modalOption.controllerAs = 'c';
43898 this.modalOption.size = 'lg';
43899 return this.$uibModal.open(this.modalOption);
43901 MyModal.prototype.preview = function () {
43902 this.modalOption.templateUrl = 'templates/preview.html';
43903 this.modalOption.controller = 'previewController';
43904 this.modalOption.controllerAs = 'c';
43905 this.modalOption.size = 'lg';
43906 return this.$uibModal.open(this.modalOption);
43908 MyModal.$inject = ['$uibModal'];
43911 services.MyModal = MyModal;
43912 })(services = app.services || (app.services = {}));
43913 })(app || (app = {}));
43917 (function (directives) {
43918 var Command = (function () {
43919 function Command() {
43920 this.restrict = 'E';
43921 this.replace = true;
43923 this.controller = 'commandController';
43924 this.controllerAs = 'ctrl';
43925 this.bindToController = {
43931 this.templateUrl = 'templates/command.html';
43933 Command.Factory = function () {
43934 var directive = function () {
43935 return new Command();
43937 directive.$inject = [];
43942 directives.Command = Command;
43943 var CommandController = (function () {
43944 function CommandController(APIEndPoint, $scope, MyModal) {
43945 this.APIEndPoint = APIEndPoint;
43946 this.$scope = $scope;
43947 this.MyModal = MyModal;
43948 var controller = this;
43950 .getOptionControlFile('mrcImageNoiseAdd')
43952 .then(function (result) {
43953 controller.options = result.info;
43958 .then(function (result) {
43959 controller.dirs = result.info;
43961 this.heading = "[" + this.index + "]: dcdFilePring";
43962 this.isOpen = true;
43963 this.$scope.$on('close', function () {
43964 controller.isOpen = false;
43967 CommandController.prototype.submit = function () {
43969 angular.forEach(this.options, function (option) {
43971 name: option.option,
43974 angular.forEach(option.arg, function (arg) {
43976 if (typeof arg.input === 'object') {
43977 obj.arguments.push(arg.input.name);
43980 obj.arguments.push(arg.input);
43984 if (obj.arguments.length > 0) {
43989 command: this.name,
43990 workspace: this.workspace.fileId,
43994 .execute(JSON.stringify(execObj))
43995 .then(function (result) {
43996 console.log(result);
43999 CommandController.prototype.removeMySelf = function (index) {
44000 this.remove()(index, this.list);
44002 CommandController.prototype.reloadFiles = function () {
44004 var fileId = this.workspace.fileId;
44008 .then(function (result) {
44009 var status = result.status;
44010 if (status === 'success') {
44011 _this.files = result.info;
44014 console.log(result.message);
44018 CommandController.prototype.debug = function () {
44019 this.MyModal.preview();
44021 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
44022 return CommandController;
44024 directives.CommandController = CommandController;
44025 })(directives = app.directives || (app.directives = {}));
44026 })(app || (app = {}));
44030 (function (directives) {
44031 var HeaderMenu = (function () {
44032 function HeaderMenu() {
44033 this.restrict = 'E';
44034 this.replace = true;
44035 this.templateUrl = 'templates/header-menu.html';
44037 HeaderMenu.Factory = function () {
44038 var directive = function () {
44039 return new HeaderMenu();
44045 directives.HeaderMenu = HeaderMenu;
44046 })(directives = app.directives || (app.directives = {}));
44047 })(app || (app = {}));
44051 (function (directives) {
44052 var Option = (function () {
44053 function Option() {
44054 this.restrict = 'E';
44055 this.replace = true;
44056 this.controller = 'optionController';
44057 this.bindToController = {
44062 this.templateUrl = 'templates/option.html';
44063 this.controllerAs = 'ctrl';
44065 Option.Factory = function () {
44066 var directive = function () {
44067 return new Option();
44069 directive.$inject = [];
44074 directives.Option = Option;
44075 var OptionController = (function () {
44076 function OptionController() {
44077 var controller = this;
44078 angular.forEach(controller.info.arg, function (arg) {
44079 if (arg.initialValue) {
44080 if (arg.formType === 'number') {
44081 arg.input = parseInt(arg.initialValue);
44084 arg.input = arg.initialValue;
44089 OptionController.$inject = [];
44090 return OptionController;
44092 directives.OptionController = OptionController;
44093 })(directives = app.directives || (app.directives = {}));
44094 })(app || (app = {}));
44098 (function (directives) {
44099 var Directory = (function () {
44100 function Directory() {
44101 this.restrict = 'E';
44102 this.replace = true;
44103 this.controller = 'directoryController';
44104 this.controllerAs = 'ctrl';
44105 this.bindToController = {
44111 this.templateUrl = 'templates/directory.html';
44113 Directory.Factory = function () {
44114 var directive = function () {
44115 return new Directory();
44121 directives.Directory = Directory;
44122 var DirectoryController = (function () {
44123 function DirectoryController(APIEndPoint, $scope) {
44124 this.APIEndPoint = APIEndPoint;
44125 this.$scope = $scope;
44126 var controller = this;
44128 .getFiles(this.info.fileId)
44130 .then(function (result) {
44131 if (result.status === 'success') {
44132 controller.files = result.info;
44133 angular.forEach(result.info, function (file) {
44134 if (file.fileType === '0') {
44136 if (controller.info.path === '/') {
44137 o.path = '/' + file.name;
44140 o.path = controller.info.path + '/' + file.name;
44142 controller.add()(o, controller.list);
44149 DirectoryController.$inject = ['APIEndPoint', '$scope'];
44150 return DirectoryController;
44152 directives.DirectoryController = DirectoryController;
44153 })(directives = app.directives || (app.directives = {}));
44154 })(app || (app = {}));
44158 (function (controllers) {
44159 var Execution = (function () {
44160 function Execution(MyModal, $scope) {
44161 this.MyModal = MyModal;
44162 this.$scope = $scope;
44163 this.commandInfoList = [];
44166 Execution.prototype.add = function () {
44167 this.$scope.$broadcast('close');
44168 var commandInfoList = this.commandInfoList;
44169 var commandInstance = this.MyModal.selectCommand();
44172 .then(function (command) {
44173 commandInfoList.push(new app.declares.CommandInfo(command));
44176 Execution.prototype.open = function () {
44177 var result = this.MyModal.open('SelectCommand');
44178 console.log(result);
44180 Execution.prototype.remove = function (index, list) {
44181 list.splice(index, 1);
44183 Execution.prototype.close = function () {
44184 console.log("close");
44186 Execution.$inject = ['MyModal', '$scope'];
44189 controllers.Execution = Execution;
44190 })(controllers = app.controllers || (app.controllers = {}));
44191 })(app || (app = {}));
44195 (function (controllers) {
44196 var Workspace = (function () {
44197 function Workspace($scope, APIEndPoint, MyModal) {
44198 this.$scope = $scope;
44199 this.APIEndPoint = APIEndPoint;
44200 this.MyModal = MyModal;
44201 this.directoryList = [];
44202 var controller = this;
44203 var directoryList = this.directoryList;
44205 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
44213 directoryList.push(o);
44215 Workspace.prototype.addDirectory = function (info, directoryList) {
44216 directoryList.push(info);
44218 Workspace.prototype.debug = function () {
44219 this.MyModal.preview();
44221 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
44224 controllers.Workspace = Workspace;
44225 })(controllers = app.controllers || (app.controllers = {}));
44226 })(app || (app = {}));
44230 (function (controllers) {
44231 var History = (function () {
44232 function History($scope) {
44233 this.page = "History";
44235 History.$inject = ['$scope'];
44238 controllers.History = History;
44239 })(controllers = app.controllers || (app.controllers = {}));
44240 })(app || (app = {}));
44244 (function (controllers) {
44245 var SelectCommand = (function () {
44246 function SelectCommand($scope, APIEndPoint, $modalInstance) {
44247 this.APIEndPoint = APIEndPoint;
44248 this.$modalInstance = $modalInstance;
44249 var controller = this;
44252 .$promise.then(function (result) {
44253 controller.tags = result.info;
44257 .$promise.then(function (result) {
44258 controller.commands = result.info;
44260 this.currentTag = 'all';
44262 SelectCommand.prototype.changeTag = function (tag) {
44263 this.currentTag = tag;
44265 SelectCommand.prototype.selectCommand = function (command) {
44266 this.$modalInstance.close(command);
44268 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
44269 return SelectCommand;
44271 controllers.SelectCommand = SelectCommand;
44272 })(controllers = app.controllers || (app.controllers = {}));
44273 })(app || (app = {}));
44277 (function (controllers) {
44278 var Preview = (function () {
44279 function Preview($scope, APIEndPoint, $modalInstance) {
44280 this.APIEndPoint = APIEndPoint;
44281 this.$modalInstance = $modalInstance;
44282 var controller = this;
44283 console.log('preview');
44285 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
44288 controllers.Preview = Preview;
44289 })(controllers = app.controllers || (app.controllers = {}));
44290 })(app || (app = {}));
44292 (function (filters) {
44294 return function (commands, tag) {
44296 angular.forEach(commands, function (command) {
44298 angular.forEach(command.tags, function (value) {
44303 result.push(command);
44309 })(filters || (filters = {}));
44313 var appName = 'zephyr';
44314 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
44315 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
44316 $urlRouterProvider.otherwise('/execution');
44317 $locationProvider.html5Mode({
44322 .state('execution', {
44324 templateUrl: 'templates/execution.html',
44325 controller: 'executionController',
44328 .state('workspace', {
44330 templateUrl: 'templates/workspace.html',
44331 controller: 'workspaceController',
44334 .state('history', {
44336 templateUrl: 'templates/history.html',
44337 controller: 'historyController',
44341 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
44342 app.zephyr.filter('Tag', filters.Tag);
44343 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
44344 app.zephyr.controller('previewController', app.controllers.Preview);
44345 app.zephyr.service('MyModal', app.services.MyModal);
44346 app.zephyr.controller('executionController', app.controllers.Execution);
44347 app.zephyr.controller('workspaceController', app.controllers.Workspace);
44348 app.zephyr.controller('historyController', app.controllers.History);
44349 app.zephyr.controller('commandController', app.directives.CommandController);
44350 app.zephyr.controller('optionController', app.directives.OptionController);
44351 app.zephyr.controller('directoryController', app.directives.DirectoryController);
44352 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
44353 app.zephyr.directive('command', app.directives.Command.Factory());
44354 app.zephyr.directive('option', app.directives.Option.Factory());
44355 app.zephyr.directive('directory', app.directives.Directory.Factory());
44356 })(app || (app = {}));
44361 /***/ function(module, exports) {
44366 (function (declares) {
44367 var CommandInfo = (function () {
44368 function CommandInfo(name) {
44371 return CommandInfo;
44373 declares.CommandInfo = CommandInfo;
44374 })(declares = app.declares || (app.declares = {}));
44375 })(app || (app = {}));
44379 (function (services) {
44380 var APIEndPoint = (function () {
44381 function APIEndPoint($resource, $http) {
44382 this.$resource = $resource;
44383 this.$http = $http;
44385 APIEndPoint.prototype.resource = function (endPoint, data) {
44386 var customAction = {
44392 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
44394 return this.$resource(endPoint, {}, { execute: execute });
44396 APIEndPoint.prototype.getOptionControlFile = function (command) {
44397 var endPoint = '/api/v1/optionControlFile/' + command;
44398 return this.resource(endPoint, {}).get();
44400 APIEndPoint.prototype.getFiles = function (fileId) {
44401 var endPoint = '/api/v1/workspace';
44403 endPoint += '/' + fileId;
44405 return this.resource(endPoint, {}).get();
44407 APIEndPoint.prototype.getDirectories = function () {
44408 var endPoint = '/api/v1/all/workspace/directory';
44409 return this.resource(endPoint, {}).get();
44411 APIEndPoint.prototype.getTags = function () {
44412 var endPoint = '/api/v1/tagList';
44413 return this.resource(endPoint, {}).get();
44415 APIEndPoint.prototype.getCommands = function () {
44416 var endPoint = '/api/v1/commandList';
44417 return this.resource(endPoint, {}).get();
44419 APIEndPoint.prototype.execute = function (data) {
44420 var endPoint = '/api/v1/execution';
44421 var fd = new FormData();
44422 fd.append('data', data);
44423 return this.$http.post(endPoint, fd, {
44424 headers: { 'Content-Type': undefined },
44425 transformRequest: angular.identity
44428 return APIEndPoint;
44430 services.APIEndPoint = APIEndPoint;
44431 })(services = app.services || (app.services = {}));
44432 })(app || (app = {}));
44436 (function (services) {
44437 var MyModal = (function () {
44438 function MyModal($uibModal) {
44439 this.$uibModal = $uibModal;
44440 this.modalOption = {
44447 MyModal.prototype.open = function (modalName) {
44448 if (modalName === 'SelectCommand') {
44449 this.modalOption.templateUrl = 'templates/select-command.html';
44450 this.modalOption.size = 'lg';
44452 return this.$uibModal.open(this.modalOption);
44454 MyModal.prototype.selectCommand = function () {
44455 this.modalOption.templateUrl = 'templates/select-command.html';
44456 this.modalOption.controller = 'selectCommandController';
44457 this.modalOption.controllerAs = 'c';
44458 this.modalOption.size = 'lg';
44459 return this.$uibModal.open(this.modalOption);
44461 MyModal.prototype.preview = function () {
44462 this.modalOption.templateUrl = 'templates/preview.html';
44463 this.modalOption.controller = 'previewController';
44464 this.modalOption.controllerAs = 'c';
44465 this.modalOption.size = 'lg';
44466 return this.$uibModal.open(this.modalOption);
44468 MyModal.$inject = ['$uibModal'];
44471 services.MyModal = MyModal;
44472 })(services = app.services || (app.services = {}));
44473 })(app || (app = {}));
44477 (function (directives) {
44478 var Command = (function () {
44479 function Command() {
44480 this.restrict = 'E';
44481 this.replace = true;
44483 this.controller = 'commandController';
44484 this.controllerAs = 'ctrl';
44485 this.bindToController = {
44491 this.templateUrl = 'templates/command.html';
44493 Command.Factory = function () {
44494 var directive = function () {
44495 return new Command();
44497 directive.$inject = [];
44502 directives.Command = Command;
44503 var CommandController = (function () {
44504 function CommandController(APIEndPoint, $scope, MyModal) {
44505 this.APIEndPoint = APIEndPoint;
44506 this.$scope = $scope;
44507 this.MyModal = MyModal;
44508 var controller = this;
44510 .getOptionControlFile('mrcImageNoiseAdd')
44512 .then(function (result) {
44513 controller.options = result.info;
44518 .then(function (result) {
44519 controller.dirs = result.info;
44521 this.heading = "[" + this.index + "]: dcdFilePring";
44522 this.isOpen = true;
44523 this.$scope.$on('close', function () {
44524 controller.isOpen = false;
44527 CommandController.prototype.submit = function () {
44529 angular.forEach(this.options, function (option) {
44531 name: option.option,
44534 angular.forEach(option.arg, function (arg) {
44536 if (typeof arg.input === 'object') {
44537 obj.arguments.push(arg.input.name);
44540 obj.arguments.push(arg.input);
44544 if (obj.arguments.length > 0) {
44549 command: this.name,
44550 workspace: this.workspace.fileId,
44554 .execute(JSON.stringify(execObj))
44555 .then(function (result) {
44556 console.log(result);
44559 CommandController.prototype.removeMySelf = function (index) {
44560 this.remove()(index, this.list);
44562 CommandController.prototype.reloadFiles = function () {
44564 var fileId = this.workspace.fileId;
44568 .then(function (result) {
44569 var status = result.status;
44570 if (status === 'success') {
44571 _this.files = result.info;
44574 console.log(result.message);
44578 CommandController.prototype.debug = function () {
44579 this.MyModal.preview();
44581 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
44582 return CommandController;
44584 directives.CommandController = CommandController;
44585 })(directives = app.directives || (app.directives = {}));
44586 })(app || (app = {}));
44590 (function (directives) {
44591 var HeaderMenu = (function () {
44592 function HeaderMenu() {
44593 this.restrict = 'E';
44594 this.replace = true;
44595 this.templateUrl = 'templates/header-menu.html';
44597 HeaderMenu.Factory = function () {
44598 var directive = function () {
44599 return new HeaderMenu();
44605 directives.HeaderMenu = HeaderMenu;
44606 })(directives = app.directives || (app.directives = {}));
44607 })(app || (app = {}));
44611 (function (directives) {
44612 var Option = (function () {
44613 function Option() {
44614 this.restrict = 'E';
44615 this.replace = true;
44616 this.controller = 'optionController';
44617 this.bindToController = {
44622 this.templateUrl = 'templates/option.html';
44623 this.controllerAs = 'ctrl';
44625 Option.Factory = function () {
44626 var directive = function () {
44627 return new Option();
44629 directive.$inject = [];
44634 directives.Option = Option;
44635 var OptionController = (function () {
44636 function OptionController() {
44637 var controller = this;
44638 angular.forEach(controller.info.arg, function (arg) {
44639 if (arg.initialValue) {
44640 if (arg.formType === 'number') {
44641 arg.input = parseInt(arg.initialValue);
44644 arg.input = arg.initialValue;
44649 OptionController.$inject = [];
44650 return OptionController;
44652 directives.OptionController = OptionController;
44653 })(directives = app.directives || (app.directives = {}));
44654 })(app || (app = {}));
44658 (function (directives) {
44659 var Directory = (function () {
44660 function Directory() {
44661 this.restrict = 'E';
44662 this.replace = true;
44663 this.controller = 'directoryController';
44664 this.controllerAs = 'ctrl';
44665 this.bindToController = {
44671 this.templateUrl = 'templates/directory.html';
44673 Directory.Factory = function () {
44674 var directive = function () {
44675 return new Directory();
44681 directives.Directory = Directory;
44682 var DirectoryController = (function () {
44683 function DirectoryController(APIEndPoint, $scope) {
44684 this.APIEndPoint = APIEndPoint;
44685 this.$scope = $scope;
44686 var controller = this;
44688 .getFiles(this.info.fileId)
44690 .then(function (result) {
44691 if (result.status === 'success') {
44692 controller.files = result.info;
44693 angular.forEach(result.info, function (file) {
44694 if (file.fileType === '0') {
44696 if (controller.info.path === '/') {
44697 o.path = '/' + file.name;
44700 o.path = controller.info.path + '/' + file.name;
44702 controller.add()(o, controller.list);
44709 DirectoryController.$inject = ['APIEndPoint', '$scope'];
44710 return DirectoryController;
44712 directives.DirectoryController = DirectoryController;
44713 })(directives = app.directives || (app.directives = {}));
44714 })(app || (app = {}));
44718 (function (controllers) {
44719 var Execution = (function () {
44720 function Execution(MyModal, $scope) {
44721 this.MyModal = MyModal;
44722 this.$scope = $scope;
44723 this.commandInfoList = [];
44726 Execution.prototype.add = function () {
44727 this.$scope.$broadcast('close');
44728 var commandInfoList = this.commandInfoList;
44729 var commandInstance = this.MyModal.selectCommand();
44732 .then(function (command) {
44733 commandInfoList.push(new app.declares.CommandInfo(command));
44736 Execution.prototype.open = function () {
44737 var result = this.MyModal.open('SelectCommand');
44738 console.log(result);
44740 Execution.prototype.remove = function (index, list) {
44741 list.splice(index, 1);
44743 Execution.prototype.close = function () {
44744 console.log("close");
44746 Execution.$inject = ['MyModal', '$scope'];
44749 controllers.Execution = Execution;
44750 })(controllers = app.controllers || (app.controllers = {}));
44751 })(app || (app = {}));
44755 (function (controllers) {
44756 var Workspace = (function () {
44757 function Workspace($scope, APIEndPoint, MyModal) {
44758 this.$scope = $scope;
44759 this.APIEndPoint = APIEndPoint;
44760 this.MyModal = MyModal;
44761 this.directoryList = [];
44762 var controller = this;
44763 var directoryList = this.directoryList;
44765 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
44773 directoryList.push(o);
44775 Workspace.prototype.addDirectory = function (info, directoryList) {
44776 directoryList.push(info);
44778 Workspace.prototype.debug = function () {
44779 this.MyModal.preview();
44781 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
44784 controllers.Workspace = Workspace;
44785 })(controllers = app.controllers || (app.controllers = {}));
44786 })(app || (app = {}));
44790 (function (controllers) {
44791 var History = (function () {
44792 function History($scope) {
44793 this.page = "History";
44795 History.$inject = ['$scope'];
44798 controllers.History = History;
44799 })(controllers = app.controllers || (app.controllers = {}));
44800 })(app || (app = {}));
44804 (function (controllers) {
44805 var SelectCommand = (function () {
44806 function SelectCommand($scope, APIEndPoint, $modalInstance) {
44807 this.APIEndPoint = APIEndPoint;
44808 this.$modalInstance = $modalInstance;
44809 var controller = this;
44812 .$promise.then(function (result) {
44813 controller.tags = result.info;
44817 .$promise.then(function (result) {
44818 controller.commands = result.info;
44820 this.currentTag = 'all';
44822 SelectCommand.prototype.changeTag = function (tag) {
44823 this.currentTag = tag;
44825 SelectCommand.prototype.selectCommand = function (command) {
44826 this.$modalInstance.close(command);
44828 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
44829 return SelectCommand;
44831 controllers.SelectCommand = SelectCommand;
44832 })(controllers = app.controllers || (app.controllers = {}));
44833 })(app || (app = {}));
44837 (function (controllers) {
44838 var Preview = (function () {
44839 function Preview($scope, APIEndPoint, $modalInstance) {
44840 this.APIEndPoint = APIEndPoint;
44841 this.$modalInstance = $modalInstance;
44842 var controller = this;
44843 console.log('preview');
44845 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
44848 controllers.Preview = Preview;
44849 })(controllers = app.controllers || (app.controllers = {}));
44850 })(app || (app = {}));
44852 (function (filters) {
44854 return function (commands, tag) {
44856 angular.forEach(commands, function (command) {
44858 angular.forEach(command.tags, function (value) {
44863 result.push(command);
44869 })(filters || (filters = {}));
44873 var appName = 'zephyr';
44874 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
44875 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
44876 $urlRouterProvider.otherwise('/execution');
44877 $locationProvider.html5Mode({
44882 .state('execution', {
44884 templateUrl: 'templates/execution.html',
44885 controller: 'executionController',
44888 .state('workspace', {
44890 templateUrl: 'templates/workspace.html',
44891 controller: 'workspaceController',
44894 .state('history', {
44896 templateUrl: 'templates/history.html',
44897 controller: 'historyController',
44901 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
44902 app.zephyr.filter('Tag', filters.Tag);
44903 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
44904 app.zephyr.controller('previewController', app.controllers.Preview);
44905 app.zephyr.service('MyModal', app.services.MyModal);
44906 app.zephyr.controller('executionController', app.controllers.Execution);
44907 app.zephyr.controller('workspaceController', app.controllers.Workspace);
44908 app.zephyr.controller('historyController', app.controllers.History);
44909 app.zephyr.controller('commandController', app.directives.CommandController);
44910 app.zephyr.controller('optionController', app.directives.OptionController);
44911 app.zephyr.controller('directoryController', app.directives.DirectoryController);
44912 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
44913 app.zephyr.directive('command', app.directives.Command.Factory());
44914 app.zephyr.directive('option', app.directives.Option.Factory());
44915 app.zephyr.directive('directory', app.directives.Directory.Factory());
44916 })(app || (app = {}));
44921 /***/ function(module, exports) {
44926 (function (declares) {
44927 var CommandInfo = (function () {
44928 function CommandInfo(name) {
44931 return CommandInfo;
44933 declares.CommandInfo = CommandInfo;
44934 })(declares = app.declares || (app.declares = {}));
44935 })(app || (app = {}));
44939 (function (services) {
44940 var APIEndPoint = (function () {
44941 function APIEndPoint($resource, $http) {
44942 this.$resource = $resource;
44943 this.$http = $http;
44945 APIEndPoint.prototype.resource = function (endPoint, data) {
44946 var customAction = {
44952 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
44954 return this.$resource(endPoint, {}, { execute: execute });
44956 APIEndPoint.prototype.getOptionControlFile = function (command) {
44957 var endPoint = '/api/v1/optionControlFile/' + command;
44958 return this.resource(endPoint, {}).get();
44960 APIEndPoint.prototype.getFiles = function (fileId) {
44961 var endPoint = '/api/v1/workspace';
44963 endPoint += '/' + fileId;
44965 return this.resource(endPoint, {}).get();
44967 APIEndPoint.prototype.getDirectories = function () {
44968 var endPoint = '/api/v1/all/workspace/directory';
44969 return this.resource(endPoint, {}).get();
44971 APIEndPoint.prototype.getTags = function () {
44972 var endPoint = '/api/v1/tagList';
44973 return this.resource(endPoint, {}).get();
44975 APIEndPoint.prototype.getCommands = function () {
44976 var endPoint = '/api/v1/commandList';
44977 return this.resource(endPoint, {}).get();
44979 APIEndPoint.prototype.execute = function (data) {
44980 var endPoint = '/api/v1/execution';
44981 var fd = new FormData();
44982 fd.append('data', data);
44983 return this.$http.post(endPoint, fd, {
44984 headers: { 'Content-Type': undefined },
44985 transformRequest: angular.identity
44988 return APIEndPoint;
44990 services.APIEndPoint = APIEndPoint;
44991 })(services = app.services || (app.services = {}));
44992 })(app || (app = {}));
44996 (function (services) {
44997 var MyModal = (function () {
44998 function MyModal($uibModal) {
44999 this.$uibModal = $uibModal;
45000 this.modalOption = {
45007 MyModal.prototype.open = function (modalName) {
45008 if (modalName === 'SelectCommand') {
45009 this.modalOption.templateUrl = 'templates/select-command.html';
45010 this.modalOption.size = 'lg';
45012 return this.$uibModal.open(this.modalOption);
45014 MyModal.prototype.selectCommand = function () {
45015 this.modalOption.templateUrl = 'templates/select-command.html';
45016 this.modalOption.controller = 'selectCommandController';
45017 this.modalOption.controllerAs = 'c';
45018 this.modalOption.size = 'lg';
45019 return this.$uibModal.open(this.modalOption);
45021 MyModal.prototype.preview = function () {
45022 this.modalOption.templateUrl = 'templates/preview.html';
45023 this.modalOption.controller = 'previewController';
45024 this.modalOption.controllerAs = 'c';
45025 this.modalOption.size = 'lg';
45026 return this.$uibModal.open(this.modalOption);
45028 MyModal.$inject = ['$uibModal'];
45031 services.MyModal = MyModal;
45032 })(services = app.services || (app.services = {}));
45033 })(app || (app = {}));
45037 (function (directives) {
45038 var Command = (function () {
45039 function Command() {
45040 this.restrict = 'E';
45041 this.replace = true;
45043 this.controller = 'commandController';
45044 this.controllerAs = 'ctrl';
45045 this.bindToController = {
45051 this.templateUrl = 'templates/command.html';
45053 Command.Factory = function () {
45054 var directive = function () {
45055 return new Command();
45057 directive.$inject = [];
45062 directives.Command = Command;
45063 var CommandController = (function () {
45064 function CommandController(APIEndPoint, $scope, MyModal) {
45065 this.APIEndPoint = APIEndPoint;
45066 this.$scope = $scope;
45067 this.MyModal = MyModal;
45068 var controller = this;
45070 .getOptionControlFile('mrcImageNoiseAdd')
45072 .then(function (result) {
45073 controller.options = result.info;
45078 .then(function (result) {
45079 controller.dirs = result.info;
45081 this.heading = "[" + this.index + "]: dcdFilePring";
45082 this.isOpen = true;
45083 this.$scope.$on('close', function () {
45084 controller.isOpen = false;
45087 CommandController.prototype.submit = function () {
45089 angular.forEach(this.options, function (option) {
45091 name: option.option,
45094 angular.forEach(option.arg, function (arg) {
45096 if (typeof arg.input === 'object') {
45097 obj.arguments.push(arg.input.name);
45100 obj.arguments.push(arg.input);
45104 if (obj.arguments.length > 0) {
45109 command: this.name,
45110 workspace: this.workspace.fileId,
45114 .execute(JSON.stringify(execObj))
45115 .then(function (result) {
45116 console.log(result);
45119 CommandController.prototype.removeMySelf = function (index) {
45120 this.remove()(index, this.list);
45122 CommandController.prototype.reloadFiles = function () {
45124 var fileId = this.workspace.fileId;
45128 .then(function (result) {
45129 var status = result.status;
45130 if (status === 'success') {
45131 _this.files = result.info;
45134 console.log(result.message);
45138 CommandController.prototype.debug = function () {
45139 this.MyModal.preview();
45141 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
45142 return CommandController;
45144 directives.CommandController = CommandController;
45145 })(directives = app.directives || (app.directives = {}));
45146 })(app || (app = {}));
45150 (function (directives) {
45151 var HeaderMenu = (function () {
45152 function HeaderMenu() {
45153 this.restrict = 'E';
45154 this.replace = true;
45155 this.templateUrl = 'templates/header-menu.html';
45157 HeaderMenu.Factory = function () {
45158 var directive = function () {
45159 return new HeaderMenu();
45165 directives.HeaderMenu = HeaderMenu;
45166 })(directives = app.directives || (app.directives = {}));
45167 })(app || (app = {}));
45171 (function (directives) {
45172 var Option = (function () {
45173 function Option() {
45174 this.restrict = 'E';
45175 this.replace = true;
45176 this.controller = 'optionController';
45177 this.bindToController = {
45182 this.templateUrl = 'templates/option.html';
45183 this.controllerAs = 'ctrl';
45185 Option.Factory = function () {
45186 var directive = function () {
45187 return new Option();
45189 directive.$inject = [];
45194 directives.Option = Option;
45195 var OptionController = (function () {
45196 function OptionController() {
45197 var controller = this;
45198 angular.forEach(controller.info.arg, function (arg) {
45199 if (arg.initialValue) {
45200 if (arg.formType === 'number') {
45201 arg.input = parseInt(arg.initialValue);
45204 arg.input = arg.initialValue;
45209 OptionController.$inject = [];
45210 return OptionController;
45212 directives.OptionController = OptionController;
45213 })(directives = app.directives || (app.directives = {}));
45214 })(app || (app = {}));
45218 (function (directives) {
45219 var Directory = (function () {
45220 function Directory() {
45221 this.restrict = 'E';
45222 this.replace = true;
45223 this.controller = 'directoryController';
45224 this.controllerAs = 'ctrl';
45225 this.bindToController = {
45231 this.templateUrl = 'templates/directory.html';
45233 Directory.Factory = function () {
45234 var directive = function () {
45235 return new Directory();
45241 directives.Directory = Directory;
45242 var DirectoryController = (function () {
45243 function DirectoryController(APIEndPoint, $scope) {
45244 this.APIEndPoint = APIEndPoint;
45245 this.$scope = $scope;
45246 var controller = this;
45248 .getFiles(this.info.fileId)
45250 .then(function (result) {
45251 if (result.status === 'success') {
45252 controller.files = result.info;
45253 angular.forEach(result.info, function (file) {
45254 if (file.fileType === '0') {
45256 if (controller.info.path === '/') {
45257 o.path = '/' + file.name;
45260 o.path = controller.info.path + '/' + file.name;
45262 controller.add()(o, controller.list);
45269 DirectoryController.$inject = ['APIEndPoint', '$scope'];
45270 return DirectoryController;
45272 directives.DirectoryController = DirectoryController;
45273 })(directives = app.directives || (app.directives = {}));
45274 })(app || (app = {}));
45278 (function (controllers) {
45279 var Execution = (function () {
45280 function Execution(MyModal, $scope) {
45281 this.MyModal = MyModal;
45282 this.$scope = $scope;
45283 this.commandInfoList = [];
45286 Execution.prototype.add = function () {
45287 this.$scope.$broadcast('close');
45288 var commandInfoList = this.commandInfoList;
45289 var commandInstance = this.MyModal.selectCommand();
45292 .then(function (command) {
45293 commandInfoList.push(new app.declares.CommandInfo(command));
45296 Execution.prototype.open = function () {
45297 var result = this.MyModal.open('SelectCommand');
45298 console.log(result);
45300 Execution.prototype.remove = function (index, list) {
45301 list.splice(index, 1);
45303 Execution.prototype.close = function () {
45304 console.log("close");
45306 Execution.$inject = ['MyModal', '$scope'];
45309 controllers.Execution = Execution;
45310 })(controllers = app.controllers || (app.controllers = {}));
45311 })(app || (app = {}));
45315 (function (controllers) {
45316 var Workspace = (function () {
45317 function Workspace($scope, APIEndPoint, MyModal) {
45318 this.$scope = $scope;
45319 this.APIEndPoint = APIEndPoint;
45320 this.MyModal = MyModal;
45321 this.directoryList = [];
45322 var controller = this;
45323 var directoryList = this.directoryList;
45325 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
45333 directoryList.push(o);
45335 Workspace.prototype.addDirectory = function (info, directoryList) {
45336 directoryList.push(info);
45338 Workspace.prototype.debug = function () {
45339 this.MyModal.preview();
45341 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
45344 controllers.Workspace = Workspace;
45345 })(controllers = app.controllers || (app.controllers = {}));
45346 })(app || (app = {}));
45350 (function (controllers) {
45351 var History = (function () {
45352 function History($scope) {
45353 this.page = "History";
45355 History.$inject = ['$scope'];
45358 controllers.History = History;
45359 })(controllers = app.controllers || (app.controllers = {}));
45360 })(app || (app = {}));
45364 (function (controllers) {
45365 var SelectCommand = (function () {
45366 function SelectCommand($scope, APIEndPoint, $modalInstance) {
45367 this.APIEndPoint = APIEndPoint;
45368 this.$modalInstance = $modalInstance;
45369 var controller = this;
45372 .$promise.then(function (result) {
45373 controller.tags = result.info;
45377 .$promise.then(function (result) {
45378 controller.commands = result.info;
45380 this.currentTag = 'all';
45382 SelectCommand.prototype.changeTag = function (tag) {
45383 this.currentTag = tag;
45385 SelectCommand.prototype.selectCommand = function (command) {
45386 this.$modalInstance.close(command);
45388 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
45389 return SelectCommand;
45391 controllers.SelectCommand = SelectCommand;
45392 })(controllers = app.controllers || (app.controllers = {}));
45393 })(app || (app = {}));
45397 (function (controllers) {
45398 var Preview = (function () {
45399 function Preview($scope, APIEndPoint, $modalInstance) {
45400 this.APIEndPoint = APIEndPoint;
45401 this.$modalInstance = $modalInstance;
45402 var controller = this;
45403 console.log('preview');
45405 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
45408 controllers.Preview = Preview;
45409 })(controllers = app.controllers || (app.controllers = {}));
45410 })(app || (app = {}));
45412 (function (filters) {
45414 return function (commands, tag) {
45416 angular.forEach(commands, function (command) {
45418 angular.forEach(command.tags, function (value) {
45423 result.push(command);
45429 })(filters || (filters = {}));
45433 var appName = 'zephyr';
45434 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
45435 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
45436 $urlRouterProvider.otherwise('/execution');
45437 $locationProvider.html5Mode({
45442 .state('execution', {
45444 templateUrl: 'templates/execution.html',
45445 controller: 'executionController',
45448 .state('workspace', {
45450 templateUrl: 'templates/workspace.html',
45451 controller: 'workspaceController',
45454 .state('history', {
45456 templateUrl: 'templates/history.html',
45457 controller: 'historyController',
45461 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
45462 app.zephyr.filter('Tag', filters.Tag);
45463 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
45464 app.zephyr.controller('previewController', app.controllers.Preview);
45465 app.zephyr.service('MyModal', app.services.MyModal);
45466 app.zephyr.controller('executionController', app.controllers.Execution);
45467 app.zephyr.controller('workspaceController', app.controllers.Workspace);
45468 app.zephyr.controller('historyController', app.controllers.History);
45469 app.zephyr.controller('commandController', app.directives.CommandController);
45470 app.zephyr.controller('optionController', app.directives.OptionController);
45471 app.zephyr.controller('directoryController', app.directives.DirectoryController);
45472 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
45473 app.zephyr.directive('command', app.directives.Command.Factory());
45474 app.zephyr.directive('option', app.directives.Option.Factory());
45475 app.zephyr.directive('directory', app.directives.Directory.Factory());
45476 })(app || (app = {}));
45481 /***/ function(module, exports) {
45486 (function (declares) {
45487 var CommandInfo = (function () {
45488 function CommandInfo(name) {
45491 return CommandInfo;
45493 declares.CommandInfo = CommandInfo;
45494 })(declares = app.declares || (app.declares = {}));
45495 })(app || (app = {}));
45499 (function (services) {
45500 var APIEndPoint = (function () {
45501 function APIEndPoint($resource, $http) {
45502 this.$resource = $resource;
45503 this.$http = $http;
45505 APIEndPoint.prototype.resource = function (endPoint, data) {
45506 var customAction = {
45512 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
45514 return this.$resource(endPoint, {}, { execute: execute });
45516 APIEndPoint.prototype.getOptionControlFile = function (command) {
45517 var endPoint = '/api/v1/optionControlFile/' + command;
45518 return this.resource(endPoint, {}).get();
45520 APIEndPoint.prototype.getFiles = function (fileId) {
45521 var endPoint = '/api/v1/workspace';
45523 endPoint += '/' + fileId;
45525 return this.resource(endPoint, {}).get();
45527 APIEndPoint.prototype.getDirectories = function () {
45528 var endPoint = '/api/v1/all/workspace/directory';
45529 return this.resource(endPoint, {}).get();
45531 APIEndPoint.prototype.getTags = function () {
45532 var endPoint = '/api/v1/tagList';
45533 return this.resource(endPoint, {}).get();
45535 APIEndPoint.prototype.getCommands = function () {
45536 var endPoint = '/api/v1/commandList';
45537 return this.resource(endPoint, {}).get();
45539 APIEndPoint.prototype.execute = function (data) {
45540 var endPoint = '/api/v1/execution';
45541 var fd = new FormData();
45542 fd.append('data', data);
45543 return this.$http.post(endPoint, fd, {
45544 headers: { 'Content-Type': undefined },
45545 transformRequest: angular.identity
45548 return APIEndPoint;
45550 services.APIEndPoint = APIEndPoint;
45551 })(services = app.services || (app.services = {}));
45552 })(app || (app = {}));
45556 (function (services) {
45557 var MyModal = (function () {
45558 function MyModal($uibModal) {
45559 this.$uibModal = $uibModal;
45560 this.modalOption = {
45567 MyModal.prototype.open = function (modalName) {
45568 if (modalName === 'SelectCommand') {
45569 this.modalOption.templateUrl = 'templates/select-command.html';
45570 this.modalOption.size = 'lg';
45572 return this.$uibModal.open(this.modalOption);
45574 MyModal.prototype.selectCommand = function () {
45575 this.modalOption.templateUrl = 'templates/select-command.html';
45576 this.modalOption.controller = 'selectCommandController';
45577 this.modalOption.controllerAs = 'c';
45578 this.modalOption.size = 'lg';
45579 return this.$uibModal.open(this.modalOption);
45581 MyModal.prototype.preview = function () {
45582 this.modalOption.templateUrl = 'templates/preview.html';
45583 this.modalOption.controller = 'previewController';
45584 this.modalOption.controllerAs = 'c';
45585 this.modalOption.size = 'lg';
45586 return this.$uibModal.open(this.modalOption);
45588 MyModal.$inject = ['$uibModal'];
45591 services.MyModal = MyModal;
45592 })(services = app.services || (app.services = {}));
45593 })(app || (app = {}));
45597 (function (directives) {
45598 var Command = (function () {
45599 function Command() {
45600 this.restrict = 'E';
45601 this.replace = true;
45603 this.controller = 'commandController';
45604 this.controllerAs = 'ctrl';
45605 this.bindToController = {
45611 this.templateUrl = 'templates/command.html';
45613 Command.Factory = function () {
45614 var directive = function () {
45615 return new Command();
45617 directive.$inject = [];
45622 directives.Command = Command;
45623 var CommandController = (function () {
45624 function CommandController(APIEndPoint, $scope, MyModal) {
45625 this.APIEndPoint = APIEndPoint;
45626 this.$scope = $scope;
45627 this.MyModal = MyModal;
45628 var controller = this;
45630 .getOptionControlFile('mrcImageNoiseAdd')
45632 .then(function (result) {
45633 controller.options = result.info;
45638 .then(function (result) {
45639 controller.dirs = result.info;
45641 this.heading = "[" + this.index + "]: dcdFilePring";
45642 this.isOpen = true;
45643 this.$scope.$on('close', function () {
45644 controller.isOpen = false;
45647 CommandController.prototype.submit = function () {
45649 angular.forEach(this.options, function (option) {
45651 name: option.option,
45654 angular.forEach(option.arg, function (arg) {
45656 if (typeof arg.input === 'object') {
45657 obj.arguments.push(arg.input.name);
45660 obj.arguments.push(arg.input);
45664 if (obj.arguments.length > 0) {
45669 command: this.name,
45670 workspace: this.workspace.fileId,
45674 .execute(JSON.stringify(execObj))
45675 .then(function (result) {
45676 console.log(result);
45679 CommandController.prototype.removeMySelf = function (index) {
45680 this.remove()(index, this.list);
45682 CommandController.prototype.reloadFiles = function () {
45684 var fileId = this.workspace.fileId;
45688 .then(function (result) {
45689 var status = result.status;
45690 if (status === 'success') {
45691 _this.files = result.info;
45694 console.log(result.message);
45698 CommandController.prototype.debug = function () {
45699 this.MyModal.preview();
45701 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
45702 return CommandController;
45704 directives.CommandController = CommandController;
45705 })(directives = app.directives || (app.directives = {}));
45706 })(app || (app = {}));
45710 (function (directives) {
45711 var HeaderMenu = (function () {
45712 function HeaderMenu() {
45713 this.restrict = 'E';
45714 this.replace = true;
45715 this.templateUrl = 'templates/header-menu.html';
45717 HeaderMenu.Factory = function () {
45718 var directive = function () {
45719 return new HeaderMenu();
45725 directives.HeaderMenu = HeaderMenu;
45726 })(directives = app.directives || (app.directives = {}));
45727 })(app || (app = {}));
45731 (function (directives) {
45732 var Option = (function () {
45733 function Option() {
45734 this.restrict = 'E';
45735 this.replace = true;
45736 this.controller = 'optionController';
45737 this.bindToController = {
45742 this.templateUrl = 'templates/option.html';
45743 this.controllerAs = 'ctrl';
45745 Option.Factory = function () {
45746 var directive = function () {
45747 return new Option();
45749 directive.$inject = [];
45754 directives.Option = Option;
45755 var OptionController = (function () {
45756 function OptionController() {
45757 var controller = this;
45758 angular.forEach(controller.info.arg, function (arg) {
45759 if (arg.initialValue) {
45760 if (arg.formType === 'number') {
45761 arg.input = parseInt(arg.initialValue);
45764 arg.input = arg.initialValue;
45769 OptionController.$inject = [];
45770 return OptionController;
45772 directives.OptionController = OptionController;
45773 })(directives = app.directives || (app.directives = {}));
45774 })(app || (app = {}));
45778 (function (directives) {
45779 var Directory = (function () {
45780 function Directory() {
45781 this.restrict = 'E';
45782 this.replace = true;
45783 this.controller = 'directoryController';
45784 this.controllerAs = 'ctrl';
45785 this.bindToController = {
45791 this.templateUrl = 'templates/directory.html';
45793 Directory.Factory = function () {
45794 var directive = function () {
45795 return new Directory();
45801 directives.Directory = Directory;
45802 var DirectoryController = (function () {
45803 function DirectoryController(APIEndPoint, $scope) {
45804 this.APIEndPoint = APIEndPoint;
45805 this.$scope = $scope;
45806 var controller = this;
45808 .getFiles(this.info.fileId)
45810 .then(function (result) {
45811 if (result.status === 'success') {
45812 controller.files = result.info;
45813 angular.forEach(result.info, function (file) {
45814 if (file.fileType === '0') {
45816 if (controller.info.path === '/') {
45817 o.path = '/' + file.name;
45820 o.path = controller.info.path + '/' + file.name;
45822 controller.add()(o, controller.list);
45829 DirectoryController.$inject = ['APIEndPoint', '$scope'];
45830 return DirectoryController;
45832 directives.DirectoryController = DirectoryController;
45833 })(directives = app.directives || (app.directives = {}));
45834 })(app || (app = {}));
45838 (function (controllers) {
45839 var Execution = (function () {
45840 function Execution(MyModal, $scope) {
45841 this.MyModal = MyModal;
45842 this.$scope = $scope;
45843 this.commandInfoList = [];
45846 Execution.prototype.add = function () {
45847 this.$scope.$broadcast('close');
45848 var commandInfoList = this.commandInfoList;
45849 var commandInstance = this.MyModal.selectCommand();
45852 .then(function (command) {
45853 commandInfoList.push(new app.declares.CommandInfo(command));
45856 Execution.prototype.open = function () {
45857 var result = this.MyModal.open('SelectCommand');
45858 console.log(result);
45860 Execution.prototype.remove = function (index, list) {
45861 list.splice(index, 1);
45863 Execution.prototype.close = function () {
45864 console.log("close");
45866 Execution.$inject = ['MyModal', '$scope'];
45869 controllers.Execution = Execution;
45870 })(controllers = app.controllers || (app.controllers = {}));
45871 })(app || (app = {}));
45875 (function (controllers) {
45876 var Workspace = (function () {
45877 function Workspace($scope, APIEndPoint, MyModal) {
45878 this.$scope = $scope;
45879 this.APIEndPoint = APIEndPoint;
45880 this.MyModal = MyModal;
45881 this.directoryList = [];
45882 var controller = this;
45883 var directoryList = this.directoryList;
45885 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
45893 directoryList.push(o);
45895 Workspace.prototype.addDirectory = function (info, directoryList) {
45896 directoryList.push(info);
45898 Workspace.prototype.debug = function () {
45899 this.MyModal.preview();
45901 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
45904 controllers.Workspace = Workspace;
45905 })(controllers = app.controllers || (app.controllers = {}));
45906 })(app || (app = {}));
45910 (function (controllers) {
45911 var History = (function () {
45912 function History($scope) {
45913 this.page = "History";
45915 History.$inject = ['$scope'];
45918 controllers.History = History;
45919 })(controllers = app.controllers || (app.controllers = {}));
45920 })(app || (app = {}));
45924 (function (controllers) {
45925 var SelectCommand = (function () {
45926 function SelectCommand($scope, APIEndPoint, $modalInstance) {
45927 this.APIEndPoint = APIEndPoint;
45928 this.$modalInstance = $modalInstance;
45929 var controller = this;
45932 .$promise.then(function (result) {
45933 controller.tags = result.info;
45937 .$promise.then(function (result) {
45938 controller.commands = result.info;
45940 this.currentTag = 'all';
45942 SelectCommand.prototype.changeTag = function (tag) {
45943 this.currentTag = tag;
45945 SelectCommand.prototype.selectCommand = function (command) {
45946 this.$modalInstance.close(command);
45948 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
45949 return SelectCommand;
45951 controllers.SelectCommand = SelectCommand;
45952 })(controllers = app.controllers || (app.controllers = {}));
45953 })(app || (app = {}));
45957 (function (controllers) {
45958 var Preview = (function () {
45959 function Preview($scope, APIEndPoint, $modalInstance) {
45960 this.APIEndPoint = APIEndPoint;
45961 this.$modalInstance = $modalInstance;
45962 var controller = this;
45963 console.log('preview');
45965 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
45968 controllers.Preview = Preview;
45969 })(controllers = app.controllers || (app.controllers = {}));
45970 })(app || (app = {}));
45972 (function (filters) {
45974 return function (commands, tag) {
45976 angular.forEach(commands, function (command) {
45978 angular.forEach(command.tags, function (value) {
45983 result.push(command);
45989 })(filters || (filters = {}));
45993 var appName = 'zephyr';
45994 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
45995 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
45996 $urlRouterProvider.otherwise('/execution');
45997 $locationProvider.html5Mode({
46002 .state('execution', {
46004 templateUrl: 'templates/execution.html',
46005 controller: 'executionController',
46008 .state('workspace', {
46010 templateUrl: 'templates/workspace.html',
46011 controller: 'workspaceController',
46014 .state('history', {
46016 templateUrl: 'templates/history.html',
46017 controller: 'historyController',
46021 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
46022 app.zephyr.filter('Tag', filters.Tag);
46023 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
46024 app.zephyr.controller('previewController', app.controllers.Preview);
46025 app.zephyr.service('MyModal', app.services.MyModal);
46026 app.zephyr.controller('executionController', app.controllers.Execution);
46027 app.zephyr.controller('workspaceController', app.controllers.Workspace);
46028 app.zephyr.controller('historyController', app.controllers.History);
46029 app.zephyr.controller('commandController', app.directives.CommandController);
46030 app.zephyr.controller('optionController', app.directives.OptionController);
46031 app.zephyr.controller('directoryController', app.directives.DirectoryController);
46032 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
46033 app.zephyr.directive('command', app.directives.Command.Factory());
46034 app.zephyr.directive('option', app.directives.Option.Factory());
46035 app.zephyr.directive('directory', app.directives.Directory.Factory());
46036 })(app || (app = {}));
46041 /***/ function(module, exports) {
46046 (function (declares) {
46047 var CommandInfo = (function () {
46048 function CommandInfo(name) {
46051 return CommandInfo;
46053 declares.CommandInfo = CommandInfo;
46054 })(declares = app.declares || (app.declares = {}));
46055 })(app || (app = {}));
46059 (function (services) {
46060 var APIEndPoint = (function () {
46061 function APIEndPoint($resource, $http) {
46062 this.$resource = $resource;
46063 this.$http = $http;
46065 APIEndPoint.prototype.resource = function (endPoint, data) {
46066 var customAction = {
46072 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
46074 return this.$resource(endPoint, {}, { execute: execute });
46076 APIEndPoint.prototype.getOptionControlFile = function (command) {
46077 var endPoint = '/api/v1/optionControlFile/' + command;
46078 return this.resource(endPoint, {}).get();
46080 APIEndPoint.prototype.getFiles = function (fileId) {
46081 var endPoint = '/api/v1/workspace';
46083 endPoint += '/' + fileId;
46085 return this.resource(endPoint, {}).get();
46087 APIEndPoint.prototype.getDirectories = function () {
46088 var endPoint = '/api/v1/all/workspace/directory';
46089 return this.resource(endPoint, {}).get();
46091 APIEndPoint.prototype.getTags = function () {
46092 var endPoint = '/api/v1/tagList';
46093 return this.resource(endPoint, {}).get();
46095 APIEndPoint.prototype.getCommands = function () {
46096 var endPoint = '/api/v1/commandList';
46097 return this.resource(endPoint, {}).get();
46099 APIEndPoint.prototype.execute = function (data) {
46100 var endPoint = '/api/v1/execution';
46101 var fd = new FormData();
46102 fd.append('data', data);
46103 return this.$http.post(endPoint, fd, {
46104 headers: { 'Content-Type': undefined },
46105 transformRequest: angular.identity
46108 return APIEndPoint;
46110 services.APIEndPoint = APIEndPoint;
46111 })(services = app.services || (app.services = {}));
46112 })(app || (app = {}));
46116 (function (services) {
46117 var MyModal = (function () {
46118 function MyModal($uibModal) {
46119 this.$uibModal = $uibModal;
46120 this.modalOption = {
46127 MyModal.prototype.open = function (modalName) {
46128 if (modalName === 'SelectCommand') {
46129 this.modalOption.templateUrl = 'templates/select-command.html';
46130 this.modalOption.size = 'lg';
46132 return this.$uibModal.open(this.modalOption);
46134 MyModal.prototype.selectCommand = function () {
46135 this.modalOption.templateUrl = 'templates/select-command.html';
46136 this.modalOption.controller = 'selectCommandController';
46137 this.modalOption.controllerAs = 'c';
46138 this.modalOption.size = 'lg';
46139 return this.$uibModal.open(this.modalOption);
46141 MyModal.prototype.preview = function () {
46142 this.modalOption.templateUrl = 'templates/preview.html';
46143 this.modalOption.controller = 'previewController';
46144 this.modalOption.controllerAs = 'c';
46145 this.modalOption.size = 'lg';
46146 return this.$uibModal.open(this.modalOption);
46148 MyModal.$inject = ['$uibModal'];
46151 services.MyModal = MyModal;
46152 })(services = app.services || (app.services = {}));
46153 })(app || (app = {}));
46157 (function (directives) {
46158 var Command = (function () {
46159 function Command() {
46160 this.restrict = 'E';
46161 this.replace = true;
46163 this.controller = 'commandController';
46164 this.controllerAs = 'ctrl';
46165 this.bindToController = {
46171 this.templateUrl = 'templates/command.html';
46173 Command.Factory = function () {
46174 var directive = function () {
46175 return new Command();
46177 directive.$inject = [];
46182 directives.Command = Command;
46183 var CommandController = (function () {
46184 function CommandController(APIEndPoint, $scope, MyModal) {
46185 this.APIEndPoint = APIEndPoint;
46186 this.$scope = $scope;
46187 this.MyModal = MyModal;
46188 var controller = this;
46190 .getOptionControlFile('mrcImageNoiseAdd')
46192 .then(function (result) {
46193 controller.options = result.info;
46198 .then(function (result) {
46199 controller.dirs = result.info;
46201 this.heading = "[" + this.index + "]: dcdFilePring";
46202 this.isOpen = true;
46203 this.$scope.$on('close', function () {
46204 controller.isOpen = false;
46207 CommandController.prototype.submit = function () {
46209 angular.forEach(this.options, function (option) {
46211 name: option.option,
46214 angular.forEach(option.arg, function (arg) {
46216 if (typeof arg.input === 'object') {
46217 obj.arguments.push(arg.input.name);
46220 obj.arguments.push(arg.input);
46224 if (obj.arguments.length > 0) {
46229 command: this.name,
46230 workspace: this.workspace.fileId,
46234 .execute(JSON.stringify(execObj))
46235 .then(function (result) {
46236 console.log(result);
46239 CommandController.prototype.removeMySelf = function (index) {
46240 this.remove()(index, this.list);
46242 CommandController.prototype.reloadFiles = function () {
46244 var fileId = this.workspace.fileId;
46248 .then(function (result) {
46249 var status = result.status;
46250 if (status === 'success') {
46251 _this.files = result.info;
46254 console.log(result.message);
46258 CommandController.prototype.debug = function () {
46259 this.MyModal.preview();
46261 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
46262 return CommandController;
46264 directives.CommandController = CommandController;
46265 })(directives = app.directives || (app.directives = {}));
46266 })(app || (app = {}));
46270 (function (directives) {
46271 var HeaderMenu = (function () {
46272 function HeaderMenu() {
46273 this.restrict = 'E';
46274 this.replace = true;
46275 this.templateUrl = 'templates/header-menu.html';
46277 HeaderMenu.Factory = function () {
46278 var directive = function () {
46279 return new HeaderMenu();
46285 directives.HeaderMenu = HeaderMenu;
46286 })(directives = app.directives || (app.directives = {}));
46287 })(app || (app = {}));
46291 (function (directives) {
46292 var Option = (function () {
46293 function Option() {
46294 this.restrict = 'E';
46295 this.replace = true;
46296 this.controller = 'optionController';
46297 this.bindToController = {
46302 this.templateUrl = 'templates/option.html';
46303 this.controllerAs = 'ctrl';
46305 Option.Factory = function () {
46306 var directive = function () {
46307 return new Option();
46309 directive.$inject = [];
46314 directives.Option = Option;
46315 var OptionController = (function () {
46316 function OptionController() {
46317 var controller = this;
46318 angular.forEach(controller.info.arg, function (arg) {
46319 if (arg.initialValue) {
46320 if (arg.formType === 'number') {
46321 arg.input = parseInt(arg.initialValue);
46324 arg.input = arg.initialValue;
46329 OptionController.$inject = [];
46330 return OptionController;
46332 directives.OptionController = OptionController;
46333 })(directives = app.directives || (app.directives = {}));
46334 })(app || (app = {}));
46338 (function (directives) {
46339 var Directory = (function () {
46340 function Directory() {
46341 this.restrict = 'E';
46342 this.replace = true;
46343 this.controller = 'directoryController';
46344 this.controllerAs = 'ctrl';
46345 this.bindToController = {
46351 this.templateUrl = 'templates/directory.html';
46353 Directory.Factory = function () {
46354 var directive = function () {
46355 return new Directory();
46361 directives.Directory = Directory;
46362 var DirectoryController = (function () {
46363 function DirectoryController(APIEndPoint, $scope) {
46364 this.APIEndPoint = APIEndPoint;
46365 this.$scope = $scope;
46366 var controller = this;
46368 .getFiles(this.info.fileId)
46370 .then(function (result) {
46371 if (result.status === 'success') {
46372 controller.files = result.info;
46373 angular.forEach(result.info, function (file) {
46374 if (file.fileType === '0') {
46376 if (controller.info.path === '/') {
46377 o.path = '/' + file.name;
46380 o.path = controller.info.path + '/' + file.name;
46382 controller.add()(o, controller.list);
46389 DirectoryController.$inject = ['APIEndPoint', '$scope'];
46390 return DirectoryController;
46392 directives.DirectoryController = DirectoryController;
46393 })(directives = app.directives || (app.directives = {}));
46394 })(app || (app = {}));
46398 (function (controllers) {
46399 var Execution = (function () {
46400 function Execution(MyModal, $scope) {
46401 this.MyModal = MyModal;
46402 this.$scope = $scope;
46403 this.commandInfoList = [];
46406 Execution.prototype.add = function () {
46407 this.$scope.$broadcast('close');
46408 var commandInfoList = this.commandInfoList;
46409 var commandInstance = this.MyModal.selectCommand();
46412 .then(function (command) {
46413 commandInfoList.push(new app.declares.CommandInfo(command));
46416 Execution.prototype.open = function () {
46417 var result = this.MyModal.open('SelectCommand');
46418 console.log(result);
46420 Execution.prototype.remove = function (index, list) {
46421 list.splice(index, 1);
46423 Execution.prototype.close = function () {
46424 console.log("close");
46426 Execution.$inject = ['MyModal', '$scope'];
46429 controllers.Execution = Execution;
46430 })(controllers = app.controllers || (app.controllers = {}));
46431 })(app || (app = {}));
46435 (function (controllers) {
46436 var Workspace = (function () {
46437 function Workspace($scope, APIEndPoint, MyModal) {
46438 this.$scope = $scope;
46439 this.APIEndPoint = APIEndPoint;
46440 this.MyModal = MyModal;
46441 this.directoryList = [];
46442 var controller = this;
46443 var directoryList = this.directoryList;
46445 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
46453 directoryList.push(o);
46455 Workspace.prototype.addDirectory = function (info, directoryList) {
46456 directoryList.push(info);
46458 Workspace.prototype.debug = function () {
46459 this.MyModal.preview();
46461 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
46464 controllers.Workspace = Workspace;
46465 })(controllers = app.controllers || (app.controllers = {}));
46466 })(app || (app = {}));
46470 (function (controllers) {
46471 var History = (function () {
46472 function History($scope) {
46473 this.page = "History";
46475 History.$inject = ['$scope'];
46478 controllers.History = History;
46479 })(controllers = app.controllers || (app.controllers = {}));
46480 })(app || (app = {}));
46484 (function (controllers) {
46485 var SelectCommand = (function () {
46486 function SelectCommand($scope, APIEndPoint, $modalInstance) {
46487 this.APIEndPoint = APIEndPoint;
46488 this.$modalInstance = $modalInstance;
46489 var controller = this;
46492 .$promise.then(function (result) {
46493 controller.tags = result.info;
46497 .$promise.then(function (result) {
46498 controller.commands = result.info;
46500 this.currentTag = 'all';
46502 SelectCommand.prototype.changeTag = function (tag) {
46503 this.currentTag = tag;
46505 SelectCommand.prototype.selectCommand = function (command) {
46506 this.$modalInstance.close(command);
46508 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
46509 return SelectCommand;
46511 controllers.SelectCommand = SelectCommand;
46512 })(controllers = app.controllers || (app.controllers = {}));
46513 })(app || (app = {}));
46517 (function (controllers) {
46518 var Preview = (function () {
46519 function Preview($scope, APIEndPoint, $modalInstance) {
46520 this.APIEndPoint = APIEndPoint;
46521 this.$modalInstance = $modalInstance;
46522 var controller = this;
46523 console.log('preview');
46525 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
46528 controllers.Preview = Preview;
46529 })(controllers = app.controllers || (app.controllers = {}));
46530 })(app || (app = {}));
46532 (function (filters) {
46534 return function (commands, tag) {
46536 angular.forEach(commands, function (command) {
46538 angular.forEach(command.tags, function (value) {
46543 result.push(command);
46549 })(filters || (filters = {}));
46553 var appName = 'zephyr';
46554 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
46555 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
46556 $urlRouterProvider.otherwise('/execution');
46557 $locationProvider.html5Mode({
46562 .state('execution', {
46564 templateUrl: 'templates/execution.html',
46565 controller: 'executionController',
46568 .state('workspace', {
46570 templateUrl: 'templates/workspace.html',
46571 controller: 'workspaceController',
46574 .state('history', {
46576 templateUrl: 'templates/history.html',
46577 controller: 'historyController',
46581 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
46582 app.zephyr.filter('Tag', filters.Tag);
46583 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
46584 app.zephyr.controller('previewController', app.controllers.Preview);
46585 app.zephyr.service('MyModal', app.services.MyModal);
46586 app.zephyr.controller('executionController', app.controllers.Execution);
46587 app.zephyr.controller('workspaceController', app.controllers.Workspace);
46588 app.zephyr.controller('historyController', app.controllers.History);
46589 app.zephyr.controller('commandController', app.directives.CommandController);
46590 app.zephyr.controller('optionController', app.directives.OptionController);
46591 app.zephyr.controller('directoryController', app.directives.DirectoryController);
46592 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
46593 app.zephyr.directive('command', app.directives.Command.Factory());
46594 app.zephyr.directive('option', app.directives.Option.Factory());
46595 app.zephyr.directive('directory', app.directives.Directory.Factory());
46596 })(app || (app = {}));
46601 /***/ function(module, exports) {
46606 (function (declares) {
46607 var CommandInfo = (function () {
46608 function CommandInfo(name) {
46611 return CommandInfo;
46613 declares.CommandInfo = CommandInfo;
46614 })(declares = app.declares || (app.declares = {}));
46615 })(app || (app = {}));
46619 (function (services) {
46620 var APIEndPoint = (function () {
46621 function APIEndPoint($resource, $http) {
46622 this.$resource = $resource;
46623 this.$http = $http;
46625 APIEndPoint.prototype.resource = function (endPoint, data) {
46626 var customAction = {
46632 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
46634 return this.$resource(endPoint, {}, { execute: execute });
46636 APIEndPoint.prototype.getOptionControlFile = function (command) {
46637 var endPoint = '/api/v1/optionControlFile/' + command;
46638 return this.resource(endPoint, {}).get();
46640 APIEndPoint.prototype.getFiles = function (fileId) {
46641 var endPoint = '/api/v1/workspace';
46643 endPoint += '/' + fileId;
46645 return this.resource(endPoint, {}).get();
46647 APIEndPoint.prototype.getDirectories = function () {
46648 var endPoint = '/api/v1/all/workspace/directory';
46649 return this.resource(endPoint, {}).get();
46651 APIEndPoint.prototype.getTags = function () {
46652 var endPoint = '/api/v1/tagList';
46653 return this.resource(endPoint, {}).get();
46655 APIEndPoint.prototype.getCommands = function () {
46656 var endPoint = '/api/v1/commandList';
46657 return this.resource(endPoint, {}).get();
46659 APIEndPoint.prototype.execute = function (data) {
46660 var endPoint = '/api/v1/execution';
46661 var fd = new FormData();
46662 fd.append('data', data);
46663 return this.$http.post(endPoint, fd, {
46664 headers: { 'Content-Type': undefined },
46665 transformRequest: angular.identity
46668 return APIEndPoint;
46670 services.APIEndPoint = APIEndPoint;
46671 })(services = app.services || (app.services = {}));
46672 })(app || (app = {}));
46676 (function (services) {
46677 var MyModal = (function () {
46678 function MyModal($uibModal) {
46679 this.$uibModal = $uibModal;
46680 this.modalOption = {
46687 MyModal.prototype.open = function (modalName) {
46688 if (modalName === 'SelectCommand') {
46689 this.modalOption.templateUrl = 'templates/select-command.html';
46690 this.modalOption.size = 'lg';
46692 return this.$uibModal.open(this.modalOption);
46694 MyModal.prototype.selectCommand = function () {
46695 this.modalOption.templateUrl = 'templates/select-command.html';
46696 this.modalOption.controller = 'selectCommandController';
46697 this.modalOption.controllerAs = 'c';
46698 this.modalOption.size = 'lg';
46699 return this.$uibModal.open(this.modalOption);
46701 MyModal.prototype.preview = function () {
46702 this.modalOption.templateUrl = 'templates/preview.html';
46703 this.modalOption.controller = 'previewController';
46704 this.modalOption.controllerAs = 'c';
46705 this.modalOption.size = 'lg';
46706 return this.$uibModal.open(this.modalOption);
46708 MyModal.$inject = ['$uibModal'];
46711 services.MyModal = MyModal;
46712 })(services = app.services || (app.services = {}));
46713 })(app || (app = {}));
46717 (function (directives) {
46718 var Command = (function () {
46719 function Command() {
46720 this.restrict = 'E';
46721 this.replace = true;
46723 this.controller = 'commandController';
46724 this.controllerAs = 'ctrl';
46725 this.bindToController = {
46731 this.templateUrl = 'templates/command.html';
46733 Command.Factory = function () {
46734 var directive = function () {
46735 return new Command();
46737 directive.$inject = [];
46742 directives.Command = Command;
46743 var CommandController = (function () {
46744 function CommandController(APIEndPoint, $scope, MyModal) {
46745 this.APIEndPoint = APIEndPoint;
46746 this.$scope = $scope;
46747 this.MyModal = MyModal;
46748 var controller = this;
46750 .getOptionControlFile('mrcImageNoiseAdd')
46752 .then(function (result) {
46753 controller.options = result.info;
46758 .then(function (result) {
46759 controller.dirs = result.info;
46761 this.heading = "[" + this.index + "]: dcdFilePring";
46762 this.isOpen = true;
46763 this.$scope.$on('close', function () {
46764 controller.isOpen = false;
46767 CommandController.prototype.submit = function () {
46769 angular.forEach(this.options, function (option) {
46771 name: option.option,
46774 angular.forEach(option.arg, function (arg) {
46776 if (typeof arg.input === 'object') {
46777 obj.arguments.push(arg.input.name);
46780 obj.arguments.push(arg.input);
46784 if (obj.arguments.length > 0) {
46789 command: this.name,
46790 workspace: this.workspace.fileId,
46794 .execute(JSON.stringify(execObj))
46795 .then(function (result) {
46796 console.log(result);
46799 CommandController.prototype.removeMySelf = function (index) {
46800 this.remove()(index, this.list);
46802 CommandController.prototype.reloadFiles = function () {
46804 var fileId = this.workspace.fileId;
46808 .then(function (result) {
46809 var status = result.status;
46810 if (status === 'success') {
46811 _this.files = result.info;
46814 console.log(result.message);
46818 CommandController.prototype.debug = function () {
46819 this.MyModal.preview();
46821 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
46822 return CommandController;
46824 directives.CommandController = CommandController;
46825 })(directives = app.directives || (app.directives = {}));
46826 })(app || (app = {}));
46830 (function (directives) {
46831 var HeaderMenu = (function () {
46832 function HeaderMenu() {
46833 this.restrict = 'E';
46834 this.replace = true;
46835 this.templateUrl = 'templates/header-menu.html';
46837 HeaderMenu.Factory = function () {
46838 var directive = function () {
46839 return new HeaderMenu();
46845 directives.HeaderMenu = HeaderMenu;
46846 })(directives = app.directives || (app.directives = {}));
46847 })(app || (app = {}));
46851 (function (directives) {
46852 var Option = (function () {
46853 function Option() {
46854 this.restrict = 'E';
46855 this.replace = true;
46856 this.controller = 'optionController';
46857 this.bindToController = {
46862 this.templateUrl = 'templates/option.html';
46863 this.controllerAs = 'ctrl';
46865 Option.Factory = function () {
46866 var directive = function () {
46867 return new Option();
46869 directive.$inject = [];
46874 directives.Option = Option;
46875 var OptionController = (function () {
46876 function OptionController() {
46877 var controller = this;
46878 angular.forEach(controller.info.arg, function (arg) {
46879 if (arg.initialValue) {
46880 if (arg.formType === 'number') {
46881 arg.input = parseInt(arg.initialValue);
46884 arg.input = arg.initialValue;
46889 OptionController.$inject = [];
46890 return OptionController;
46892 directives.OptionController = OptionController;
46893 })(directives = app.directives || (app.directives = {}));
46894 })(app || (app = {}));
46898 (function (directives) {
46899 var Directory = (function () {
46900 function Directory() {
46901 this.restrict = 'E';
46902 this.replace = true;
46903 this.controller = 'directoryController';
46904 this.controllerAs = 'ctrl';
46905 this.bindToController = {
46911 this.templateUrl = 'templates/directory.html';
46913 Directory.Factory = function () {
46914 var directive = function () {
46915 return new Directory();
46921 directives.Directory = Directory;
46922 var DirectoryController = (function () {
46923 function DirectoryController(APIEndPoint, $scope) {
46924 this.APIEndPoint = APIEndPoint;
46925 this.$scope = $scope;
46926 var controller = this;
46928 .getFiles(this.info.fileId)
46930 .then(function (result) {
46931 if (result.status === 'success') {
46932 controller.files = result.info;
46933 angular.forEach(result.info, function (file) {
46934 if (file.fileType === '0') {
46936 if (controller.info.path === '/') {
46937 o.path = '/' + file.name;
46940 o.path = controller.info.path + '/' + file.name;
46942 controller.add()(o, controller.list);
46949 DirectoryController.$inject = ['APIEndPoint', '$scope'];
46950 return DirectoryController;
46952 directives.DirectoryController = DirectoryController;
46953 })(directives = app.directives || (app.directives = {}));
46954 })(app || (app = {}));
46958 (function (controllers) {
46959 var Execution = (function () {
46960 function Execution(MyModal, $scope) {
46961 this.MyModal = MyModal;
46962 this.$scope = $scope;
46963 this.commandInfoList = [];
46966 Execution.prototype.add = function () {
46967 this.$scope.$broadcast('close');
46968 var commandInfoList = this.commandInfoList;
46969 var commandInstance = this.MyModal.selectCommand();
46972 .then(function (command) {
46973 commandInfoList.push(new app.declares.CommandInfo(command));
46976 Execution.prototype.open = function () {
46977 var result = this.MyModal.open('SelectCommand');
46978 console.log(result);
46980 Execution.prototype.remove = function (index, list) {
46981 list.splice(index, 1);
46983 Execution.prototype.close = function () {
46984 console.log("close");
46986 Execution.$inject = ['MyModal', '$scope'];
46989 controllers.Execution = Execution;
46990 })(controllers = app.controllers || (app.controllers = {}));
46991 })(app || (app = {}));
46995 (function (controllers) {
46996 var Workspace = (function () {
46997 function Workspace($scope, APIEndPoint, MyModal) {
46998 this.$scope = $scope;
46999 this.APIEndPoint = APIEndPoint;
47000 this.MyModal = MyModal;
47001 this.directoryList = [];
47002 var controller = this;
47003 var directoryList = this.directoryList;
47005 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
47013 directoryList.push(o);
47015 Workspace.prototype.addDirectory = function (info, directoryList) {
47016 directoryList.push(info);
47018 Workspace.prototype.debug = function () {
47019 this.MyModal.preview();
47021 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
47024 controllers.Workspace = Workspace;
47025 })(controllers = app.controllers || (app.controllers = {}));
47026 })(app || (app = {}));
47030 (function (controllers) {
47031 var History = (function () {
47032 function History($scope) {
47033 this.page = "History";
47035 History.$inject = ['$scope'];
47038 controllers.History = History;
47039 })(controllers = app.controllers || (app.controllers = {}));
47040 })(app || (app = {}));
47044 (function (controllers) {
47045 var SelectCommand = (function () {
47046 function SelectCommand($scope, APIEndPoint, $modalInstance) {
47047 this.APIEndPoint = APIEndPoint;
47048 this.$modalInstance = $modalInstance;
47049 var controller = this;
47052 .$promise.then(function (result) {
47053 controller.tags = result.info;
47057 .$promise.then(function (result) {
47058 controller.commands = result.info;
47060 this.currentTag = 'all';
47062 SelectCommand.prototype.changeTag = function (tag) {
47063 this.currentTag = tag;
47065 SelectCommand.prototype.selectCommand = function (command) {
47066 this.$modalInstance.close(command);
47068 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
47069 return SelectCommand;
47071 controllers.SelectCommand = SelectCommand;
47072 })(controllers = app.controllers || (app.controllers = {}));
47073 })(app || (app = {}));
47077 (function (controllers) {
47078 var Preview = (function () {
47079 function Preview($scope, APIEndPoint, $modalInstance) {
47080 this.APIEndPoint = APIEndPoint;
47081 this.$modalInstance = $modalInstance;
47082 var controller = this;
47083 console.log('preview');
47085 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
47088 controllers.Preview = Preview;
47089 })(controllers = app.controllers || (app.controllers = {}));
47090 })(app || (app = {}));
47092 (function (filters) {
47094 return function (commands, tag) {
47096 angular.forEach(commands, function (command) {
47098 angular.forEach(command.tags, function (value) {
47103 result.push(command);
47109 })(filters || (filters = {}));
47113 var appName = 'zephyr';
47114 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
47115 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
47116 $urlRouterProvider.otherwise('/execution');
47117 $locationProvider.html5Mode({
47122 .state('execution', {
47124 templateUrl: 'templates/execution.html',
47125 controller: 'executionController',
47128 .state('workspace', {
47130 templateUrl: 'templates/workspace.html',
47131 controller: 'workspaceController',
47134 .state('history', {
47136 templateUrl: 'templates/history.html',
47137 controller: 'historyController',
47141 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
47142 app.zephyr.filter('Tag', filters.Tag);
47143 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
47144 app.zephyr.controller('previewController', app.controllers.Preview);
47145 app.zephyr.service('MyModal', app.services.MyModal);
47146 app.zephyr.controller('executionController', app.controllers.Execution);
47147 app.zephyr.controller('workspaceController', app.controllers.Workspace);
47148 app.zephyr.controller('historyController', app.controllers.History);
47149 app.zephyr.controller('commandController', app.directives.CommandController);
47150 app.zephyr.controller('optionController', app.directives.OptionController);
47151 app.zephyr.controller('directoryController', app.directives.DirectoryController);
47152 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
47153 app.zephyr.directive('command', app.directives.Command.Factory());
47154 app.zephyr.directive('option', app.directives.Option.Factory());
47155 app.zephyr.directive('directory', app.directives.Directory.Factory());
47156 })(app || (app = {}));
47161 /***/ function(module, exports) {
47166 (function (declares) {
47167 var CommandInfo = (function () {
47168 function CommandInfo(name) {
47171 return CommandInfo;
47173 declares.CommandInfo = CommandInfo;
47174 })(declares = app.declares || (app.declares = {}));
47175 })(app || (app = {}));
47179 (function (services) {
47180 var APIEndPoint = (function () {
47181 function APIEndPoint($resource, $http) {
47182 this.$resource = $resource;
47183 this.$http = $http;
47185 APIEndPoint.prototype.resource = function (endPoint, data) {
47186 var customAction = {
47192 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
47194 return this.$resource(endPoint, {}, { execute: execute });
47196 APIEndPoint.prototype.getOptionControlFile = function (command) {
47197 var endPoint = '/api/v1/optionControlFile/' + command;
47198 return this.resource(endPoint, {}).get();
47200 APIEndPoint.prototype.getFiles = function (fileId) {
47201 var endPoint = '/api/v1/workspace';
47203 endPoint += '/' + fileId;
47205 return this.resource(endPoint, {}).get();
47207 APIEndPoint.prototype.getDirectories = function () {
47208 var endPoint = '/api/v1/all/workspace/directory';
47209 return this.resource(endPoint, {}).get();
47211 APIEndPoint.prototype.getTags = function () {
47212 var endPoint = '/api/v1/tagList';
47213 return this.resource(endPoint, {}).get();
47215 APIEndPoint.prototype.getCommands = function () {
47216 var endPoint = '/api/v1/commandList';
47217 return this.resource(endPoint, {}).get();
47219 APIEndPoint.prototype.execute = function (data) {
47220 var endPoint = '/api/v1/execution';
47221 var fd = new FormData();
47222 fd.append('data', data);
47223 return this.$http.post(endPoint, fd, {
47224 headers: { 'Content-Type': undefined },
47225 transformRequest: angular.identity
47228 return APIEndPoint;
47230 services.APIEndPoint = APIEndPoint;
47231 })(services = app.services || (app.services = {}));
47232 })(app || (app = {}));
47236 (function (services) {
47237 var MyModal = (function () {
47238 function MyModal($uibModal) {
47239 this.$uibModal = $uibModal;
47240 this.modalOption = {
47247 MyModal.prototype.open = function (modalName) {
47248 if (modalName === 'SelectCommand') {
47249 this.modalOption.templateUrl = 'templates/select-command.html';
47250 this.modalOption.size = 'lg';
47252 return this.$uibModal.open(this.modalOption);
47254 MyModal.prototype.selectCommand = function () {
47255 this.modalOption.templateUrl = 'templates/select-command.html';
47256 this.modalOption.controller = 'selectCommandController';
47257 this.modalOption.controllerAs = 'c';
47258 this.modalOption.size = 'lg';
47259 return this.$uibModal.open(this.modalOption);
47261 MyModal.prototype.preview = function () {
47262 this.modalOption.templateUrl = 'templates/preview.html';
47263 this.modalOption.controller = 'previewController';
47264 this.modalOption.controllerAs = 'c';
47265 this.modalOption.size = 'lg';
47266 return this.$uibModal.open(this.modalOption);
47268 MyModal.$inject = ['$uibModal'];
47271 services.MyModal = MyModal;
47272 })(services = app.services || (app.services = {}));
47273 })(app || (app = {}));
47277 (function (directives) {
47278 var Command = (function () {
47279 function Command() {
47280 this.restrict = 'E';
47281 this.replace = true;
47283 this.controller = 'commandController';
47284 this.controllerAs = 'ctrl';
47285 this.bindToController = {
47291 this.templateUrl = 'templates/command.html';
47293 Command.Factory = function () {
47294 var directive = function () {
47295 return new Command();
47297 directive.$inject = [];
47302 directives.Command = Command;
47303 var CommandController = (function () {
47304 function CommandController(APIEndPoint, $scope, MyModal) {
47305 this.APIEndPoint = APIEndPoint;
47306 this.$scope = $scope;
47307 this.MyModal = MyModal;
47308 var controller = this;
47310 .getOptionControlFile('mrcImageNoiseAdd')
47312 .then(function (result) {
47313 controller.options = result.info;
47318 .then(function (result) {
47319 controller.dirs = result.info;
47321 this.heading = "[" + this.index + "]: dcdFilePring";
47322 this.isOpen = true;
47323 this.$scope.$on('close', function () {
47324 controller.isOpen = false;
47327 CommandController.prototype.submit = function () {
47329 angular.forEach(this.options, function (option) {
47331 name: option.option,
47334 angular.forEach(option.arg, function (arg) {
47336 if (typeof arg.input === 'object') {
47337 obj.arguments.push(arg.input.name);
47340 obj.arguments.push(arg.input);
47344 if (obj.arguments.length > 0) {
47349 command: this.name,
47350 workspace: this.workspace.fileId,
47354 .execute(JSON.stringify(execObj))
47355 .then(function (result) {
47356 console.log(result);
47359 CommandController.prototype.removeMySelf = function (index) {
47360 this.remove()(index, this.list);
47362 CommandController.prototype.reloadFiles = function () {
47364 var fileId = this.workspace.fileId;
47368 .then(function (result) {
47369 var status = result.status;
47370 if (status === 'success') {
47371 _this.files = result.info;
47374 console.log(result.message);
47378 CommandController.prototype.debug = function () {
47379 this.MyModal.preview();
47381 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
47382 return CommandController;
47384 directives.CommandController = CommandController;
47385 })(directives = app.directives || (app.directives = {}));
47386 })(app || (app = {}));
47390 (function (directives) {
47391 var HeaderMenu = (function () {
47392 function HeaderMenu() {
47393 this.restrict = 'E';
47394 this.replace = true;
47395 this.templateUrl = 'templates/header-menu.html';
47397 HeaderMenu.Factory = function () {
47398 var directive = function () {
47399 return new HeaderMenu();
47405 directives.HeaderMenu = HeaderMenu;
47406 })(directives = app.directives || (app.directives = {}));
47407 })(app || (app = {}));
47411 (function (directives) {
47412 var Option = (function () {
47413 function Option() {
47414 this.restrict = 'E';
47415 this.replace = true;
47416 this.controller = 'optionController';
47417 this.bindToController = {
47422 this.templateUrl = 'templates/option.html';
47423 this.controllerAs = 'ctrl';
47425 Option.Factory = function () {
47426 var directive = function () {
47427 return new Option();
47429 directive.$inject = [];
47434 directives.Option = Option;
47435 var OptionController = (function () {
47436 function OptionController() {
47437 var controller = this;
47438 angular.forEach(controller.info.arg, function (arg) {
47439 if (arg.initialValue) {
47440 if (arg.formType === 'number') {
47441 arg.input = parseInt(arg.initialValue);
47444 arg.input = arg.initialValue;
47449 OptionController.$inject = [];
47450 return OptionController;
47452 directives.OptionController = OptionController;
47453 })(directives = app.directives || (app.directives = {}));
47454 })(app || (app = {}));
47458 (function (directives) {
47459 var Directory = (function () {
47460 function Directory() {
47461 this.restrict = 'E';
47462 this.replace = true;
47463 this.controller = 'directoryController';
47464 this.controllerAs = 'ctrl';
47465 this.bindToController = {
47471 this.templateUrl = 'templates/directory.html';
47473 Directory.Factory = function () {
47474 var directive = function () {
47475 return new Directory();
47481 directives.Directory = Directory;
47482 var DirectoryController = (function () {
47483 function DirectoryController(APIEndPoint, $scope) {
47484 this.APIEndPoint = APIEndPoint;
47485 this.$scope = $scope;
47486 var controller = this;
47488 .getFiles(this.info.fileId)
47490 .then(function (result) {
47491 if (result.status === 'success') {
47492 controller.files = result.info;
47493 angular.forEach(result.info, function (file) {
47494 if (file.fileType === '0') {
47496 if (controller.info.path === '/') {
47497 o.path = '/' + file.name;
47500 o.path = controller.info.path + '/' + file.name;
47502 controller.add()(o, controller.list);
47509 DirectoryController.$inject = ['APIEndPoint', '$scope'];
47510 return DirectoryController;
47512 directives.DirectoryController = DirectoryController;
47513 })(directives = app.directives || (app.directives = {}));
47514 })(app || (app = {}));
47518 (function (controllers) {
47519 var Execution = (function () {
47520 function Execution(MyModal, $scope) {
47521 this.MyModal = MyModal;
47522 this.$scope = $scope;
47523 this.commandInfoList = [];
47526 Execution.prototype.add = function () {
47527 this.$scope.$broadcast('close');
47528 var commandInfoList = this.commandInfoList;
47529 var commandInstance = this.MyModal.selectCommand();
47532 .then(function (command) {
47533 commandInfoList.push(new app.declares.CommandInfo(command));
47536 Execution.prototype.open = function () {
47537 var result = this.MyModal.open('SelectCommand');
47538 console.log(result);
47540 Execution.prototype.remove = function (index, list) {
47541 list.splice(index, 1);
47543 Execution.prototype.close = function () {
47544 console.log("close");
47546 Execution.$inject = ['MyModal', '$scope'];
47549 controllers.Execution = Execution;
47550 })(controllers = app.controllers || (app.controllers = {}));
47551 })(app || (app = {}));
47555 (function (controllers) {
47556 var Workspace = (function () {
47557 function Workspace($scope, APIEndPoint, MyModal) {
47558 this.$scope = $scope;
47559 this.APIEndPoint = APIEndPoint;
47560 this.MyModal = MyModal;
47561 this.directoryList = [];
47562 var controller = this;
47563 var directoryList = this.directoryList;
47565 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
47573 directoryList.push(o);
47575 Workspace.prototype.addDirectory = function (info, directoryList) {
47576 directoryList.push(info);
47578 Workspace.prototype.debug = function () {
47579 this.MyModal.preview();
47581 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
47584 controllers.Workspace = Workspace;
47585 })(controllers = app.controllers || (app.controllers = {}));
47586 })(app || (app = {}));
47590 (function (controllers) {
47591 var History = (function () {
47592 function History($scope) {
47593 this.page = "History";
47595 History.$inject = ['$scope'];
47598 controllers.History = History;
47599 })(controllers = app.controllers || (app.controllers = {}));
47600 })(app || (app = {}));
47604 (function (controllers) {
47605 var SelectCommand = (function () {
47606 function SelectCommand($scope, APIEndPoint, $modalInstance) {
47607 this.APIEndPoint = APIEndPoint;
47608 this.$modalInstance = $modalInstance;
47609 var controller = this;
47612 .$promise.then(function (result) {
47613 controller.tags = result.info;
47617 .$promise.then(function (result) {
47618 controller.commands = result.info;
47620 this.currentTag = 'all';
47622 SelectCommand.prototype.changeTag = function (tag) {
47623 this.currentTag = tag;
47625 SelectCommand.prototype.selectCommand = function (command) {
47626 this.$modalInstance.close(command);
47628 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
47629 return SelectCommand;
47631 controllers.SelectCommand = SelectCommand;
47632 })(controllers = app.controllers || (app.controllers = {}));
47633 })(app || (app = {}));
47637 (function (controllers) {
47638 var Preview = (function () {
47639 function Preview($scope, APIEndPoint, $modalInstance) {
47640 this.APIEndPoint = APIEndPoint;
47641 this.$modalInstance = $modalInstance;
47642 var controller = this;
47643 console.log('preview');
47645 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
47648 controllers.Preview = Preview;
47649 })(controllers = app.controllers || (app.controllers = {}));
47650 })(app || (app = {}));
47652 (function (filters) {
47654 return function (commands, tag) {
47656 angular.forEach(commands, function (command) {
47658 angular.forEach(command.tags, function (value) {
47663 result.push(command);
47669 })(filters || (filters = {}));
47673 var appName = 'zephyr';
47674 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
47675 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
47676 $urlRouterProvider.otherwise('/execution');
47677 $locationProvider.html5Mode({
47682 .state('execution', {
47684 templateUrl: 'templates/execution.html',
47685 controller: 'executionController',
47688 .state('workspace', {
47690 templateUrl: 'templates/workspace.html',
47691 controller: 'workspaceController',
47694 .state('history', {
47696 templateUrl: 'templates/history.html',
47697 controller: 'historyController',
47701 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
47702 app.zephyr.filter('Tag', filters.Tag);
47703 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
47704 app.zephyr.controller('previewController', app.controllers.Preview);
47705 app.zephyr.service('MyModal', app.services.MyModal);
47706 app.zephyr.controller('executionController', app.controllers.Execution);
47707 app.zephyr.controller('workspaceController', app.controllers.Workspace);
47708 app.zephyr.controller('historyController', app.controllers.History);
47709 app.zephyr.controller('commandController', app.directives.CommandController);
47710 app.zephyr.controller('optionController', app.directives.OptionController);
47711 app.zephyr.controller('directoryController', app.directives.DirectoryController);
47712 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
47713 app.zephyr.directive('command', app.directives.Command.Factory());
47714 app.zephyr.directive('option', app.directives.Option.Factory());
47715 app.zephyr.directive('directory', app.directives.Directory.Factory());
47716 })(app || (app = {}));
47721 /***/ function(module, exports) {
47726 (function (declares) {
47727 var CommandInfo = (function () {
47728 function CommandInfo(name) {
47731 return CommandInfo;
47733 declares.CommandInfo = CommandInfo;
47734 })(declares = app.declares || (app.declares = {}));
47735 })(app || (app = {}));
47739 (function (services) {
47740 var APIEndPoint = (function () {
47741 function APIEndPoint($resource, $http) {
47742 this.$resource = $resource;
47743 this.$http = $http;
47745 APIEndPoint.prototype.resource = function (endPoint, data) {
47746 var customAction = {
47752 headers: { 'Content-Type': undefined, enctype: 'multipart/form-data' }
47754 return this.$resource(endPoint, {}, { execute: execute });
47756 APIEndPoint.prototype.getOptionControlFile = function (command) {
47757 var endPoint = '/api/v1/optionControlFile/' + command;
47758 return this.resource(endPoint, {}).get();
47760 APIEndPoint.prototype.getFiles = function (fileId) {
47761 var endPoint = '/api/v1/workspace';
47763 endPoint += '/' + fileId;
47765 return this.resource(endPoint, {}).get();
47767 APIEndPoint.prototype.getDirectories = function () {
47768 var endPoint = '/api/v1/all/workspace/directory';
47769 return this.resource(endPoint, {}).get();
47771 APIEndPoint.prototype.getTags = function () {
47772 var endPoint = '/api/v1/tagList';
47773 return this.resource(endPoint, {}).get();
47775 APIEndPoint.prototype.getCommands = function () {
47776 var endPoint = '/api/v1/commandList';
47777 return this.resource(endPoint, {}).get();
47779 APIEndPoint.prototype.execute = function (data) {
47780 var endPoint = '/api/v1/execution';
47781 var fd = new FormData();
47782 fd.append('data', data);
47783 return this.$http.post(endPoint, fd, {
47784 headers: { 'Content-Type': undefined },
47785 transformRequest: angular.identity
47788 return APIEndPoint;
47790 services.APIEndPoint = APIEndPoint;
47791 })(services = app.services || (app.services = {}));
47792 })(app || (app = {}));
47796 (function (services) {
47797 var MyModal = (function () {
47798 function MyModal($uibModal) {
47799 this.$uibModal = $uibModal;
47800 this.modalOption = {
47807 MyModal.prototype.open = function (modalName) {
47808 if (modalName === 'SelectCommand') {
47809 this.modalOption.templateUrl = 'templates/select-command.html';
47810 this.modalOption.size = 'lg';
47812 return this.$uibModal.open(this.modalOption);
47814 MyModal.prototype.selectCommand = function () {
47815 this.modalOption.templateUrl = 'templates/select-command.html';
47816 this.modalOption.controller = 'selectCommandController';
47817 this.modalOption.controllerAs = 'c';
47818 this.modalOption.size = 'lg';
47819 return this.$uibModal.open(this.modalOption);
47821 MyModal.prototype.preview = function () {
47822 this.modalOption.templateUrl = 'templates/preview.html';
47823 this.modalOption.controller = 'previewController';
47824 this.modalOption.controllerAs = 'c';
47825 this.modalOption.size = 'lg';
47826 return this.$uibModal.open(this.modalOption);
47828 MyModal.$inject = ['$uibModal'];
47831 services.MyModal = MyModal;
47832 })(services = app.services || (app.services = {}));
47833 })(app || (app = {}));
47837 (function (directives) {
47838 var Command = (function () {
47839 function Command() {
47840 this.restrict = 'E';
47841 this.replace = true;
47843 this.controller = 'commandController';
47844 this.controllerAs = 'ctrl';
47845 this.bindToController = {
47851 this.templateUrl = 'templates/command.html';
47853 Command.Factory = function () {
47854 var directive = function () {
47855 return new Command();
47857 directive.$inject = [];
47862 directives.Command = Command;
47863 var CommandController = (function () {
47864 function CommandController(APIEndPoint, $scope, MyModal) {
47865 this.APIEndPoint = APIEndPoint;
47866 this.$scope = $scope;
47867 this.MyModal = MyModal;
47868 var controller = this;
47870 .getOptionControlFile('mrcImageNoiseAdd')
47872 .then(function (result) {
47873 controller.options = result.info;
47878 .then(function (result) {
47879 controller.dirs = result.info;
47881 this.heading = "[" + this.index + "]: dcdFilePring";
47882 this.isOpen = true;
47883 this.$scope.$on('close', function () {
47884 controller.isOpen = false;
47887 CommandController.prototype.submit = function () {
47889 angular.forEach(this.options, function (option) {
47891 name: option.option,
47894 angular.forEach(option.arg, function (arg) {
47896 if (typeof arg.input === 'object') {
47897 obj.arguments.push(arg.input.name);
47900 obj.arguments.push(arg.input);
47904 if (obj.arguments.length > 0) {
47909 command: this.name,
47910 workspace: this.workspace.fileId,
47914 .execute(JSON.stringify(execObj))
47915 .then(function (result) {
47916 console.log(result);
47919 CommandController.prototype.removeMySelf = function (index) {
47920 this.remove()(index, this.list);
47922 CommandController.prototype.reloadFiles = function () {
47924 var fileId = this.workspace.fileId;
47928 .then(function (result) {
47929 var status = result.status;
47930 if (status === 'success') {
47931 _this.files = result.info;
47934 console.log(result.message);
47938 CommandController.prototype.debug = function () {
47939 this.MyModal.preview();
47941 CommandController.$inject = ['APIEndPoint', '$scope', 'MyModal'];
47942 return CommandController;
47944 directives.CommandController = CommandController;
47945 })(directives = app.directives || (app.directives = {}));
47946 })(app || (app = {}));
47950 (function (directives) {
47951 var HeaderMenu = (function () {
47952 function HeaderMenu() {
47953 this.restrict = 'E';
47954 this.replace = true;
47955 this.templateUrl = 'templates/header-menu.html';
47957 HeaderMenu.Factory = function () {
47958 var directive = function () {
47959 return new HeaderMenu();
47965 directives.HeaderMenu = HeaderMenu;
47966 })(directives = app.directives || (app.directives = {}));
47967 })(app || (app = {}));
47971 (function (directives) {
47972 var Option = (function () {
47973 function Option() {
47974 this.restrict = 'E';
47975 this.replace = true;
47976 this.controller = 'optionController';
47977 this.bindToController = {
47982 this.templateUrl = 'templates/option.html';
47983 this.controllerAs = 'ctrl';
47985 Option.Factory = function () {
47986 var directive = function () {
47987 return new Option();
47989 directive.$inject = [];
47994 directives.Option = Option;
47995 var OptionController = (function () {
47996 function OptionController() {
47997 var controller = this;
47998 angular.forEach(controller.info.arg, function (arg) {
47999 if (arg.initialValue) {
48000 if (arg.formType === 'number') {
48001 arg.input = parseInt(arg.initialValue);
48004 arg.input = arg.initialValue;
48009 OptionController.$inject = [];
48010 return OptionController;
48012 directives.OptionController = OptionController;
48013 })(directives = app.directives || (app.directives = {}));
48014 })(app || (app = {}));
48018 (function (directives) {
48019 var Directory = (function () {
48020 function Directory() {
48021 this.restrict = 'E';
48022 this.replace = true;
48023 this.controller = 'directoryController';
48024 this.controllerAs = 'ctrl';
48025 this.bindToController = {
48031 this.templateUrl = 'templates/directory.html';
48033 Directory.Factory = function () {
48034 var directive = function () {
48035 return new Directory();
48041 directives.Directory = Directory;
48042 var DirectoryController = (function () {
48043 function DirectoryController(APIEndPoint, $scope) {
48044 this.APIEndPoint = APIEndPoint;
48045 this.$scope = $scope;
48046 var controller = this;
48048 .getFiles(this.info.fileId)
48050 .then(function (result) {
48051 if (result.status === 'success') {
48052 controller.files = result.info;
48053 angular.forEach(result.info, function (file) {
48054 if (file.fileType === '0') {
48056 if (controller.info.path === '/') {
48057 o.path = '/' + file.name;
48060 o.path = controller.info.path + '/' + file.name;
48062 controller.add()(o, controller.list);
48069 DirectoryController.$inject = ['APIEndPoint', '$scope'];
48070 return DirectoryController;
48072 directives.DirectoryController = DirectoryController;
48073 })(directives = app.directives || (app.directives = {}));
48074 })(app || (app = {}));
48078 (function (controllers) {
48079 var Execution = (function () {
48080 function Execution(MyModal, $scope) {
48081 this.MyModal = MyModal;
48082 this.$scope = $scope;
48083 this.commandInfoList = [];
48086 Execution.prototype.add = function () {
48087 this.$scope.$broadcast('close');
48088 var commandInfoList = this.commandInfoList;
48089 var commandInstance = this.MyModal.selectCommand();
48092 .then(function (command) {
48093 commandInfoList.push(new app.declares.CommandInfo(command));
48096 Execution.prototype.open = function () {
48097 var result = this.MyModal.open('SelectCommand');
48098 console.log(result);
48100 Execution.prototype.remove = function (index, list) {
48101 list.splice(index, 1);
48103 Execution.prototype.close = function () {
48104 console.log("close");
48106 Execution.$inject = ['MyModal', '$scope'];
48109 controllers.Execution = Execution;
48110 })(controllers = app.controllers || (app.controllers = {}));
48111 })(app || (app = {}));
48115 (function (controllers) {
48116 var Workspace = (function () {
48117 function Workspace($scope, APIEndPoint, MyModal) {
48118 this.$scope = $scope;
48119 this.APIEndPoint = APIEndPoint;
48120 this.MyModal = MyModal;
48121 this.directoryList = [];
48122 var controller = this;
48123 var directoryList = this.directoryList;
48125 fileId: '1f83f620-c1ed-11e5-9657-7942989daa00',
48133 directoryList.push(o);
48135 Workspace.prototype.addDirectory = function (info, directoryList) {
48136 directoryList.push(info);
48138 Workspace.prototype.debug = function () {
48139 this.MyModal.preview();
48141 Workspace.$inject = ['$scope', 'APIEndPoint', 'MyModal'];
48144 controllers.Workspace = Workspace;
48145 })(controllers = app.controllers || (app.controllers = {}));
48146 })(app || (app = {}));
48150 (function (controllers) {
48151 var History = (function () {
48152 function History($scope) {
48153 this.page = "History";
48155 History.$inject = ['$scope'];
48158 controllers.History = History;
48159 })(controllers = app.controllers || (app.controllers = {}));
48160 })(app || (app = {}));
48164 (function (controllers) {
48165 var SelectCommand = (function () {
48166 function SelectCommand($scope, APIEndPoint, $modalInstance) {
48167 this.APIEndPoint = APIEndPoint;
48168 this.$modalInstance = $modalInstance;
48169 var controller = this;
48172 .$promise.then(function (result) {
48173 controller.tags = result.info;
48177 .$promise.then(function (result) {
48178 controller.commands = result.info;
48180 this.currentTag = 'all';
48182 SelectCommand.prototype.changeTag = function (tag) {
48183 this.currentTag = tag;
48185 SelectCommand.prototype.selectCommand = function (command) {
48186 this.$modalInstance.close(command);
48188 SelectCommand.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
48189 return SelectCommand;
48191 controllers.SelectCommand = SelectCommand;
48192 })(controllers = app.controllers || (app.controllers = {}));
48193 })(app || (app = {}));
48197 (function (controllers) {
48198 var Preview = (function () {
48199 function Preview($scope, APIEndPoint, $modalInstance) {
48200 this.APIEndPoint = APIEndPoint;
48201 this.$modalInstance = $modalInstance;
48202 var controller = this;
48203 console.log('preview');
48205 Preview.$inject = ['$scope', 'APIEndPoint', '$uibModalInstance'];
48208 controllers.Preview = Preview;
48209 })(controllers = app.controllers || (app.controllers = {}));
48210 })(app || (app = {}));
48212 (function (filters) {
48214 return function (commands, tag) {
48216 angular.forEach(commands, function (command) {
48218 angular.forEach(command.tags, function (value) {
48223 result.push(command);
48229 })(filters || (filters = {}));
48233 var appName = 'zephyr';
48234 app.zephyr = angular.module(appName, ['ui.router', 'ngResource', 'ui.bootstrap']);
48235 app.zephyr.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
48236 $urlRouterProvider.otherwise('/execution');
48237 $locationProvider.html5Mode({
48242 .state('execution', {
48244 templateUrl: 'templates/execution.html',
48245 controller: 'executionController',
48248 .state('workspace', {
48250 templateUrl: 'templates/workspace.html',
48251 controller: 'workspaceController',
48254 .state('history', {
48256 templateUrl: 'templates/history.html',
48257 controller: 'historyController',
48261 app.zephyr.service('APIEndPoint', app.services.APIEndPoint);
48262 app.zephyr.filter('Tag', filters.Tag);
48263 app.zephyr.controller('selectCommandController', app.controllers.SelectCommand);
48264 app.zephyr.controller('previewController', app.controllers.Preview);
48265 app.zephyr.service('MyModal', app.services.MyModal);
48266 app.zephyr.controller('executionController', app.controllers.Execution);
48267 app.zephyr.controller('workspaceController', app.controllers.Workspace);
48268 app.zephyr.controller('historyController', app.controllers.History);
48269 app.zephyr.controller('commandController', app.directives.CommandController);
48270 app.zephyr.controller('optionController', app.directives.OptionController);
48271 app.zephyr.controller('directoryController', app.directives.DirectoryController);
48272 app.zephyr.directive('headerMenu', app.directives.HeaderMenu.Factory());
48273 app.zephyr.directive('command', app.directives.Command.Factory());
48274 app.zephyr.directive('option', app.directives.Option.Factory());
48275 app.zephyr.directive('directory', app.directives.Directory.Factory());
48276 })(app || (app = {}));