Remove component resolver (#10858)
* refactor(core): remove deprecated ComponentResolver BREAKING CHANGE: deprecated ComponentResolver was removed Please follow deprecation instruction and migrate your code to use ComponentFactoryResolver. * refactor(common): remove deprecated NgSwitchWhen directive BREAKING CHANGE: previously deprecated NgSwitchWhen directive was removed, use NgSwitchCase instead
This commit is contained in:
parent
9adf80385b
commit
73a9ee4a05
|
@ -24,14 +24,14 @@ import {CORE_DIRECTIVES} from './directives';
|
||||||
* Instead of writing:
|
* Instead of writing:
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, NgModel, NgForm} from
|
* import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault, NgModel, NgForm} from
|
||||||
* '@angular/common';
|
* '@angular/common';
|
||||||
* import {OtherDirective} from './myDirectives';
|
* import {OtherDirective} from './myDirectives';
|
||||||
*
|
*
|
||||||
* @Component({
|
* @Component({
|
||||||
* selector: 'my-component',
|
* selector: 'my-component',
|
||||||
* templateUrl: 'myComponent.html',
|
* templateUrl: 'myComponent.html',
|
||||||
* directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, NgModel, NgForm,
|
* directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault, NgModel, NgForm,
|
||||||
* OtherDirective]
|
* OtherDirective]
|
||||||
* })
|
* })
|
||||||
* export class MyComponent {
|
* export class MyComponent {
|
||||||
|
|
|
@ -28,13 +28,13 @@ import {NgTemplateOutlet} from './ng_template_outlet';
|
||||||
* Instead of writing:
|
* Instead of writing:
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from '@angular/common';
|
* import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common';
|
||||||
* import {OtherDirective} from './myDirectives';
|
* import {OtherDirective} from './myDirectives';
|
||||||
*
|
*
|
||||||
* @Component({
|
* @Component({
|
||||||
* selector: 'my-component',
|
* selector: 'my-component',
|
||||||
* templateUrl: 'myComponent.html',
|
* templateUrl: 'myComponent.html',
|
||||||
* directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, OtherDirective]
|
* directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault, OtherDirective]
|
||||||
* })
|
* })
|
||||||
* export class MyComponent {
|
* export class MyComponent {
|
||||||
* ...
|
* ...
|
||||||
|
|
|
@ -13,9 +13,6 @@ import {isBlank, isPresent, normalizeBlank} from '../facade/lang';
|
||||||
|
|
||||||
const _CASE_DEFAULT = new Object();
|
const _CASE_DEFAULT = new Object();
|
||||||
|
|
||||||
// TODO: remove when fully deprecated
|
|
||||||
let _warned: boolean = false;
|
|
||||||
|
|
||||||
export class SwitchView {
|
export class SwitchView {
|
||||||
constructor(
|
constructor(
|
||||||
private _viewContainerRef: ViewContainerRef, private _templateRef: TemplateRef<Object>) {}
|
private _viewContainerRef: ViewContainerRef, private _templateRef: TemplateRef<Object>) {}
|
||||||
|
@ -182,7 +179,7 @@ export class NgSwitch {
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
@Directive({selector: '[ngSwitchCase],[ngSwitchWhen]'})
|
@Directive({selector: '[ngSwitchCase]'})
|
||||||
export class NgSwitchCase {
|
export class NgSwitchCase {
|
||||||
// `_CASE_DEFAULT` is used as a marker for a not yet initialized value
|
// `_CASE_DEFAULT` is used as a marker for a not yet initialized value
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -203,16 +200,6 @@ export class NgSwitchCase {
|
||||||
this._switch._onCaseValueChanged(this._value, value, this._view);
|
this._switch._onCaseValueChanged(this._value, value, this._view);
|
||||||
this._value = value;
|
this._value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
|
||||||
set ngSwitchWhen(value: any) {
|
|
||||||
if (!_warned) {
|
|
||||||
_warned = true;
|
|
||||||
console.warn('*ngSwitchWhen is deprecated and will be removed. Use *ngSwitchCase instead');
|
|
||||||
}
|
|
||||||
this._switch._onCaseValueChanged(this._value, value, this._view);
|
|
||||||
this._value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,11 +44,11 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// TODO(robwormald): deprecate and remove
|
// TODO(robwormald): deprecate and remove
|
||||||
it('should switch amongst when values using switchWhen', async(() => {
|
it('should switch amongst when values using switchCase', async(() => {
|
||||||
var template = '<div>' +
|
var template = '<div>' +
|
||||||
'<ul [ngSwitch]="switchValue">' +
|
'<ul [ngSwitch]="switchValue">' +
|
||||||
'<template ngSwitchWhen="a"><li>when a</li></template>' +
|
'<template ngSwitchCase="a"><li>when a</li></template>' +
|
||||||
'<template ngSwitchWhen="b"><li>when b</li></template>' +
|
'<template ngSwitchCase="b"><li>when b</li></template>' +
|
||||||
'</ul></div>';
|
'</ul></div>';
|
||||||
|
|
||||||
TestBed.overrideComponent(TestComponent, {set: {template: template}});
|
TestBed.overrideComponent(TestComponent, {set: {template: template}});
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
|
import {Compiler, ComponentFactory, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, Provider, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
|
||||||
|
|
||||||
import {Console} from '../core_private';
|
import {Console} from '../core_private';
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMeta
|
||||||
import {CompilerConfig} from './config';
|
import {CompilerConfig} from './config';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from './directive_normalizer';
|
||||||
import {BaseException} from './facade/exceptions';
|
import {BaseException} from './facade/exceptions';
|
||||||
import {isBlank, isString, stringify} from './facade/lang';
|
import {isBlank, stringify} from './facade/lang';
|
||||||
import {CompileMetadataResolver} from './metadata_resolver';
|
import {CompileMetadataResolver} from './metadata_resolver';
|
||||||
import {NgModuleCompiler} from './ng_module_compiler';
|
import {NgModuleCompiler} from './ng_module_compiler';
|
||||||
import * as ir from './output/output_ast';
|
import * as ir from './output/output_ast';
|
||||||
|
@ -124,18 +124,9 @@ export class RuntimeCompiler implements Compiler {
|
||||||
let ngModuleFactory = this._compiledNgModuleCache.get(moduleType);
|
let ngModuleFactory = this._compiledNgModuleCache.get(moduleType);
|
||||||
if (!ngModuleFactory) {
|
if (!ngModuleFactory) {
|
||||||
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType);
|
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType);
|
||||||
const transitiveModuleMeta = moduleMeta.transitiveModule;
|
// Always provide a bound Compiler
|
||||||
let boundCompilerFactory = (parentResolver: ComponentResolver) =>
|
const extraProviders = [this._metadataResolver.getProviderMetadata(new ProviderMeta(
|
||||||
new ModuleBoundCompiler(this, moduleMeta.type.runtime, parentResolver, this._console);
|
Compiler, {useFactory: () => new ModuleBoundCompiler(this, moduleMeta.type.runtime)}))];
|
||||||
// Always provide a bound Compiler and ComponentResolver
|
|
||||||
const extraProviders = [
|
|
||||||
this._metadataResolver.getProviderMetadata(new ProviderMeta(Compiler, {
|
|
||||||
useFactory: boundCompilerFactory,
|
|
||||||
deps: [[new OptionalMetadata(), new SkipSelfMetadata(), ComponentResolver]]
|
|
||||||
})),
|
|
||||||
this._metadataResolver.getProviderMetadata(
|
|
||||||
new ProviderMeta(ComponentResolver, {useExisting: Compiler}))
|
|
||||||
];
|
|
||||||
var compileResult = this._ngModuleCompiler.compile(moduleMeta, extraProviders);
|
var compileResult = this._ngModuleCompiler.compile(moduleMeta, extraProviders);
|
||||||
compileResult.dependencies.forEach((dep) => {
|
compileResult.dependencies.forEach((dep) => {
|
||||||
dep.placeholder.runtime =
|
dep.placeholder.runtime =
|
||||||
|
@ -405,34 +396,13 @@ function assertComponent(meta: CompileDirectiveMetadata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements `Compiler` and `ComponentResolver` by delegating
|
* Implements `Compiler` by delegating to the RuntimeCompiler using a known module.
|
||||||
* to the RuntimeCompiler using a known module.
|
|
||||||
*/
|
*/
|
||||||
class ModuleBoundCompiler implements Compiler, ComponentResolver {
|
class ModuleBoundCompiler implements Compiler {
|
||||||
private _warnOnComponentResolver = true;
|
constructor(private _delegate: RuntimeCompiler, private _ngModule: Type<any>) {}
|
||||||
|
|
||||||
constructor(
|
|
||||||
private _delegate: RuntimeCompiler, private _ngModule: Type<any>,
|
|
||||||
private _parentComponentResolver: ComponentResolver, private _console: Console) {}
|
|
||||||
|
|
||||||
get _injector(): Injector { return this._delegate.injector; }
|
get _injector(): Injector { return this._delegate.injector; }
|
||||||
|
|
||||||
resolveComponent(component: Type<any>|string): Promise<ComponentFactory<any>> {
|
|
||||||
if (isString(component)) {
|
|
||||||
if (this._parentComponentResolver) {
|
|
||||||
return this._parentComponentResolver.resolveComponent(component);
|
|
||||||
} else {
|
|
||||||
return <Promise<any>>Promise.reject(
|
|
||||||
new BaseException(`Cannot resolve component using '${component}'.`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this._warnOnComponentResolver) {
|
|
||||||
this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg);
|
|
||||||
this._warnOnComponentResolver = false;
|
|
||||||
}
|
|
||||||
return this.compileComponentAsync(<Type<any>>component);
|
|
||||||
}
|
|
||||||
|
|
||||||
compileComponentAsync<T>(compType: Type<T>, ngModule: Type<any> = null):
|
compileComponentAsync<T>(compType: Type<T>, ngModule: Type<any> = null):
|
||||||
Promise<ComponentFactory<T>> {
|
Promise<ComponentFactory<T>> {
|
||||||
return this._delegate.compileComponentAsync(compType, ngModule ? ngModule : this._ngModule);
|
return this._delegate.compileComponentAsync(compType, ngModule ? ngModule : this._ngModule);
|
||||||
|
@ -461,12 +431,7 @@ class ModuleBoundCompiler implements Compiler, ComponentResolver {
|
||||||
/**
|
/**
|
||||||
* Clears all caches
|
* Clears all caches
|
||||||
*/
|
*/
|
||||||
clearCache(): void {
|
clearCache(): void { this._delegate.clearCache(); }
|
||||||
this._delegate.clearCache();
|
|
||||||
if (this._parentComponentResolver) {
|
|
||||||
this._parentComponentResolver.clearCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the cache for the given component/ngModule.
|
* Clears the cache for the given component/ngModule.
|
||||||
|
|
|
@ -20,7 +20,6 @@ import * as debug from './src/debug/debug_renderer';
|
||||||
import * as provider from './src/di/provider';
|
import * as provider from './src/di/provider';
|
||||||
import * as reflective_provider from './src/di/reflective_provider';
|
import * as reflective_provider from './src/di/reflective_provider';
|
||||||
import * as component_factory_resolver from './src/linker/component_factory_resolver';
|
import * as component_factory_resolver from './src/linker/component_factory_resolver';
|
||||||
import * as component_resolver from './src/linker/component_resolver';
|
|
||||||
import * as debug_context from './src/linker/debug_context';
|
import * as debug_context from './src/linker/debug_context';
|
||||||
import * as element from './src/linker/element';
|
import * as element from './src/linker/element';
|
||||||
import * as ng_module_factory from './src/linker/ng_module_factory';
|
import * as ng_module_factory from './src/linker/ng_module_factory';
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
|
||||||
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
|
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
|
||||||
import {LOCALE_ID} from './i18n/tokens';
|
import {LOCALE_ID} from './i18n/tokens';
|
||||||
import {Compiler} from './linker/compiler';
|
import {Compiler} from './linker/compiler';
|
||||||
import {ComponentResolver} from './linker/component_resolver';
|
|
||||||
import {ViewUtils} from './linker/view_utils';
|
import {ViewUtils} from './linker/view_utils';
|
||||||
import {NgModule} from './metadata';
|
import {NgModule} from './metadata';
|
||||||
import {Type} from './type';
|
import {Type} from './type';
|
||||||
|
@ -45,7 +44,6 @@ export const APPLICATION_COMMON_PROVIDERS: Array<Type<any>|{[k: string]: any}|an
|
||||||
{provide: ApplicationRef, useExisting: ApplicationRef_},
|
{provide: ApplicationRef, useExisting: ApplicationRef_},
|
||||||
ApplicationInitStatus,
|
ApplicationInitStatus,
|
||||||
Compiler,
|
Compiler,
|
||||||
{provide: ComponentResolver, useExisting: Compiler},
|
|
||||||
APP_ID_RANDOM_PROVIDER,
|
APP_ID_RANDOM_PROVIDER,
|
||||||
ViewUtils,
|
ViewUtils,
|
||||||
{provide: IterableDiffers, useFactory: _iterableDiffersFactory},
|
{provide: IterableDiffers, useFactory: _iterableDiffersFactory},
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
export {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, ComponentStillLoadingError, ModuleWithComponentFactories} from './linker/compiler';
|
export {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, ComponentStillLoadingError, ModuleWithComponentFactories} from './linker/compiler';
|
||||||
export {ComponentFactory, ComponentRef} from './linker/component_factory';
|
export {ComponentFactory, ComponentRef} from './linker/component_factory';
|
||||||
export {ComponentFactoryResolver, NoComponentFactoryError} from './linker/component_factory_resolver';
|
export {ComponentFactoryResolver, NoComponentFactoryError} from './linker/component_factory_resolver';
|
||||||
export {ComponentResolver} from './linker/component_resolver';
|
|
||||||
export {ElementRef} from './linker/element_ref';
|
export {ElementRef} from './linker/element_ref';
|
||||||
export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions';
|
export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions';
|
||||||
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
|
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Type} from '../type';
|
|
||||||
import {ComponentFactory} from './component_factory';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Low-level service for loading {@link ComponentFactory}s, which
|
|
||||||
* can later be used to create and render a Component instance.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link ComponentFactoryResolver} together with {@link
|
|
||||||
* NgModule}.entryComponents}/{@link Component}.entryComponents or
|
|
||||||
* {@link ANALYZE_FOR_ENTRY_COMPONENTS} provider for dynamic component creation.
|
|
||||||
* Use {@link NgModuleFactoryLoader} for lazy loading.
|
|
||||||
*/
|
|
||||||
export abstract class ComponentResolver {
|
|
||||||
static DynamicCompilationDeprecationMsg =
|
|
||||||
'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.entryComponents or ANALYZE_FOR_ENTRY_COMPONENTS provider instead. For runtime compile only, you can also use Compiler.compileComponentSync/Async.';
|
|
||||||
static LazyLoadingDeprecationMsg =
|
|
||||||
'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.';
|
|
||||||
|
|
||||||
|
|
||||||
abstract resolveComponent(component: Type<any>|string): Promise<ComponentFactory<any>>;
|
|
||||||
abstract clearCache(): void;
|
|
||||||
}
|
|
|
@ -78,7 +78,7 @@ export abstract class ViewContainerRef {
|
||||||
* specified `index`.
|
* specified `index`.
|
||||||
*
|
*
|
||||||
* The component is instantiated using its {@link ComponentFactory} which can be
|
* The component is instantiated using its {@link ComponentFactory} which can be
|
||||||
* obtained via {@link ComponentResolver#resolveComponent}.
|
* obtained via {@link ComponentFactoryResolver#resolveComponentFactory}.
|
||||||
*
|
*
|
||||||
* If `index` is not specified, the new View will be inserted as the last View in the container.
|
* If `index` is not specified, the new View will be inserted as the last View in the container.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncPipe, NgFor, NgIf} from '@angular/common';
|
import {AsyncPipe, NgFor, NgIf} from '@angular/common';
|
||||||
import {CompilerConfig} from '@angular/compiler';
|
import {Compiler, Host, Inject, Injectable, Injector, NgModule, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata, forwardRef} from '@angular/core';
|
||||||
import {Compiler, Host, Inject, Injectable, Injector, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata, forwardRef} from '@angular/core';
|
|
||||||
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
|
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
|
||||||
import {ComponentResolver} from '@angular/core/src/linker/component_resolver';
|
import {ComponentFactoryResolver} from '@angular/core/src/linker/component_factory_resolver';
|
||||||
import {ElementRef} from '@angular/core/src/linker/element_ref';
|
import {ElementRef} from '@angular/core/src/linker/element_ref';
|
||||||
import {QueryList} from '@angular/core/src/linker/query_list';
|
import {QueryList} from '@angular/core/src/linker/query_list';
|
||||||
import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref';
|
import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref';
|
||||||
|
@ -19,7 +18,7 @@ import {EmbeddedViewRef} from '@angular/core/src/linker/view_ref';
|
||||||
import {Attribute, Component, ContentChildren, Directive, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata';
|
import {Attribute, Component, ContentChildren, Directive, HostBinding, HostListener, Input, Output, Pipe} from '@angular/core/src/metadata';
|
||||||
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
||||||
import {Renderer} from '@angular/core/src/render';
|
import {Renderer} from '@angular/core/src/render';
|
||||||
import {ComponentFixture, TestBed, fakeAsync, tick} from '@angular/core/testing';
|
import {ComponentFixture, TestBed, async, fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util';
|
import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util';
|
||||||
|
@ -1263,25 +1262,33 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('dynamic ViewContainers', () => {
|
describe('dynamic ViewContainers', () => {
|
||||||
it('should allow to create a ViewContainerRef at any bound location',
|
beforeEach(() => {
|
||||||
inject(
|
|
||||||
[TestComponentBuilder, AsyncTestCompleter, ComponentResolver],
|
// we need a module to declarate ChildCompUsingService as an entryComponent otherwise the
|
||||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter,
|
// factory doesn't get created
|
||||||
compiler: ComponentResolver) => {
|
@NgModule({
|
||||||
tcb.overrideView(MyComp, new ViewMetadata({
|
declarations: [DynamicViewport, MyComp, ChildCompUsingService],
|
||||||
template: '<div><dynamic-vp #dynamic></dynamic-vp></div>',
|
entryComponents: [ChildCompUsingService, MyComp]
|
||||||
directives: [DynamicViewport]
|
})
|
||||||
}))
|
class MyModule {
|
||||||
.createAsync(MyComp)
|
}
|
||||||
.then((fixture) => {
|
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({imports: [MyModule]});
|
||||||
|
TestBed.overrideComponent(
|
||||||
|
MyComp, {add: {template: '<div><dynamic-vp #dynamic></dynamic-vp></div>'}});
|
||||||
|
return TestBed.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should allow to create a ViewContainerRef at any bound location', async(() => {
|
||||||
|
var fixture = TestBed.createComponent(MyComp);
|
||||||
var tc = fixture.debugElement.children[0].children[0];
|
var tc = fixture.debugElement.children[0].children[0];
|
||||||
var dynamicVp: DynamicViewport = tc.injector.get(DynamicViewport);
|
var dynamicVp: DynamicViewport = tc.injector.get(DynamicViewport);
|
||||||
dynamicVp.done.then((_) => {
|
dynamicVp.done.then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.children[0].children[1].nativeElement)
|
expect(fixture.debugElement.children[0].children[1].nativeElement)
|
||||||
.toHaveText('dynamic greet');
|
.toHaveText('dynamic greet');
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -2135,13 +2142,14 @@ class SimpleImperativeViewComponent {
|
||||||
@Directive({selector: 'dynamic-vp'})
|
@Directive({selector: 'dynamic-vp'})
|
||||||
class DynamicViewport {
|
class DynamicViewport {
|
||||||
done: Promise<any>;
|
done: Promise<any>;
|
||||||
constructor(vc: ViewContainerRef, compiler: ComponentResolver) {
|
constructor(vc: ViewContainerRef, componentFactoryResolver: ComponentFactoryResolver) {
|
||||||
var myService = new MyService();
|
var myService = new MyService();
|
||||||
myService.greeting = 'dynamic greet';
|
myService.greeting = 'dynamic greet';
|
||||||
|
|
||||||
var injector = ReflectiveInjector.resolveAndCreate(
|
var injector = ReflectiveInjector.resolveAndCreate(
|
||||||
[{provide: MyService, useValue: myService}], vc.injector);
|
[{provide: MyService, useValue: myService}], vc.injector);
|
||||||
this.done = compiler.resolveComponent(ChildCompUsingService)
|
this.done =
|
||||||
|
Promise.resolve(componentFactoryResolver.resolveComponentFactory(ChildCompUsingService))
|
||||||
.then((componentFactory) => vc.createComponent(componentFactory, 0, injector));
|
.then((componentFactory) => vc.createComponent(componentFactory, 0, injector));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, ComponentResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, ReflectiveInjector, SelfMetadata, Type, forwardRef} from '@angular/core';
|
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, SelfMetadata, Type, forwardRef} from '@angular/core';
|
||||||
import {Console} from '@angular/core/src/console';
|
import {Console} from '@angular/core/src/console';
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
|
@ -628,47 +628,6 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
// compile again should produce the same result
|
// compile again should produce the same result
|
||||||
expect(boundCompiler.compileComponentSync(CompUsingModuleDirectiveAndPipe)).toBe(cf);
|
expect(boundCompiler.compileComponentSync(CompUsingModuleDirectiveAndPipe)).toBe(cf);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide a ComponentResolver instance that uses the directives/pipes of the module',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
|
|
||||||
@NgModule({declarations: [SomeDirective, SomePipe]})
|
|
||||||
class SomeModule {
|
|
||||||
}
|
|
||||||
|
|
||||||
const ngModule = createModule(SomeModule);
|
|
||||||
|
|
||||||
const boundCompiler: ComponentResolver = ngModule.injector.get(ComponentResolver);
|
|
||||||
boundCompiler.resolveComponent(CompUsingModuleDirectiveAndPipe).then((cf) => {
|
|
||||||
const compFixture = new ComponentFixture(cf.create(injector), null, false);
|
|
||||||
compFixture.detectChanges();
|
|
||||||
expect(compFixture.debugElement.children[0].properties['title'])
|
|
||||||
.toBe('transformed someValue');
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should provide a ComponentResolver instance that delegates to the parent ComponentResolver for strings',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
@NgModule()
|
|
||||||
class SomeModule {
|
|
||||||
}
|
|
||||||
|
|
||||||
let parentResolver: any =
|
|
||||||
jasmine.createSpyObj('resolver', ['resolveComponent', 'clearCache']);
|
|
||||||
const ngModule = createModule(
|
|
||||||
SomeModule, ReflectiveInjector.resolveAndCreate(
|
|
||||||
[{provide: ComponentResolver, useValue: parentResolver}]));
|
|
||||||
parentResolver.resolveComponent.and.returnValue(
|
|
||||||
Promise.resolve('someFactoryFromParent'));
|
|
||||||
let boundCompiler: ComponentResolver = ngModule.injector.get(ComponentResolver);
|
|
||||||
boundCompiler.resolveComponent('someString').then((result) => {
|
|
||||||
expect(parentResolver.resolveComponent).toHaveBeenCalledWith('someString');
|
|
||||||
expect(result).toBe('someFactoryFromParent');
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('providers', function() {
|
describe('providers', function() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
} from '@angular/testing/src/benchmark_util';
|
} from '@angular/testing/src/benchmark_util';
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from '@angular/common';
|
import {NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common';
|
||||||
import {ApplicationRef} from '@angular/core/src/application_ref';
|
import {ApplicationRef} from '@angular/core/src/application_ref';
|
||||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ function setupReflector() {
|
||||||
reflector.registerGetters({
|
reflector.registerGetters({
|
||||||
'benchmarktype': (o) => o.benchmarktype,
|
'benchmarktype': (o) => o.benchmarktype,
|
||||||
'switch': (o) => null,
|
'switch': (o) => null,
|
||||||
'switchWhen': (o) => o.switchWhen
|
'switchCase': (o) => o.switchCase
|
||||||
});
|
});
|
||||||
reflector.registerSetters({
|
reflector.registerSetters({
|
||||||
'benchmarktype': (o, v) => o.benchmarktype = v,
|
'benchmarktype': (o, v) => o.benchmarktype = v,
|
||||||
'switch': (o, v) => null,
|
'switch': (o, v) => null,
|
||||||
'switchWhen': (o, v) => o.switchWhen = v
|
'switchCase': (o, v) => o.switchCase = v
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,24 +210,24 @@ class CellData {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'largetable',
|
selector: 'largetable',
|
||||||
inputs: ['data', 'benchmarkType'],
|
inputs: ['data', 'benchmarkType'],
|
||||||
directives: [NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault],
|
directives: [NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault],
|
||||||
template: `
|
template: `
|
||||||
<table [ngSwitch]="benchmarkType">
|
<table [ngSwitch]="benchmarkType">
|
||||||
<tbody template="ngSwitchWhen 'interpolation'">
|
<tbody template="ngSwitchCase 'interpolation'">
|
||||||
<tr template="ngFor let row of data">
|
<tr template="ngFor let row of data">
|
||||||
<td template="ngFor let column of row">
|
<td template="ngFor let column of row">
|
||||||
{{column.i}}:{{column.j}}|
|
{{column.i}}:{{column.j}}|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tbody template="ngSwitchWhen 'interpolationAttr'">
|
<tbody template="ngSwitchCase 'interpolationAttr'">
|
||||||
<tr template="ngFor let row of data">
|
<tr template="ngFor let row of data">
|
||||||
<td template="ngFor let column of row" attr.i="{{column.i}}" attr.j="{{column.j}}">
|
<td template="ngFor let column of row" attr.i="{{column.i}}" attr.j="{{column.j}}">
|
||||||
i,j attrs
|
i,j attrs
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tbody template="ngSwitchWhen 'interpolationFn'">
|
<tbody template="ngSwitchCase 'interpolationFn'">
|
||||||
<tr template="ngFor let row of data">
|
<tr template="ngFor let row of data">
|
||||||
<td template="ngFor let column of row">
|
<td template="ngFor let column of row">
|
||||||
{{column.iFn()}}:{{column.jFn()}}|
|
{{column.iFn()}}:{{column.jFn()}}|
|
||||||
|
|
|
@ -164,7 +164,6 @@ export declare class NgSwitch {
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class NgSwitchCase {
|
export declare class NgSwitchCase {
|
||||||
ngSwitchCase: any;
|
ngSwitchCase: any;
|
||||||
ngSwitchWhen: any;
|
|
||||||
constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef<Object>, ngSwitch: NgSwitch);
|
constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef<Object>, ngSwitch: NgSwitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,14 +329,6 @@ export declare abstract class ComponentRef<C> {
|
||||||
abstract onDestroy(callback: Function): void;
|
abstract onDestroy(callback: Function): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export declare abstract class ComponentResolver {
|
|
||||||
abstract clearCache(): void;
|
|
||||||
abstract resolveComponent(component: Type<any> | string): Promise<ComponentFactory<any>>;
|
|
||||||
static DynamicCompilationDeprecationMsg: string;
|
|
||||||
static LazyLoadingDeprecationMsg: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class ComponentStillLoadingError extends BaseException {
|
export declare class ComponentStillLoadingError extends BaseException {
|
||||||
compType: Type<any>;
|
compType: Type<any>;
|
||||||
|
|
Loading…
Reference in New Issue