/** @hidden TODO: move these callbacks to $view and/or `/hooks/components.ts` or something */ function registerControllerCallbacks($q, $transitions, controllerInstance, $scope, cfg) { // Call $onInit() ASAP if (isFunction(controllerInstance.$onInit) && !(cfg.viewDecl.component && hasComponentImpl)) { controllerInstance.$onInit(); } var viewState = tail(cfg.path).state.self; var hookOptions = { bind: controllerInstance }; // Add component-level hook for onParamsChange if (isFunction(controllerInstance.uiOnParamsChanged)) { var resolveContext = new ResolveContext(cfg.path); var viewCreationTrans_1 = resolveContext.getResolvable('$transition$').data; // Fire callback on any successful transition var paramsUpdated = function ($transition$) { // Exit early if the $transition$ is the same as the view was created within. // Exit early if the $transition$ will exit the state the view is for. if ($transition$ === viewCreationTrans_1 || $transition$.exiting().indexOf(viewState) !== -1) return; var toParams = $transition$.params('to'); var fromParams = $transition$.params('from'); var toSchema = $transition$.treeChanges().to.map(function (node) { return node.paramSchema; }).reduce(unnestR, []); var fromSchema = $transition$.treeChanges().from.map(function (node) { return node.paramSchema; }).reduce(unnestR, []); // Find the to params that have different values than the from params var changedToParams = toSchema.filter(function (param) { var idx = fromSchema.indexOf(param); return idx === -1 || !fromSchema[idx].type.equals(toParams[param.id], fromParams[param.id]); }); // Only trigger callback if a to param has changed or is new if (changedToParams.length) { var changedKeys_1 = changedToParams.map(function (x) { return x.id; }); // Filter the params to only changed/new to params. `$transition$.params()` may be used to get all params. var newValues = filter(toParams, function (val, key) { return changedKeys_1.indexOf(key) !== -1; }); controllerInstance.uiOnParamsChanged(newValues, $transition$); } }; $scope.$on('$destroy', $transitions.onSuccess({}, paramsUpdated, hookOptions)); } // Add component-level hook for uiCanExit if (isFunction(controllerInstance.uiCanExit)) { var id_1 = _uiCanExitId++; var cacheProp_1 = '_uiCanExitIds'; // Returns true if a redirect transition already answered truthy var prevTruthyAnswer_1 = function (trans) { return !!trans && (trans[cacheProp_1] && trans[cacheProp_1][id_1] === true || prevTruthyAnswer_1(trans.redirectedFrom())); }; // If a user answered yes, but the transition was later redirected, don't also ask for the new redirect transition var wrappedHook = function (trans) { var promise; var ids = trans[cacheProp_1] = trans[cacheProp_1] || {}; if (!prevTruthyAnswer_1(trans)) { promise = $q.when(controllerInstance.uiCanExit(trans)); promise.then(function (val) { return ids[id_1] = (val !== false); }); } return promise; }; var criteria = { exiting: viewState.name }; $scope.$on('$destroy', $transitions.onBefore(criteria, wrappedHook, hookOptions)); } }
Ng1ViewConfig.prototype.getController = function (context) { var provider = this.viewDecl.controllerProvider; if (!isInjectable(provider)) return this.viewDecl.controller; var deps = services.$injector.annotate(provider); var providerFn = isArray(provider) ? tail(provider) : provider; var resolvable = new Resolvable('', providerFn, deps); return resolvable.get(context); };
/** @hidden */ function stateContext(el) { var $uiView = el.parent().inheritedData('$uiView'); var path = core_1.parse('$cfg.path')($uiView); return path ? core_1.tail(path).state.name : undefined; }
TemplateFactory.prototype.fromComponentProvider = function (provider, params, context) { var deps = core_1.services.$injector.annotate(provider); var providerFn = core_1.isArray(provider) ? core_1.tail(provider) : provider; var resolvable = new core_1.Resolvable('', providerFn, deps); return resolvable.get(context); };