MCPcopy
hub / github.com/angular-ui/ui-router / TemplateFactory

Class TemplateFactory

src/templateFactory.ts:24–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 * Service which manages loading of templates from a ViewConfig.
23 */
24export class TemplateFactory implements TemplateFactoryProvider {
25 /** @hidden */ private _useHttp = angular.version.minor < 3;
26 /** @hidden */ private $templateRequest;
27 /** @hidden */ private $templateCache;
28 /** @hidden */ private $http;
29
30 /** @hidden */ $get = [
31 '$http',
32 '$templateCache',
33 '$injector',
34 ($http, $templateCache, $injector) => {
35 this.$templateRequest = $injector.has && $injector.has('$templateRequest') && $injector.get('$templateRequest');
36 this.$http = $http;
37 this.$templateCache = $templateCache;
38 return this;
39 },
40 ];
41
42 /** @hidden */
43 useHttpService(value: boolean) {
44 this._useHttp = value;
45 }
46
47 /**
48 * Creates a template from a configuration object.
49 *
50 * @param config Configuration object for which to load a template.
51 * The following properties are search in the specified order, and the first one
52 * that is defined is used to create the template:
53 *
54 * @param params Parameters to pass to the template function.
55 * @param context The resolve context associated with the template's view
56 *
57 * @return {string|object} The template html as a string, or a promise for
58 * that string,or `null` if no template is configured.
59 */
60 fromConfig(
61 config: Ng1ViewDeclaration,
62 params: any,
63 context: ResolveContext
64 ): Promise<{ template?: string; component?: string }> {
65 const defaultTemplate = '<ui-view></ui-view>';
66
67 const asTemplate = (result) => services.$q.when(result).then((str) => ({ template: str }));
68 const asComponent = (result) => services.$q.when(result).then((str) => ({ component: str }));
69
70 return isDefined(config.template)
71 ? asTemplate(this.fromString(config.template, params))
72 : isDefined(config.templateUrl)
73 ? asTemplate(this.fromUrl(config.templateUrl, params))
74 : isDefined(config.templateProvider)
75 ? asTemplate(this.fromProvider(config.templateProvider, params, context))
76 : isDefined(config.component)
77 ? asComponent(config.component)
78 : isDefined(config.componentProvider)
79 ? asComponent(this.fromComponentProvider(config.componentProvider, params, context))
80 : asTemplate(defaultTemplate);
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected