1
1
/**
2
- * @license AngularJS v1.7.2-build.5557 +sha.ad0ba99
2
+ * @license AngularJS v1.7.2-build.5558 +sha.c9a92fc
3
3
* (c) 2010-2018 Google, Inc. http://angularjs.org
4
4
* License: MIT
5
5
*/
@@ -99,7 +99,7 @@ function isValidObjectMaxDepth(maxDepth) {
99
99
function minErr(module, ErrorConstructor) {
100
100
ErrorConstructor = ErrorConstructor || Error;
101
101
102
- var url = 'https://errors.angularjs.org/1.7.2-build.5557 +sha.ad0ba99 /';
102
+ var url = 'https://errors.angularjs.org/1.7.2-build.5558 +sha.c9a92fc /';
103
103
var regex = url.replace('.', '\\.') + '[\\s\\S]*';
104
104
var errRegExp = new RegExp(regex, 'g');
105
105
@@ -2779,7 +2779,7 @@ function toDebugString(obj, maxDepth) {
2779
2779
var version = {
2780
2780
// These placeholder strings will be replaced by grunt's `build` task.
2781
2781
// They need to be double- or single-quoted.
2782
- full: '1.7.2-build.5557 +sha.ad0ba99 ',
2782
+ full: '1.7.2-build.5558 +sha.c9a92fc ',
2783
2783
major: 1,
2784
2784
minor: 7,
2785
2785
dot: 2,
@@ -2930,7 +2930,7 @@ function publishExternalAPI(angular) {
2930
2930
});
2931
2931
}
2932
2932
])
2933
- .info({ angularVersion: '1.7.2-build.5557 +sha.ad0ba99 ' });
2933
+ .info({ angularVersion: '1.7.2-build.5558 +sha.c9a92fc ' });
2934
2934
}
2935
2935
2936
2936
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -4234,8 +4234,12 @@ var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
4234
4234
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
4235
4235
var $injectorMinErr = minErr('$injector');
4236
4236
4237
+ function stringifyFn(fn) {
4238
+ return Function.prototype.toString.call(fn);
4239
+ }
4240
+
4237
4241
function extractArgs(fn) {
4238
- var fnText = Function.prototype.toString.call (fn).replace(STRIP_COMMENTS, ''),
4242
+ var fnText = stringifyFn (fn).replace(STRIP_COMMENTS, ''),
4239
4243
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
4240
4244
return args;
4241
4245
}
@@ -5074,6 +5078,19 @@ function createInjector(modulesToLoad, strictDi) {
5074
5078
return args;
5075
5079
}
5076
5080
5081
+ function isClass(func) {
5082
+ // Support: IE 9-11 only
5083
+ // IE 9-11 do not support classes and IE9 leaks with the code below.
5084
+ if (msie || typeof func !== 'function') {
5085
+ return false;
5086
+ }
5087
+ var result = func.$$ngIsClass;
5088
+ if (!isBoolean(result)) {
5089
+ result = func.$$ngIsClass = /^class\b/.test(stringifyFn(func));
5090
+ }
5091
+ return result;
5092
+ }
5093
+
5077
5094
function invoke(fn, self, locals, serviceName) {
5078
5095
if (typeof locals === 'string') {
5079
5096
serviceName = locals;
@@ -5085,9 +5102,14 @@ function createInjector(modulesToLoad, strictDi) {
5085
5102
fn = fn[fn.length - 1];
5086
5103
}
5087
5104
5088
- // http://jsperf.com/angularjs-invoke-apply-vs-switch
5089
- // #5388
5090
- return fn.apply(self, args);
5105
+ if (!isClass(fn)) {
5106
+ // http://jsperf.com/angularjs-invoke-apply-vs-switch
5107
+ // #5388
5108
+ return fn.apply(self, args);
5109
+ } else {
5110
+ args.unshift(null);
5111
+ return new (Function.prototype.bind.apply(fn, args))();
5112
+ }
5091
5113
}
5092
5114
5093
5115
@@ -9981,6 +10003,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
9981
10003
};
9982
10004
}
9983
10005
10006
+ if (controllerDirectives) {
10007
+ elementControllers = setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective);
10008
+ }
10009
+
9984
10010
if (newIsolateScopeDirective) {
9985
10011
// Initialize isolate scope bindings for new isolate scope directive.
9986
10012
compile.$$addScopeInfo($element, isolateScope, true, !(templateDirective && (templateDirective === newIsolateScopeDirective ||
@@ -9996,69 +10022,53 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
9996
10022
}
9997
10023
}
9998
10024
9999
- if (controllerDirectives) {
10000
- elementControllers = createMap();
10001
- for (var name in controllerDirectives) {
10002
- var directive = controllerDirectives[name];
10003
- var locals = {
10004
- $scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
10005
- $element: $element,
10006
- $attrs: attrs,
10007
- $transclude: transcludeFn
10008
- };
10009
-
10010
- var controllerConstructor = directive.controller;
10011
- if (controllerConstructor === '@') {
10012
- controllerConstructor = attrs[name];
10013
- }
10025
+ // Initialize bindToController bindings
10026
+ for (var name in elementControllers) {
10027
+ var controllerDirective = controllerDirectives[name];
10028
+ var controller = elementControllers[name];
10029
+ var bindings = controllerDirective.$$bindings.bindToController;
10014
10030
10015
- var instance = $controller(controllerConstructor, locals, directive.controllerAs);
10016
-
10017
- $element.data('$' + name + 'Controller', instance);
10018
-
10019
- // Initialize bindToController bindings
10020
- var bindings = directive.$$bindings.bindToController;
10021
- var bindingInfo = initializeDirectiveBindings(controllerScope, attrs, instance, bindings, directive);
10022
-
10023
- elementControllers[name] = { instance: instance, bindingInfo: bindingInfo };
10031
+ controller.instance = controller();
10032
+ $element.data('$' + controllerDirective.name + 'Controller', controller.instance);
10033
+ controller.bindingInfo =
10034
+ initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
10024
10035
}
10025
10036
10026
- // Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
10027
- forEach(controllerDirectives, function(controllerDirective, name) {
10028
- var require = controllerDirective.require;
10029
- if (controllerDirective.bindToController && !isArray(require) && isObject(require)) {
10030
- extend(elementControllers[name].instance, getControllers(name, require, $element, elementControllers));
10031
- }
10032
- });
10037
+ // Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
10038
+ forEach(controllerDirectives, function(controllerDirective, name) {
10039
+ var require = controllerDirective.require;
10040
+ if (controllerDirective.bindToController && !isArray(require) && isObject(require)) {
10041
+ extend(elementControllers[name].instance, getControllers(name, require, $element, elementControllers));
10042
+ }
10043
+ });
10033
10044
10034
- // Handle the init and destroy lifecycle hooks on all controllers that have them
10035
- forEach(elementControllers, function(controller) {
10036
- var controllerInstance = controller.instance;
10037
- if (isFunction(controllerInstance.$onChanges)) {
10038
- try {
10039
- controllerInstance.$onChanges(controller.bindingInfo.initialChanges);
10040
- } catch (e) {
10041
- $exceptionHandler(e);
10042
- }
10043
- }
10044
- if (isFunction(controllerInstance.$onInit)) {
10045
- try {
10046
- controllerInstance.$onInit();
10047
- } catch (e) {
10048
- $exceptionHandler(e);
10049
- }
10050
- }
10051
- if (isFunction(controllerInstance.$doCheck)) {
10052
- controllerScope.$watch(function() { controllerInstance.$doCheck(); });
10053
- controllerInstance.$doCheck();
10045
+ // Handle the init and destroy lifecycle hooks on all controllers that have them
10046
+ forEach(elementControllers, function(controller) {
10047
+ var controllerInstance = controller.instance;
10048
+ if (isFunction(controllerInstance.$onChanges)) {
10049
+ try {
10050
+ controllerInstance.$onChanges(controller.bindingInfo.initialChanges);
10051
+ } catch (e) {
10052
+ $exceptionHandler(e);
10054
10053
}
10055
- if (isFunction(controllerInstance.$onDestroy)) {
10056
- controllerScope.$on('$destroy', function callOnDestroyHook() {
10057
- controllerInstance.$onDestroy();
10058
- });
10054
+ }
10055
+ if (isFunction(controllerInstance.$onInit)) {
10056
+ try {
10057
+ controllerInstance.$onInit();
10058
+ } catch (e) {
10059
+ $exceptionHandler(e);
10059
10060
}
10060
- });
10061
- }
10061
+ }
10062
+ if (isFunction(controllerInstance.$doCheck)) {
10063
+ controllerScope.$watch(function() { controllerInstance.$doCheck(); });
10064
+ controllerInstance.$doCheck();
10065
+ }
10066
+ if (isFunction(controllerInstance.$onDestroy)) {
10067
+ controllerScope.$on('$destroy', function callOnDestroyHook() {
10068
+ controllerInstance.$onDestroy();
10069
+ });
10070
+ }
10071
+ });
10062
10072
10063
10073
// PRELINKING
10064
10074
for (i = 0, ii = preLinkFns.length; i < ii; i++) {
@@ -10186,6 +10196,34 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10186
10196
return value || null;
10187
10197
}
10188
10198
10199
+ function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective) {
10200
+ var elementControllers = createMap();
10201
+ for (var controllerKey in controllerDirectives) {
10202
+ var directive = controllerDirectives[controllerKey];
10203
+ var locals = {
10204
+ $scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
10205
+ $element: $element,
10206
+ $attrs: attrs,
10207
+ $transclude: transcludeFn
10208
+ };
10209
+
10210
+ var controller = directive.controller;
10211
+ if (controller === '@') {
10212
+ controller = attrs[directive.name];
10213
+ }
10214
+
10215
+ var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
10216
+
10217
+ // For directives with element transclusion the element is a comment.
10218
+ // In this case .data will not attach any data.
10219
+ // Instead, we save the controllers for the element in a local hash and attach to .data
10220
+ // later, once we have the actual element.
10221
+ elementControllers[directive.name] = controllerInstance;
10222
+ $element.data('$' + directive.name + 'Controller', controllerInstance.instance);
10223
+ }
10224
+ return elementControllers;
10225
+ }
10226
+
10189
10227
// Depending upon the context in which a directive finds itself it might need to have a new isolated
10190
10228
// or child scope created. For instance:
10191
10229
// * if the directive has been pulled into a template because another directive with a higher priority
@@ -11064,11 +11102,16 @@ function $ControllerProvider() {
11064
11102
* It's just a simple call to {@link auto.$injector $injector}, but extracted into
11065
11103
* a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
11066
11104
*/
11067
- return function $controller(expression, locals, ident) {
11105
+ return function $controller(expression, locals, later, ident) {
11068
11106
// PRIVATE API:
11107
+ // param `later` --- indicates that the controller's constructor is invoked at a later time.
11108
+ // If true, $controller will allocate the object with the correct
11109
+ // prototype chain, but will not invoke the controller until a returned
11110
+ // callback is invoked.
11069
11111
// param `ident` --- An optional label which overrides the label parsed from the controller
11070
11112
// expression, if any.
11071
11113
var instance, match, constructor, identifier;
11114
+ later = later === true;
11072
11115
if (ident && isString(ident)) {
11073
11116
identifier = ident;
11074
11117
}
@@ -11094,6 +11137,41 @@ function $ControllerProvider() {
11094
11137
assertArgFn(expression, constructor, true);
11095
11138
}
11096
11139
11140
+ if (later) {
11141
+ // Instantiate controller later:
11142
+ // This machinery is used to create an instance of the object before calling the
11143
+ // controller's constructor itself.
11144
+ //
11145
+ // This allows properties to be added to the controller before the constructor is
11146
+ // invoked. Primarily, this is used for isolate scope bindings in $compile.
11147
+ //
11148
+ // This feature is not intended for use by applications, and is thus not documented
11149
+ // publicly.
11150
+ // Object creation: http://jsperf.com/create-constructor/2
11151
+ var controllerPrototype = (isArray(expression) ?
11152
+ expression[expression.length - 1] : expression).prototype;
11153
+ instance = Object.create(controllerPrototype || null);
11154
+
11155
+ if (identifier) {
11156
+ addIdentifier(locals, identifier, instance, constructor || expression.name);
11157
+ }
11158
+
11159
+ return extend(function $controllerInit() {
11160
+ var result = $injector.invoke(expression, instance, locals, constructor);
11161
+ if (result !== instance && (isObject(result) || isFunction(result))) {
11162
+ instance = result;
11163
+ if (identifier) {
11164
+ // If result changed, re-assign controllerAs value to scope.
11165
+ addIdentifier(locals, identifier, instance, constructor || expression.name);
11166
+ }
11167
+ }
11168
+ return instance;
11169
+ }, {
11170
+ instance: instance,
11171
+ identifier: identifier
11172
+ });
11173
+ }
11174
+
11097
11175
instance = $injector.instantiate(expression, locals, constructor);
11098
11176
11099
11177
if (identifier) {
0 commit comments