* **Best Practice**: Always provide a `cloneFn` (clone attach function) when you call a transclude function
@@ -7696,6 +7703,16 @@ function $TemplateCacheProvider() {
*
* For information on how the compiler works, see the
* {@link guide/compiler Angular HTML Compiler} section of the Developer Guide.
+ *
+ * @knownIssue
+ *
+ * ### Double Compilation
+ *
+ Double compilation occurs when an already compiled part of the DOM gets
+ compiled again. This is an undesired effect and can lead to misbehaving directives, performance issues,
+ and memory leaks. Refer to the Compiler Guide {@link guide/compiler#double-compilation-and-how-to-avoid-it
+ section on double compilation} for an in-depth explanation and ways to avoid it.
+ *
*/
var $compileMinErr = minErr('$compile');
@@ -7714,8 +7731,8 @@ $CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider'];
function $CompileProvider($provide, $$sanitizeUriProvider) {
var hasDirectives = {},
Suffix = 'Directive',
- COMMENT_DIRECTIVE_REGEXP = /^\s*directive:\s*([\w\-]+)\s+(.*)$/,
- CLASS_DIRECTIVE_REGEXP = /(([\w\-]+)(?::([^;]+))?;?)/,
+ COMMENT_DIRECTIVE_REGEXP = /^\s*directive:\s*([\w-]+)\s+(.*)$/,
+ CLASS_DIRECTIVE_REGEXP = /(([\w-]+)(?::([^;]+))?;?)/,
ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'),
REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/;
@@ -7779,20 +7796,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
bindings.bindToController =
parseIsolateBindings(directive.bindToController, directiveName, true);
}
- if (isObject(bindings.bindToController)) {
- var controller = directive.controller;
- var controllerAs = directive.controllerAs;
- if (!controller) {
- // There is no controller, there may or may not be a controllerAs property
- throw $compileMinErr('noctrl',
- 'Cannot bind to controller without directive \'{0}\'s controller.',
- directiveName);
- } else if (!identifierForController(controller, controllerAs)) {
- // There is a controller, but no identifier or controllerAs property
- throw $compileMinErr('noident',
- 'Cannot bind to controller without identifier for directive \'{0}\'.',
- directiveName);
- }
+ if (bindings.bindToController && !directive.controller) {
+ // There is no controller
+ throw $compileMinErr('noctrl',
+ 'Cannot bind to controller without directive \'{0}\'s controller.',
+ directiveName);
}
return bindings;
}
@@ -7823,6 +7831,17 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return require;
}
+ function getDirectiveRestrict(restrict, name) {
+ if (restrict && !(isString(restrict) && /[EACM]/.test(restrict))) {
+ throw $compileMinErr('badrestrict',
+ 'Restrict property \'{0}\' of directive \'{1}\' is invalid',
+ restrict,
+ name);
+ }
+
+ return restrict || 'EA';
+ }
+
/**
* @ngdoc method
* @name $compileProvider#directive
@@ -7839,6 +7858,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* @returns {ng.$compileProvider} Self for chaining.
*/
this.directive = function registerDirective(name, directiveFactory) {
+ assertArg(name, 'name');
assertNotHasOwnProperty(name, 'directive');
if (isString(name)) {
assertValidDirectiveName(name);
@@ -7860,7 +7880,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
directive.index = index;
directive.name = directive.name || name;
directive.require = getDirectiveRequire(directive);
- directive.restrict = directive.restrict || 'EA';
+ directive.restrict = getDirectiveRestrict(directive.restrict, name);
directive.$$moduleName = directiveFactory.$$moduleName;
directives.push(directive);
} catch (e) {
@@ -8109,6 +8129,35 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return debugInfoEnabled;
};
+ /**
+ * @ngdoc method
+ * @name $compileProvider#preAssignBindingsEnabled
+ *
+ * @param {boolean=} enabled update the preAssignBindingsEnabled state if provided, otherwise just return the
+ * current preAssignBindingsEnabled state
+ * @returns {*} current value if used as getter or itself (chaining) if used as setter
+ *
+ * @kind function
+ *
+ * @description
+ * Call this method to enable/disable whether directive controllers are assigned bindings before
+ * calling the controller's constructor.
+ * If enabled (true), the compiler assigns the value of each of the bindings to the
+ * properties of the controller object before the constructor of this object is called.
+ *
+ * If disabled (false), the compiler calls the constructor first before assigning bindings.
+ *
+ * The default value is true in Angular 1.5.x but will switch to false in Angular 1.6.x.
+ */
+ var preAssignBindingsEnabled = true;
+ this.preAssignBindingsEnabled = function(enabled) {
+ if (isDefined(enabled)) {
+ preAssignBindingsEnabled = enabled;
+ return this;
+ }
+ return preAssignBindingsEnabled;
+ };
+
var TTL = 10;
/**
@@ -8920,7 +8969,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
/**
- * Given a node with an directive-start it collects all of the siblings until it finds
+ * Given a node with a directive-start it collects all of the siblings until it finds
* directive-end.
* @param node
* @param attrStart
@@ -9107,7 +9156,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
if (!directive.templateUrl && directive.controller) {
- directiveValue = directive.controller;
controllerDirectives = controllerDirectives || createMap();
assertNoDuplicate('\'' + directiveName + '\' controller',
controllerDirectives[directiveName], directive, $compileNode);
@@ -9406,22 +9454,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var controller = elementControllers[name];
var bindings = controllerDirective.$$bindings.bindToController;
- if (controller.identifier && bindings) {
- controller.bindingInfo =
- initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
- } else {
- controller.bindingInfo = {};
- }
-
- var controllerResult = controller();
- if (controllerResult !== controller.instance) {
- // If the controller constructor has a return value, overwrite the instance
- // from setupControllers
- controller.instance = controllerResult;
- $element.data('$' + controllerDirective.name + 'Controller', controllerResult);
- if (controller.bindingInfo.removeWatches) {
- controller.bindingInfo.removeWatches();
+ if (preAssignBindingsEnabled) {
+ if (bindings) {
+ controller.bindingInfo =
+ initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
+ } else {
+ controller.bindingInfo = {};
}
+
+ var controllerResult = controller();
+ if (controllerResult !== controller.instance) {
+ // If the controller constructor has a return value, overwrite the instance
+ // from setupControllers
+ controller.instance = controllerResult;
+ $element.data('$' + controllerDirective.name + 'Controller', controllerResult);
+ if (controller.bindingInfo.removeWatches) {
+ controller.bindingInfo.removeWatches();
+ }
+ controller.bindingInfo =
+ initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
+ }
+ } else {
+ controller.instance = controller();
+ $element.data('$' + controllerDirective.name + 'Controller', controller.instance);
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
}
@@ -9650,24 +9705,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (hasDirectives.hasOwnProperty(name)) {
for (var directive, directives = $injector.get(name + Suffix),
i = 0, ii = directives.length; i < ii; i++) {
- try {
- directive = directives[i];
- if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
- directive.restrict.indexOf(location) !== -1) {
- if (startAttrName) {
- directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
- }
- if (!directive.$$bindings) {
- var bindings = directive.$$bindings =
- parseDirectiveBindings(directive, directive.name);
- if (isObject(bindings.isolateScope)) {
- directive.$$isolateBindings = bindings.isolateScope;
- }
- }
- tDirectives.push(directive);
- match = directive;
+ directive = directives[i];
+ if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
+ directive.restrict.indexOf(location) !== -1) {
+ if (startAttrName) {
+ directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
}
- } catch (e) { $exceptionHandler(e); }
+ if (!directive.$$bindings) {
+ var bindings = directive.$$bindings =
+ parseDirectiveBindings(directive, directive.name);
+ if (isObject(bindings.isolateScope)) {
+ directive.$$isolateBindings = bindings.isolateScope;
+ }
+ }
+ tDirectives.push(directive);
+ match = directive;
+ }
}
}
return match;
@@ -9937,16 +9990,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
- function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) {
+ function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
var trustedContext = getTrustedContext(node, name);
- allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing;
+ var mustHaveExpression = !isNgAttr;
+ var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
- var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing);
+ var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
// no interpolation found -> ignore
if (!interpolateFn) return;
-
if (name === 'multiple' && nodeName_(node) === 'select') {
throw $compileMinErr('selmulti',
'Binding to the \'multiple\' attribute is not supported. Element: {0}',
@@ -10099,8 +10152,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
- // Set up $watches for isolate scope and controller bindings. This process
- // only occurs for isolate scopes and new scopes with controllerAs.
+ // Set up $watches for isolate scope and controller bindings.
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
var removeWatchCollection = [];
var initialChanges = {};
@@ -10118,7 +10170,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (!optional && !hasOwnProperty.call(attrs, attrName)) {
destination[scopeName] = attrs[attrName] = undefined;
}
- attrs.$observe(attrName, function(value) {
+ removeWatch = attrs.$observe(attrName, function(value) {
if (isString(value) || isBoolean(value)) {
var oldValue = destination[scopeName];
recordChanges(scopeName, value, oldValue);
@@ -10137,6 +10189,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
destination[scopeName] = lastValue;
}
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
+ removeWatchCollection.push(removeWatch);
break;
case '=':
@@ -10192,18 +10245,21 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (optional && !attrs[attrName]) break;
parentGet = $parse(attrs[attrName]);
+ var deepWatch = parentGet.literal;
var initialValue = destination[scopeName] = parentGet(scope);
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
removeWatch = scope.$watch(parentGet, function parentValueWatchAction(newValue, oldValue) {
if (oldValue === newValue) {
- if (oldValue === initialValue) return;
+ if (oldValue === initialValue || (deepWatch && equals(oldValue, initialValue))) {
+ return;
+ }
oldValue = initialValue;
}
recordChanges(scopeName, newValue, oldValue);
destination[scopeName] = newValue;
- }, parentGet.literal);
+ }, deepWatch);
removeWatchCollection.push(removeWatch);
break;
@@ -10223,7 +10279,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
});
function recordChanges(key, currentValue, previousValue) {
- if (isFunction(destination.$onChanges) && currentValue !== previousValue) {
+ if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
+ // eslint-disable-next-line no-self-compare
+ (currentValue === currentValue || previousValue === previousValue)) {
// If we have not already scheduled the top level onChangesQueue handler then do so now
if (!onChangesQueue) {
scope.$$postDigest(flushOnChangesQueue);
@@ -10363,8 +10421,9 @@ function removeComments(jqNodes) {
while (i--) {
var node = jqNodes[i];
- if (node.nodeType === NODE_TYPE_COMMENT) {
- splice.call(jqNodes, i, 1);
+ if (node.nodeType === NODE_TYPE_COMMENT ||
+ (node.nodeType === NODE_TYPE_TEXT && node.nodeValue.trim() === '')) {
+ splice.call(jqNodes, i, 1);
}
}
return jqNodes;
@@ -10428,7 +10487,13 @@ function $ControllerProvider() {
/**
* @ngdoc method
* @name $controllerProvider#allowGlobals
- * @description If called, allows `$controller` to find controller constructors on `window`
+ *
+ * @deprecated
+ * sinceVersion="v1.3.0"
+ * removeVersion="v1.7.0"
+ * This method of finding controllers has been deprecated.
+ *
+ * @description If called, allows `$controller` to find controller constructors on `window` *
*/
this.allowGlobals = function() {
globals = true;
@@ -10492,6 +10557,11 @@ function $ControllerProvider() {
: getter(locals.$scope, constructor, true) ||
(globals ? getter($window, constructor, true) : undefined);
+ if (!expression) {
+ throw $controllerMinErr('ctrlreg',
+ 'The controller with the name \'{0}\' is not registered.', constructor);
+ }
+
assertArgFn(expression, constructor, true);
}
@@ -10665,7 +10735,7 @@ var JSON_ENDS = {
'[': /]$/,
'{': /}$/
};
-var JSON_PROTECTION_PREFIX = /^\)\]\}',?\n/;
+var JSON_PROTECTION_PREFIX = /^\)]\}',?\n/;
var $httpMinErr = minErr('$http');
var $httpMinErrLegacyFn = function(method) {
return function() {
@@ -10853,7 +10923,7 @@ function parseHeaders(headers) {
* @param {(string|Object)} headers Headers to provide access to.
* @returns {function(string=)} Returns a getter function which if called with:
*
- * - if called with single an argument returns a single header value or null
+ * - if called with an argument returns a single header value or null
* - if called with no arguments returns an object containing all headers.
*/
function headersGetter(headers) {
@@ -11004,6 +11074,11 @@ function $HttpProvider() {
* @name $httpProvider#useLegacyPromiseExtensions
* @description
*
+ * @deprecated
+ * sinceVersion="v1.4.4"
+ * removeVersion="v1.6.0"
+ * This method will be removed in v1.6.0 along with the legacy promise methods.
+ *
* Configure `$http` service to return promises without the shorthand methods `success` and `error`.
* This should be used to make sure that applications work without these methods.
*
@@ -11157,7 +11232,8 @@ function $HttpProvider() {
*
* ## Deprecation Notice
*
- * The `$http` legacy promise methods `success` and `error` have been deprecated.
+ * The `$http` legacy promise methods `success` and `error` have been deprecated and will be
+ * removed in v1.6.0.
* Use the standard `then` method instead.
* If {@link $httpProvider#useLegacyPromiseExtensions `$httpProvider.useLegacyPromiseExtensions`} is set to
* `false` then these methods will throw {@link $http:legacy `$http/legacy`} error.
@@ -11170,7 +11246,7 @@ function $HttpProvider() {
* object, which currently contains this default configuration:
*
* - `$httpProvider.defaults.headers.common` (headers that are common for all requests):
- * - `Accept: application/json, text/plain, * / *`
+ * - Accept: application/json, text/plain, \*/\*
* - `$httpProvider.defaults.headers.post`: (header defaults for POST requests)
* - `Content-Type: application/json`
* - `$httpProvider.defaults.headers.put` (header defaults for PUT requests)
@@ -11797,7 +11873,7 @@ function $HttpProvider() {
*
* @description
* Shortcut method to perform `JSONP` request.
- * If you would like to customise where and how the callbacks are stored then try overriding
+ * If you would like to customize where and how the callbacks are stored then try overriding
* or decorating the {@link $jsonpCallbacks} service.
*
* @param {string} url Relative or absolute URL specifying the destination of the request.
@@ -12689,7 +12765,8 @@ function $IntervalProvider() {
* appropriate moment. See the example below for more details on how and when to do this.
*
*
- * @param {function()} fn A function that should be called repeatedly.
+ * @param {function()} fn A function that should be called repeatedly. If no additional arguments
+ * are passed (see below), the function is called with the current iteration count.
* @param {number} delay Number of milliseconds between each function call.
* @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
* indefinitely.
@@ -12948,7 +13025,7 @@ var $jsonpCallbacksProvider = /** @this */ function() {
* * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`)
*/
-var PATH_MATCH = /^([^\?#]*)(\?([^#]*))?(#(.*))?$/,
+var PATH_MATCH = /^([^?#]*)(\?([^#]*))?(#(.*))?$/,
DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21};
var $locationMinErr = minErr('$location');
@@ -13001,8 +13078,8 @@ function parseAppUrl(url, locationObj) {
}
}
-function startsWith(haystack, needle) {
- return haystack.lastIndexOf(needle, 0) === 0;
+function startsWith(str, search) {
+ return str.slice(0, search.length) === search;
}
/**
@@ -13040,13 +13117,13 @@ function serverBase(url) {
/**
- * LocationHtml5Url represents an url
+ * LocationHtml5Url represents a URL
* This object is exposed as $location service when HTML5 mode is enabled and supported
*
* @constructor
* @param {string} appBase application base URL
* @param {string} appBaseNoFile application base URL stripped of any filename
- * @param {string} basePrefix url path prefix
+ * @param {string} basePrefix URL path prefix
*/
function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
this.$$html5 = true;
@@ -13055,8 +13132,8 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
/**
- * Parse given html5 (regular) url string into properties
- * @param {string} url HTML5 url
+ * Parse given HTML5 (regular) URL string into properties
+ * @param {string} url HTML5 URL
* @private
*/
this.$$parse = function(url) {
@@ -13119,7 +13196,7 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
/**
- * LocationHashbangUrl represents url
+ * LocationHashbangUrl represents URL
* This object is exposed as $location service when developer doesn't opt into html5 mode.
* It also serves as the base class for html5 mode fallback on legacy browsers.
*
@@ -13134,8 +13211,8 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
/**
- * Parse given hashbang url into properties
- * @param {string} url Hashbang url
+ * Parse given hashbang URL into properties
+ * @param {string} url Hashbang URL
* @private
*/
this.$$parse = function(url) {
@@ -13144,7 +13221,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {
- // The rest of the url starts with a hash so we have
+ // The rest of the URL starts with a hash so we have
// got either a hashbang path or a plain hash fragment
withoutHashUrl = stripBaseUrl(hashPrefix, withoutBaseUrl);
if (isUndefined(withoutHashUrl)) {
@@ -13209,7 +13286,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
};
/**
- * Compose hashbang url and update `absUrl` property
+ * Compose hashbang URL and update `absUrl` property
* @private
*/
this.$$compose = function() {
@@ -13231,7 +13308,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
/**
- * LocationHashbangUrl represents url
+ * LocationHashbangUrl represents URL
* This object is exposed as $location service when html5 history api is enabled but the browser
* does not support it.
*
@@ -13283,7 +13360,7 @@ function LocationHashbangInHtml5Url(appBase, appBaseNoFile, hashPrefix) {
var locationPrototype = {
/**
- * Ensure absolute url is initialized.
+ * Ensure absolute URL is initialized.
* @private
*/
$$absUrl:'',
@@ -13307,17 +13384,17 @@ var locationPrototype = {
* @description
* This method is getter only.
*
- * Return full url representation with all segments encoded according to rules specified in
+ * Return full URL representation with all segments encoded according to rules specified in
* [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var absUrl = $location.absUrl();
* // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
* ```
*
- * @return {string} full url
+ * @return {string} full URL
*/
absUrl: locationGetter('$$absUrl'),
@@ -13328,18 +13405,18 @@ var locationPrototype = {
* @description
* This method is getter / setter.
*
- * Return url (e.g. `/path?a=b#hash`) when called without any parameter.
+ * Return URL (e.g. `/path?a=b#hash`) when called without any parameter.
*
* Change path, search and hash, when called with parameter and return `$location`.
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var url = $location.url();
* // => "/some/path?foo=bar&baz=xoxo"
* ```
*
- * @param {string=} url New url without base prefix (e.g. `/path?a=b#hash`)
+ * @param {string=} url New URL without base prefix (e.g. `/path?a=b#hash`)
* @return {string} url
*/
url: function(url) {
@@ -13362,16 +13439,16 @@ var locationPrototype = {
* @description
* This method is getter only.
*
- * Return protocol of current url.
+ * Return protocol of current URL.
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var protocol = $location.protocol();
* // => "http"
* ```
*
- * @return {string} protocol of current url
+ * @return {string} protocol of current URL
*/
protocol: locationGetter('$$protocol'),
@@ -13382,24 +13459,24 @@ var locationPrototype = {
* @description
* This method is getter only.
*
- * Return host of current url.
+ * Return host of current URL.
*
* Note: compared to the non-angular version `location.host` which returns `hostname:port`, this returns the `hostname` portion only.
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var host = $location.host();
* // => "example.com"
*
- * // given url http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
* host = $location.host();
* // => "example.com"
* host = location.host;
* // => "example.com:8080"
* ```
*
- * @return {string} host of current url.
+ * @return {string} host of current URL.
*/
host: locationGetter('$$host'),
@@ -13410,11 +13487,11 @@ var locationPrototype = {
* @description
* This method is getter only.
*
- * Return port of current url.
+ * Return port of current URL.
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var port = $location.port();
* // => 80
* ```
@@ -13430,7 +13507,7 @@ var locationPrototype = {
* @description
* This method is getter / setter.
*
- * Return path of current url when called without any parameter.
+ * Return path of current URL when called without any parameter.
*
* Change path when called with parameter and return `$location`.
*
@@ -13439,7 +13516,7 @@ var locationPrototype = {
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var path = $location.path();
* // => "/some/path"
* ```
@@ -13459,13 +13536,13 @@ var locationPrototype = {
* @description
* This method is getter / setter.
*
- * Return search part (as object) of current url when called without any parameter.
+ * Return search part (as object) of current URL when called without any parameter.
*
* Change search part when called with parameter and return `$location`.
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
* var searchObject = $location.search();
* // => {foo: 'bar', baz: 'xoxo'}
*
@@ -13481,7 +13558,7 @@ var locationPrototype = {
* of `$location` to the specified value.
*
* If the argument is a hash object containing an array of values, these values will be encoded
- * as duplicate search parameters in the url.
+ * as duplicate search parameters in the URL.
*
* @param {(string|Number|Array
|boolean)=} paramValue If `search` is a string or number, then `paramValue`
* will override only a single search property.
@@ -13543,7 +13620,7 @@ var locationPrototype = {
*
*
* ```js
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
* var hash = $location.hash();
* // => "hashValue"
* ```
@@ -13677,6 +13754,7 @@ function $LocationProvider() {
* @ngdoc method
* @name $locationProvider#hashPrefix
* @description
+ * The default value for the prefix is `''`.
* @param {string=} prefix Prefix for hash part (containing path and search)
* @returns {*} current value if used as getter or itself (chaining) if used as setter
*/
@@ -13703,8 +13781,12 @@ function $LocationProvider() {
* whether or not a tag is required to be present. If `enabled` and `requireBase` are
* true, and a base tag is not present, an error will be thrown when `$location` is injected.
* See the {@link guide/$location $location guide for more information}
- * - **rewriteLinks** - `{boolean}` - (default: `true`) When html5Mode is enabled,
- * enables/disables url rewriting for relative links.
+ * - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
+ * enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
+ * only happen on links with an attribute that matches the given string. For example, if set
+ * to `'internal-link'`, then the URL will only be rewritten for `` links.
+ * Note that [attribute name normalization](guide/directive#normalization) does not apply
+ * here, so `'internalLink'` will **not** match `'internal-link'`.
*
* @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
*/
@@ -13722,7 +13804,7 @@ function $LocationProvider() {
html5Mode.requireBase = mode.requireBase;
}
- if (isBoolean(mode.rewriteLinks)) {
+ if (isBoolean(mode.rewriteLinks) || isString(mode.rewriteLinks)) {
html5Mode.rewriteLinks = mode.rewriteLinks;
}
@@ -13819,10 +13901,11 @@ function $LocationProvider() {
}
$rootElement.on('click', function(event) {
+ var rewriteLinks = html5Mode.rewriteLinks;
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
// currently we open nice url link and redirect then
- if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.shiftKey || event.which === 2 || event.button === 2) return;
+ if (!rewriteLinks || event.ctrlKey || event.metaKey || event.shiftKey || event.which === 2 || event.button === 2) return;
var elm = jqLite(event.target);
@@ -13832,6 +13915,8 @@ function $LocationProvider() {
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
}
+ if (isString(rewriteLinks) && isUndefined(elm.attr(rewriteLinks))) return;
+
var absHref = elm.prop('href');
// get the actual href attribute - see
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
@@ -14556,6 +14641,10 @@ AST.prototype = {
assignment: function() {
var result = this.ternary();
if (this.expect('=')) {
+ if (!isAssignable(result)) {
+ throw $parseMinErr('lval', 'Trying to assign a value to a non l-value');
+ }
+
result = { type: AST.AssignmentExpression, left: result, right: this.assignment(), operator: '='};
}
return result;
@@ -15268,9 +15357,6 @@ ASTCompiler.prototype = {
case AST.AssignmentExpression:
right = this.nextId();
left = {};
- if (!isAssignable(ast.left)) {
- throw $parseMinErr('lval', 'Trying to assign a value to a non l-value');
- }
this.recurse(ast.left, undefined, left, function() {
self.if_(self.notNull(left.context), function() {
self.recurse(ast.right, right);
@@ -16020,7 +16106,7 @@ function $ParseProvider() {
* representation. It is expected for the function to return `true` or `false`, whether that
* character is allowed or not.
*
- * Since this function will be called extensivelly, keep the implementation of these functions fast,
+ * Since this function will be called extensively, keep the implementation of these functions fast,
* as the performance of these functions have a direct impact on the expressions parsing speed.
*
* @param {function=} identifierStart The function that will decide whether the given character is
@@ -16545,14 +16631,14 @@ function qFactory(nextTick, exceptionHandler) {
*
* @returns {Deferred} Returns a new instance of deferred.
*/
- var defer = function() {
+ function defer() {
var d = new Deferred();
//Necessary to support unbound execution :/
d.resolve = simpleBind(d, d.resolve);
d.reject = simpleBind(d, d.reject);
d.notify = simpleBind(d, d.notify);
return d;
- };
+ }
function Promise() {
this.$$state = { status: 0 };
@@ -16578,9 +16664,9 @@ function qFactory(nextTick, exceptionHandler) {
'finally': function(callback, progressBack) {
return this.then(function(value) {
- return handleCallback(value, true, callback);
+ return handleCallback(value, resolve, callback);
}, function(error) {
- return handleCallback(error, false, callback);
+ return handleCallback(error, reject, callback);
}, progressBack);
}
});
@@ -16738,39 +16824,27 @@ function qFactory(nextTick, exceptionHandler) {
* @param {*} reason Constant, message, exception or an object representing the rejection reason.
* @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`.
*/
- var reject = function(reason) {
+ function reject(reason) {
var result = new Deferred();
result.reject(reason);
return result.promise;
- };
+ }
- var makePromise = function makePromise(value, resolved) {
- var result = new Deferred();
- if (resolved) {
- result.resolve(value);
- } else {
- result.reject(value);
- }
- return result.promise;
- };
-
- var handleCallback = function handleCallback(value, isResolved, callback) {
+ function handleCallback(value, resolver, callback) {
var callbackOutput = null;
try {
if (isFunction(callback)) callbackOutput = callback();
} catch (e) {
- return makePromise(e, false);
+ return reject(e);
}
if (isPromiseLike(callbackOutput)) {
return callbackOutput.then(function() {
- return makePromise(value, isResolved);
- }, function(error) {
- return makePromise(error, false);
- });
+ return resolver(value);
+ }, reject);
} else {
- return makePromise(value, isResolved);
+ return resolver(value);
}
- };
+ }
/**
* @ngdoc method
@@ -16790,11 +16864,11 @@ function qFactory(nextTick, exceptionHandler) {
*/
- var when = function(value, callback, errback, progressBack) {
+ function when(value, callback, errback, progressBack) {
var result = new Deferred();
result.resolve(value);
return result.promise.then(callback, errback, progressBack);
- };
+ }
/**
* @ngdoc method
@@ -16836,11 +16910,9 @@ function qFactory(nextTick, exceptionHandler) {
forEach(promises, function(promise, key) {
counter++;
when(promise).then(function(value) {
- if (results.hasOwnProperty(key)) return;
results[key] = value;
if (!(--counter)) deferred.resolve(results);
}, function(reason) {
- if (results.hasOwnProperty(key)) return;
deferred.reject(reason);
});
});
@@ -16876,7 +16948,7 @@ function qFactory(nextTick, exceptionHandler) {
return deferred.promise;
}
- var $Q = function Q(resolver) {
+ function $Q(resolver) {
if (!isFunction(resolver)) {
throw $qMinErr('norslvr', 'Expected resolverFn, got \'{0}\'', resolver);
}
@@ -16894,7 +16966,7 @@ function qFactory(nextTick, exceptionHandler) {
resolver(resolveFn, rejectFn);
return deferred.promise;
- };
+ }
// Let's make the instanceof operator work for promises, so that
// `new $q(fn) instanceof $q` would evaluate to true.
@@ -17226,7 +17298,7 @@ function $RootScopeProvider() {
* $digest()} and should return the value that will be watched. (`watchExpression` should not change
* its value when executed multiple times with the same input because it may be executed multiple
* times by {@link ng.$rootScope.Scope#$digest $digest()}. That is, `watchExpression` should be
- * [idempotent](http://en.wikipedia.org/wiki/Idempotence).
+ * [idempotent](http://en.wikipedia.org/wiki/Idempotence).)
* - The `listener` is called only when the value from the current `watchExpression` and the
* previous call to `watchExpression` are not equal (with the exception of the initial run,
* see below). Inequality is determined according to reference inequality,
@@ -17354,15 +17426,21 @@ function $RootScopeProvider() {
if (!array) {
array = scope.$$watchers = [];
+ array.$$digestWatchIndex = -1;
}
// we use unshift since we use a while loop in $digest for speed.
// the while loop reads in reverse order.
array.unshift(watcher);
+ array.$$digestWatchIndex++;
incrementWatchersCount(this, 1);
return function deregisterWatch() {
- if (arrayRemove(array, watcher) >= 0) {
+ var index = arrayRemove(array, watcher);
+ if (index >= 0) {
incrementWatchersCount(scope, -1);
+ if (index < array.$$digestWatchIndex) {
+ array.$$digestWatchIndex--;
+ }
}
lastDirtyWatch = null;
};
@@ -17377,8 +17455,8 @@ function $RootScopeProvider() {
* A variant of {@link ng.$rootScope.Scope#$watch $watch()} where it watches an array of `watchExpressions`.
* If any one expression in the collection changes the `listener` is executed.
*
- * - The items in the `watchExpressions` array are observed via standard $watch operation and are examined on every
- * call to $digest() to see if any items changes.
+ * - The items in the `watchExpressions` array are observed via the standard `$watch` operation. Their return
+ * values are examined for changes on every call to `$digest`.
* - The `listener` is called whenever any expression in the `watchExpressions` array changes.
*
* @param {Array.} watchExpressions Array of expressions that will be individually
@@ -17695,7 +17773,6 @@ function $RootScopeProvider() {
$digest: function() {
var watch, value, last, fn, get,
watchers,
- length,
dirty, ttl = TTL,
next, current, target = this,
watchLog = [],
@@ -17736,10 +17813,10 @@ function $RootScopeProvider() {
do { // "traverse the scopes" loop
if ((watchers = current.$$watchers)) {
// process our watches
- length = watchers.length;
- while (length--) {
+ watchers.$$digestWatchIndex = watchers.length;
+ while (watchers.$$digestWatchIndex--) {
try {
- watch = watchers[length];
+ watch = watchers[watchers.$$digestWatchIndex];
// Most common watches are on primitives, in which case we can short
// circuit it with === operator, only when === fails do we use .equals
if (watch) {
@@ -18452,8 +18529,8 @@ function adjustMatcher(matcher) {
'Illegal sequence *** in string matcher. String: {0}', matcher);
}
matcher = escapeForRegexp(matcher).
- replace('\\*\\*', '.*').
- replace('\\*', '[^:/.?&;]*');
+ replace(/\\\*\\\*/g, '.*').
+ replace(/\\\*/g, '[^:/.?&;]*');
return new RegExp('^' + matcher + '$');
} else if (isRegExp(matcher)) {
// The only other type of matcher allowed is a Regexp.
@@ -20310,7 +20387,7 @@ function $FilterProvider($provide) {
*
* The final result is an array of those elements that the predicate returned true for.
*
- * @param {function(actual, expected)|true|undefined} comparator Comparator which is used in
+ * @param {function(actual, expected)|true|false} [comparator] Comparator which is used in
* determining if the expected value (from the filter expression) and actual value (from
* the object in the array) should be considered a match.
*
@@ -20323,13 +20400,14 @@ function $FilterProvider($provide) {
* - `true`: A shorthand for `function(actual, expected) { return angular.equals(actual, expected)}`.
* This is essentially strict comparison of expected and actual.
*
- * - `false|undefined`: A short hand for a function which will look for a substring match in case
- * insensitive way.
+ * - `false`: A short hand for a function which will look for a substring match in a case
+ * insensitive way. Primitive values are converted to strings. Objects are not compared against
+ * primitives, unless they have a custom `toString` method (e.g. `Date` objects).
*
- * Primitive values are converted to strings. Objects are not compared against primitives,
- * unless they have a custom `toString` method (e.g. `Date` objects).
*
- * @param {string=} anyPropertyKey The special property name that matches against any property.
+ * Defaults to `false`.
+ *
+ * @param {string} [anyPropertyKey] The special property name that matches against any property.
* By default `$`.
*
* @example
@@ -21004,7 +21082,7 @@ var DATE_FORMATS = {
};
var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/,
- NUMBER_STRING = /^\-?\d+$/;
+ NUMBER_STRING = /^-?\d+$/;
/**
* @ngdoc filter
@@ -21091,7 +21169,7 @@ var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+
expect(element(by.binding("1288323623006 | date:'medium'")).getText()).
toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/);
expect(element(by.binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).getText()).
- toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/);
+ toMatch(/2010-10-2\d \d{2}:\d{2}:\d{2} (-|\+)?\d{4}/);
expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()).
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/);
expect(element(by.binding("'1288323623006' | date:\"MM/dd/yyyy 'at' h:mma\"")).getText()).
@@ -21387,7 +21465,7 @@ function sliceFn(input, begin, end) {
* String, etc).
*
* The `expression` can be a single predicate, or a list of predicates each serving as a tie-breaker
- * for the preceeding one. The `expression` is evaluated against each item and the output is used
+ * for the preceding one. The `expression` is evaluated against each item and the output is used
* for comparing with other items.
*
* You can change the sorting order by setting `reverse` to `true`. By default, items are sorted in
@@ -21457,6 +21535,9 @@ function sliceFn(input, begin, end) {
*
* **Note:** If you notice numbers not being sorted as expected, make sure they are actually being
* saved as numbers and not strings.
+ * **Note:** For the purpose of sorting, `null` values are treated as the string `'null'` (i.e.
+ * `type: 'string'`, `value: 'null'`). This may cause unexpected sort order relative to
+ * other values.
*
* @param {Array|ArrayLike} collection - The collection (array or array-like object) to sort.
* @param {(Function|string|Array.)=} expression - A predicate (or list of
@@ -22078,12 +22159,10 @@ function ngDirective(directive) {
* @restrict E
*
* @description
- * Modifies the default behavior of the html A tag so that the default action is prevented when
+ * Modifies the default behavior of the html a tag so that the default action is prevented when
* the href attribute is empty.
*
- * This change permits the easy creation of action links with the `ngClick` directive
- * without changing the location or causing page reloads, e.g.:
- * `Add Item`
+ * For dynamically creating `href` attributes for a tags, see the {@link ng.ngHref `ngHref`} directive.
*/
var htmlAnchorDirective = valueFn({
restrict: 'E',
@@ -23115,11 +23194,11 @@ var ISO_DATE_REGEXP = /^\d{4,}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+(?:[+-
// 7. Path
// 8. Query
// 9. Fragment
-// 1111111111111111 222 333333 44444 555555555555555555555555 666 77777777 8888888 999
-var URL_REGEXP = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+\])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i;
+// 1111111111111111 222 333333 44444 55555555555555555555555 666 77777777 8888888 999
+var URL_REGEXP = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i;
// eslint-disable-next-line max-len
-var EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+\/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+\/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
-var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/;
+var EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
+var NUMBER_REGEXP = /^\s*(-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/;
var DATE_REGEXP = /^(\d{4,})-(\d{2})-(\d{2})$/;
var DATETIMELOCAL_REGEXP = /^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/;
var WEEK_REGEXP = /^(\d{4,})-W(\d\d)$/;
@@ -24206,6 +24285,9 @@ var inputType = {
* Can be interpolated.
* @param {string=} ngChange Angular expression to be executed when the ngModel value changes due
* to user interaction with the input element.
+ * @param {expression=} ngChecked If the expression is truthy, then the `checked` attribute will be set on the
+ * element. **Note** : `ngChecked` should not be used alongside `ngModel`.
+ * Checkout {@link ng.directive:ngChecked ngChecked} for usage.
*
* @example
@@ -24339,7 +24421,7 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
var type = lowercase(element[0].type);
- // In composition mode, users are still inputing intermediate text buffer,
+ // In composition mode, users are still inputting intermediate text buffer,
// hold the listener until composition is done.
// More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
if (!$sniffer.android) {
@@ -24893,7 +24975,9 @@ function radioInputType(scope, element, attr, ctrl) {
ctrl.$render = function() {
var value = attr.value;
- element[0].checked = (value === ctrl.$viewValue);
+ // We generally use strict comparison. This is behavior we cannot change without a BC.
+ // eslint-disable-next-line eqeqeq
+ element[0].checked = (value == ctrl.$viewValue);
};
attr.$observe('value', ctrl.$render);
@@ -25528,8 +25612,6 @@ function classDirective(name, selector) {
link: function(scope, element, attr) {
var oldVal;
- scope.$watch(attr[name], ngClassWatchAction, true);
-
attr.$observe('class', function(value) {
ngClassWatchAction(scope.$eval(attr[name]));
});
@@ -25540,7 +25622,7 @@ function classDirective(name, selector) {
/* eslint-disable no-bitwise */
var mod = $index & 1;
if (mod !== (old$index & 1)) {
- var classes = arrayClasses(scope.$eval(attr[name]));
+ var classes = arrayClasses(oldVal);
if (mod === selector) {
addClasses(classes);
} else {
@@ -25551,6 +25633,8 @@ function classDirective(name, selector) {
});
}
+ scope.$watch(attr[name], ngClassWatchAction, true);
+
function addClasses(classes) {
var newClasses = digestClassCounts(classes, 1);
attr.$addClass(newClasses);
@@ -26228,31 +26312,38 @@ var ngControllerDirective = [function() {
* @ngdoc directive
* @name ngCsp
*
- * @element html
+ * @restrict A
+ * @element ANY
* @description
*
- * Angular has some features that can break certain
+ * Angular has some features that can conflict with certain restrictions that are applied when using
* [CSP (Content Security Policy)](https://developer.mozilla.org/en/Security/CSP) rules.
*
- * If you intend to implement these rules then you must tell Angular not to use these features.
+ * If you intend to implement CSP with these rules then you must tell Angular not to use these
+ * features.
*
* This is necessary when developing things like Google Chrome Extensions or Universal Windows Apps.
*
*
- * The following rules affect Angular:
+ * The following default rules in CSP affect Angular:
*
- * * `unsafe-eval`: this rule forbids apps to use `eval` or `Function(string)` generated functions
- * (among other things). Angular makes use of this in the {@link $parse} service to provide a 30%
- * increase in the speed of evaluating Angular expressions.
+ * * The use of `eval()`, `Function(string)` and similar functions to dynamically create and execute
+ * code from strings is forbidden. Angular makes use of this in the {@link $parse} service to
+ * provide a 30% increase in the speed of evaluating Angular expressions. (This CSP rule can be
+ * disabled with the CSP keyword `unsafe-eval`, but it is generally not recommended as it would
+ * weaken the protections offered by CSP.)
*
- * * `unsafe-inline`: this rule forbids apps from inject custom styles into the document. Angular
- * makes use of this to include some CSS rules (e.g. {@link ngCloak} and {@link ngHide}).
- * To make these directives work when a CSP rule is blocking inline styles, you must link to the
- * `angular-csp.css` in your HTML manually.
+ * * The use of inline resources, such as inline `