@ -11,7 +11,7 @@ import {platformBrowser} from '@angular/platform-browser';
|
||||
|
||||
import {IInjectorService, IProvideService, module_ as angularModule} from '../../src/common/src/angular1';
|
||||
import {$INJECTOR, $PROVIDE, DOWNGRADED_MODULE_COUNT_KEY, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../../src/common/src/constants';
|
||||
import {LazyModuleRef, UpgradeAppType, getDowngradedModuleCount, isFunction} from '../../src/common/src/util';
|
||||
import {getDowngradedModuleCount, isFunction, LazyModuleRef, UpgradeAppType} from '../../src/common/src/util';
|
||||
|
||||
import {angular1Providers, setTempInjectorRef} from './angular1_providers';
|
||||
import {NgAdapterInjector} from './util';
|
||||
@ -128,9 +128,8 @@ let moduleUid = 0;
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export function downgradeModule<T>(
|
||||
moduleFactoryOrBootstrapFn: NgModuleFactory<T>|
|
||||
((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>)): string {
|
||||
export function downgradeModule<T>(moduleFactoryOrBootstrapFn: NgModuleFactory<T>|(
|
||||
(extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>)): string {
|
||||
const lazyModuleName = `${UPGRADE_MODULE_NAME}.lazy${++moduleUid}`;
|
||||
const lazyModuleRefKey = `${LAZY_MODULE_REF}${lazyModuleName}`;
|
||||
const lazyInjectorKey = `${INJECTOR_KEY}${lazyModuleName}`;
|
||||
|
@ -79,18 +79,18 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
private bindings: Bindings;
|
||||
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private controllerInstance !: IControllerInstance;
|
||||
private controllerInstance!: IControllerInstance;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private bindingDestination !: IBindingDestination;
|
||||
private bindingDestination!: IBindingDestination;
|
||||
|
||||
// We will be instantiating the controller in the `ngOnInit` hook, when the
|
||||
// first `ngOnChanges` will have been already triggered. We store the
|
||||
// `SimpleChanges` and "play them back" later.
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private pendingChanges !: SimpleChanges | null;
|
||||
private pendingChanges!: SimpleChanges|null;
|
||||
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private unregisterDoCheckWatcher !: Function;
|
||||
private unregisterDoCheckWatcher!: Function;
|
||||
|
||||
/**
|
||||
* Create a new `UpgradeComponent` instance. You should not normally need to do this.
|
||||
@ -135,8 +135,8 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
if (controllerType) {
|
||||
this.controllerInstance = this.helper.buildController(controllerType, this.$componentScope);
|
||||
} else if (bindToController) {
|
||||
throw new Error(
|
||||
`Upgraded directive '${this.directive.name}' specifies 'bindToController' but no controller.`);
|
||||
throw new Error(`Upgraded directive '${
|
||||
this.directive.name}' specifies 'bindToController' but no controller.`);
|
||||
}
|
||||
|
||||
// Set up outputs
|
||||
@ -160,7 +160,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
|
||||
// Hook: $doCheck
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$doCheck)) {
|
||||
const callDoCheck = () => this.controllerInstance.$doCheck !();
|
||||
const callDoCheck = () => this.controllerInstance.$doCheck!();
|
||||
|
||||
this.unregisterDoCheckWatcher = this.$componentScope.$parent.$watch(callDoCheck);
|
||||
callDoCheck();
|
||||
@ -176,7 +176,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||
}
|
||||
|
||||
linkFn(this.$componentScope, null !, {parentBoundTranscludeFn: attachChildNodes});
|
||||
linkFn(this.$componentScope, null!, {parentBoundTranscludeFn: attachChildNodes});
|
||||
|
||||
if (postLink) {
|
||||
postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||
@ -224,7 +224,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
|
||||
private initializeBindings(directive: IDirective) {
|
||||
const btcIsObject = typeof directive.bindToController === 'object';
|
||||
if (btcIsObject && Object.keys(directive.scope !).length) {
|
||||
if (btcIsObject && Object.keys(directive.scope!).length) {
|
||||
throw new Error(
|
||||
`Binding definitions on scope and controller at the same time is not supported.`);
|
||||
}
|
||||
|
@ -6,11 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector, NgModule, NgZone, Testability, isDevMode} from '@angular/core';
|
||||
import {Injector, isDevMode, NgModule, NgZone, Testability} from '@angular/core';
|
||||
|
||||
import {IInjectorService, IIntervalService, IProvideService, ITestabilityService, bootstrap, element as angularElement, module_ as angularModule} from '../../src/common/src/angular1';
|
||||
import {bootstrap, element as angularElement, IInjectorService, IIntervalService, IProvideService, ITestabilityService, module_ as angularModule} from '../../src/common/src/angular1';
|
||||
import {$$TESTABILITY, $DELEGATE, $INJECTOR, $INTERVAL, $PROVIDE, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../../src/common/src/constants';
|
||||
import {LazyModuleRef, UpgradeAppType, controllerKey} from '../../src/common/src/util';
|
||||
import {controllerKey, LazyModuleRef, UpgradeAppType} from '../../src/common/src/util';
|
||||
|
||||
import {angular1Providers, setTempInjectorRef} from './angular1_providers';
|
||||
import {NgAdapterInjector} from './util';
|
||||
@ -179,7 +179,7 @@ export class UpgradeModule {
|
||||
|
||||
.factory(
|
||||
LAZY_MODULE_REF,
|
||||
[INJECTOR_KEY, (injector: Injector) => ({ injector } as LazyModuleRef)])
|
||||
[INJECTOR_KEY, (injector: Injector) => ({injector} as LazyModuleRef)])
|
||||
|
||||
.config([
|
||||
$PROVIDE, $INJECTOR,
|
||||
@ -225,7 +225,9 @@ export class UpgradeModule {
|
||||
// $rootScope.$apply, and running the callback in NgZone will
|
||||
// cause a '$digest already in progress' error if it's in the
|
||||
// same vm turn.
|
||||
setTimeout(() => { this.ngZone.run(() => fn(...args)); });
|
||||
setTimeout(() => {
|
||||
this.ngZone.run(() => fn(...args));
|
||||
});
|
||||
}, delay, count, invokeApply, ...pass);
|
||||
});
|
||||
};
|
||||
@ -248,7 +250,7 @@ export class UpgradeModule {
|
||||
this.injector.get($INJECTOR);
|
||||
|
||||
// Put the injector on the DOM, so that it can be "required"
|
||||
angularElement(element).data !(controllerKey(INJECTOR_KEY), this.injector);
|
||||
angularElement(element).data!(controllerKey(INJECTOR_KEY), this.injector);
|
||||
|
||||
// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
|
||||
// We need to do this in the next tick so that we don't prevent the bootup
|
||||
@ -267,7 +269,9 @@ export class UpgradeModule {
|
||||
|
||||
return $rootScope.$digest();
|
||||
});
|
||||
$rootScope.$on('$destroy', () => { subscription.unsubscribe(); });
|
||||
$rootScope.$on('$destroy', () => {
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
]);
|
||||
@ -279,7 +283,9 @@ export class UpgradeModule {
|
||||
windowAngular.resumeBootstrap = undefined;
|
||||
|
||||
// Bootstrap the AngularJS application inside our zone
|
||||
this.ngZone.run(() => { bootstrap(element, [upgradeModule.name], config); });
|
||||
this.ngZone.run(() => {
|
||||
bootstrap(element, [upgradeModule.name], config);
|
||||
});
|
||||
|
||||
// Patch resumeBootstrap() to run inside the ngZone
|
||||
if (windowAngular.resumeBootstrap) {
|
||||
|
@ -6,11 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Directive, ElementRef, Injector, Input, NgModule, NgZone, SimpleChanges, destroyPlatform} from '@angular/core';
|
||||
import {Component, destroyPlatform, Directive, ElementRef, Injector, Input, NgModule, NgZone, SimpleChanges} from '@angular/core';
|
||||
import {async} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
||||
import {downgradeComponent, UpgradeComponent, UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {html, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
@ -139,7 +139,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'my-app', template: '<my-child [value]="value"></my-child>'})
|
||||
class AppComponent {
|
||||
value?: number;
|
||||
constructor() { appComponent = this; }
|
||||
constructor() {
|
||||
appComponent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -149,15 +151,18 @@ withEachNg1Version(() => {
|
||||
class ChildComponent {
|
||||
valueFromPromise?: number;
|
||||
@Input()
|
||||
set value(v: number) { expect(NgZone.isInAngularZone()).toBe(true); }
|
||||
set value(v: number) {
|
||||
expect(NgZone.isInAngularZone()).toBe(true);
|
||||
}
|
||||
|
||||
constructor(private zone: NgZone) {}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['value'].isFirstChange()) return;
|
||||
|
||||
this.zone.onMicrotaskEmpty.subscribe(
|
||||
() => { expect(element.textContent).toEqual('5'); });
|
||||
this.zone.onMicrotaskEmpty.subscribe(() => {
|
||||
expect(element.textContent).toEqual('5');
|
||||
});
|
||||
|
||||
// Create a micro-task to update the value to be rendered asynchronously.
|
||||
Promise.resolve().then(() => this.valueFromPromise = changes['value'].currentValue);
|
||||
|
@ -6,24 +6,23 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Directive, ElementRef, Injector, Input, NgModule, destroyPlatform} from '@angular/core';
|
||||
import {Component, destroyPlatform, Directive, ElementRef, Injector, Input, NgModule} from '@angular/core';
|
||||
import {async} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {downgradeComponent, UpgradeComponent, UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {html, multiTrim, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
|
||||
import {bootstrap} from './static_test_helpers';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('content projection', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
it('should instantiate ng2 in ng1 template and project content', async(() => {
|
||||
|
||||
// the ng2 component that will be used in ng1 (downgraded)
|
||||
@Component({selector: 'ng2', template: `{{ prop }}(<ng-content></ng-content>)`})
|
||||
class Ng2Component {
|
||||
@ -62,7 +61,7 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: 'ng2-{{ itemId }}(<ng-content></ng-content>)'})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() itemId !: string;
|
||||
@Input() itemId!: string;
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -96,7 +95,6 @@ withEachNg1Version(() => {
|
||||
}));
|
||||
|
||||
it('should instantiate ng1 in ng2 template and project content', async(() => {
|
||||
|
||||
@Component({
|
||||
selector: 'ng2',
|
||||
template: `{{ 'ng2(' }}<ng1>{{ transclude }}</ng1>{{ ')' }}`,
|
||||
@ -142,7 +140,6 @@ withEachNg1Version(() => {
|
||||
}));
|
||||
|
||||
it('should support multi-slot projection', async(() => {
|
||||
|
||||
@Component({
|
||||
selector: 'ng2',
|
||||
template: '2a(<ng-content select=".ng1a"></ng-content>)' +
|
||||
|
@ -6,19 +6,19 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ChangeDetectionStrategy, Compiler, Component, Directive, ElementRef, EventEmitter, Injector, Input, NgModule, NgModuleRef, OnChanges, OnDestroy, Output, SimpleChanges, destroyPlatform} from '@angular/core';
|
||||
import {ChangeDetectionStrategy, Compiler, Component, destroyPlatform, Directive, ElementRef, EventEmitter, Injector, Input, NgModule, NgModuleRef, OnChanges, OnDestroy, Output, SimpleChanges} from '@angular/core';
|
||||
import {async, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {downgradeComponent, UpgradeComponent, UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {html, multiTrim, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
|
||||
import {$apply, bootstrap} from './static_test_helpers';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('downgrade ng2 component', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -73,8 +73,8 @@ withEachNg1Version(() => {
|
||||
}
|
||||
const actualValue = changes[prop].currentValue;
|
||||
if (actualValue != value) {
|
||||
throw new Error(
|
||||
`Expected changes record for'${prop}' to be '${value}' but was '${actualValue}'`);
|
||||
throw new Error(`Expected changes record for'${prop}' to be '${value}' but was '${
|
||||
actualValue}'`);
|
||||
}
|
||||
};
|
||||
|
||||
@ -147,8 +147,9 @@ withEachNg1Version(() => {
|
||||
}));
|
||||
|
||||
it('should bind properties to onpush components', async(() => {
|
||||
const ng1Module = angular.module_('ng1', []).run(
|
||||
($rootScope: angular.IScope) => { $rootScope['dataB'] = 'B'; });
|
||||
const ng1Module = angular.module_('ng1', []).run(($rootScope: angular.IScope) => {
|
||||
$rootScope['dataB'] = 'B';
|
||||
});
|
||||
|
||||
@Component({
|
||||
selector: 'ng2',
|
||||
@ -247,7 +248,9 @@ withEachNg1Version(() => {
|
||||
@Input() value1 = -1;
|
||||
@Input() value2 = -1;
|
||||
|
||||
constructor() { ng2Component = this; }
|
||||
constructor() {
|
||||
ng2Component = this;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -310,7 +313,9 @@ withEachNg1Version(() => {
|
||||
@Input() value1 = -1;
|
||||
@Input() value2 = -1;
|
||||
|
||||
constructor() { ng2Component = this; }
|
||||
constructor() {
|
||||
ng2Component = this;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -372,7 +377,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: '{{ value }}'})
|
||||
class Ng2Component {
|
||||
value = 'foo';
|
||||
constructor() { setTimeout(() => this.value = 'bar', 1000); }
|
||||
constructor() {
|
||||
setTimeout(() => this.value = 'bar', 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -413,9 +420,9 @@ withEachNg1Version(() => {
|
||||
ngOnChangesCount = 0;
|
||||
firstChangesCount = 0;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
initialValue !: string;
|
||||
initialValue!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() foo !: string;
|
||||
@Input() foo!: string;
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
this.ngOnChangesCount++;
|
||||
@ -462,8 +469,9 @@ withEachNg1Version(() => {
|
||||
}));
|
||||
|
||||
it('should bind to ng-model', async(() => {
|
||||
const ng1Module = angular.module_('ng1', []).run(
|
||||
($rootScope: angular.IScope) => { $rootScope['modelA'] = 'A'; });
|
||||
const ng1Module = angular.module_('ng1', []).run(($rootScope: angular.IScope) => {
|
||||
$rootScope['modelA'] = 'A';
|
||||
});
|
||||
|
||||
let ng2Instance: Ng2;
|
||||
@Component({selector: 'ng2', template: '<span>{{_value}}</span>'})
|
||||
@ -471,11 +479,21 @@ withEachNg1Version(() => {
|
||||
private _value: any = '';
|
||||
private _onChangeCallback: (_: any) => void = () => {};
|
||||
private _onTouchedCallback: () => void = () => {};
|
||||
constructor() { ng2Instance = this; }
|
||||
writeValue(value: any) { this._value = value; }
|
||||
registerOnChange(fn: any) { this._onChangeCallback = fn; }
|
||||
registerOnTouched(fn: any) { this._onTouchedCallback = fn; }
|
||||
doTouch() { this._onTouchedCallback(); }
|
||||
constructor() {
|
||||
ng2Instance = this;
|
||||
}
|
||||
writeValue(value: any) {
|
||||
this._value = value;
|
||||
}
|
||||
registerOnChange(fn: any) {
|
||||
this._onChangeCallback = fn;
|
||||
}
|
||||
registerOnTouched(fn: any) {
|
||||
this._onTouchedCallback = fn;
|
||||
}
|
||||
doTouch() {
|
||||
this._onTouchedCallback();
|
||||
}
|
||||
doChange(newValue: string) {
|
||||
this._value = newValue;
|
||||
this._onChangeCallback(newValue);
|
||||
@ -517,11 +535,12 @@ withEachNg1Version(() => {
|
||||
}));
|
||||
|
||||
it('should properly run cleanup when ng1 directive is destroyed', async(() => {
|
||||
|
||||
let destroyed = false;
|
||||
@Component({selector: 'ng2', template: 'test'})
|
||||
class Ng2Component implements OnDestroy {
|
||||
ngOnDestroy() { destroyed = true; }
|
||||
ngOnDestroy() {
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -533,12 +552,13 @@ withEachNg1Version(() => {
|
||||
ngDoBootstrap() {}
|
||||
}
|
||||
|
||||
const ng1Module =
|
||||
angular.module_('ng1', [])
|
||||
.directive(
|
||||
'ng1',
|
||||
() => { return {template: '<div ng-if="!destroyIt"><ng2></ng2></div>'}; })
|
||||
.directive('ng2', downgradeComponent({component: Ng2Component}));
|
||||
const ng1Module = angular.module_('ng1', [])
|
||||
.directive(
|
||||
'ng1',
|
||||
() => {
|
||||
return {template: '<div ng-if="!destroyIt"><ng2></ng2></div>'};
|
||||
})
|
||||
.directive('ng2', downgradeComponent({component: Ng2Component}));
|
||||
const element = html('<ng1></ng1>');
|
||||
platformBrowserDynamic().bootstrapModule(Ng2Module).then((ref) => {
|
||||
const adapter = ref.injector.get(UpgradeModule) as UpgradeModule;
|
||||
@ -567,7 +587,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2-inner', template: 'test'})
|
||||
class Ng2InnerComponent implements OnDestroy {
|
||||
ngOnDestroy() { destroyed = true; }
|
||||
ngOnDestroy() {
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Directive({selector: 'ng1'})
|
||||
@ -607,7 +629,6 @@ withEachNg1Version(() => {
|
||||
|
||||
it('should work when compiled outside the dom (by fallback to the root ng2.injector)',
|
||||
async(() => {
|
||||
|
||||
@Component({selector: 'ng2', template: 'test'})
|
||||
class Ng2Component {
|
||||
}
|
||||
@ -637,7 +658,7 @@ withEachNg1Version(() => {
|
||||
// an ng2 injector so it should use the `moduleInjector` instead.
|
||||
const compiled = $compile('<ng2></ng2>');
|
||||
const template = compiled($scope);
|
||||
$element.append !(template);
|
||||
$element.append!(template);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -770,7 +791,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2', template: ''})
|
||||
class Ng2Component {
|
||||
constructor(injector: Injector) { componentInjector = injector; }
|
||||
constructor(injector: Injector) {
|
||||
componentInjector = injector;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -806,12 +829,11 @@ withEachNg1Version(() => {
|
||||
const modFactory = compiler.compileModuleSync(LazyLoadedModule);
|
||||
const childMod = modFactory.create(modInjector);
|
||||
const cmpFactory =
|
||||
childMod.componentFactoryResolver.resolveComponentFactory(LazyLoadedComponent) !;
|
||||
childMod.componentFactoryResolver.resolveComponentFactory(LazyLoadedComponent)!;
|
||||
const lazyCmp = cmpFactory.create(componentInjector);
|
||||
|
||||
expect(lazyCmp.instance.module.injector === childMod.injector).toBe(true);
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should throw if `downgradedModule` is specified', async(() => {
|
||||
@ -836,7 +858,9 @@ withEachNg1Version(() => {
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module)
|
||||
.then(
|
||||
() => { throw new Error('Expected bootstraping to fail.'); },
|
||||
() => {
|
||||
throw new Error('Expected bootstraping to fail.');
|
||||
},
|
||||
err =>
|
||||
expect(err.message)
|
||||
.toBe(
|
||||
|
@ -6,12 +6,12 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ApplicationRef, Compiler, Component, Directive, DoCheck, ElementRef, Inject, Injectable, Injector, Input, NgModule, NgZone, OnChanges, OnDestroy, OnInit, StaticProvider, Type, ViewRef, destroyPlatform, getPlatform} from '@angular/core';
|
||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ApplicationRef, Compiler, Component, destroyPlatform, Directive, DoCheck, ElementRef, getPlatform, Inject, Injectable, Injector, Input, NgModule, NgZone, OnChanges, OnDestroy, OnInit, StaticProvider, Type, ViewRef} from '@angular/core';
|
||||
import {async, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {UpgradeComponent, downgradeComponent, downgradeModule} from '@angular/upgrade/static';
|
||||
import {downgradeComponent, downgradeModule, UpgradeComponent} from '@angular/upgrade/static';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {$EXCEPTION_HANDLER, $ROOT_SCOPE, INJECTOR_KEY, LAZY_MODULE_REF} from '../../../src/common/src/constants';
|
||||
@ -23,7 +23,6 @@ import {setTempInjectorRef} from '../../src/angular1_providers';
|
||||
withEachNg1Version(() => {
|
||||
[true, false].forEach(propagateDigest => {
|
||||
describe(`lazy-load ng2 module (propagateDigest: ${propagateDigest})`, () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -65,11 +64,13 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', [downModA, downModB])
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2ComponentA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2ComponentB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html('<ng2-a></ng2-a> | <ng2-b></ng2-b>');
|
||||
@ -134,11 +135,13 @@ withEachNg1Version(() => {
|
||||
.directive('ng1A', () => ({template: 'ng1A(<ng2-b ng-if="showB"></ng2-b>)'}))
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2ComponentA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2ComponentB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html('<ng2-a></ng2-a>');
|
||||
@ -206,11 +209,13 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', [downModA, downModB])
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2ComponentA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2ComponentB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html('<ng2-a><ng2-b ng-if="showB"></ng2-b></ng2-a>');
|
||||
@ -299,11 +304,13 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', [downModA, downModB])
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2ComponentA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2ComponentB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html(`
|
||||
@ -497,11 +504,13 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', [downModA, downModB])
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2ComponentA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2ComponentB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html(`
|
||||
@ -599,7 +608,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: '{{ value }}'})
|
||||
class Ng2Component {
|
||||
value: string;
|
||||
constructor(ng2Service: Ng2Service) { this.value = ng2Service.getValue(); }
|
||||
constructor(ng2Service: Ng2Service) {
|
||||
this.value = ng2Service.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -651,7 +662,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: 'In the zone: {{ inTheZone }}'})
|
||||
class Ng2Component {
|
||||
private inTheZone = false;
|
||||
constructor() { this.inTheZone = NgZone.isInAngularZone(); }
|
||||
constructor() {
|
||||
this.inTheZone = NgZone.isInAngularZone();
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -686,7 +699,9 @@ withEachNg1Version(() => {
|
||||
|
||||
@Component({selector: 'ng2', template: ''})
|
||||
class Ng2Component implements OnDestroy {
|
||||
ngOnDestroy() { destroyedInTheZone = NgZone.isInAngularZone(); }
|
||||
ngOnDestroy() {
|
||||
destroyedInTheZone = NgZone.isInAngularZone();
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -725,7 +740,9 @@ withEachNg1Version(() => {
|
||||
@Input() attrInput = 'foo';
|
||||
@Input() propInput = 'foo';
|
||||
|
||||
constructor() { ng2Component = this; }
|
||||
constructor() {
|
||||
ng2Component = this;
|
||||
}
|
||||
ngOnChanges() {}
|
||||
}
|
||||
|
||||
@ -785,8 +802,12 @@ withEachNg1Version(() => {
|
||||
template: '',
|
||||
})
|
||||
class TestComponent implements OnDestroy {
|
||||
constructor() { createdInTheZone = NgZone.isInAngularZone(); }
|
||||
ngOnDestroy() { destroyedInTheZone = NgZone.isInAngularZone(); }
|
||||
constructor() {
|
||||
createdInTheZone = NgZone.isInAngularZone();
|
||||
}
|
||||
ngOnDestroy() {
|
||||
destroyedInTheZone = NgZone.isInAngularZone();
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -842,7 +863,9 @@ withEachNg1Version(() => {
|
||||
{selector: 'ng2', template: '{{ count }}<button (click)="increment()"></button>'})
|
||||
class Ng2Component {
|
||||
private count = 0;
|
||||
increment() { ++this.count; }
|
||||
increment() {
|
||||
++this.count;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -867,7 +890,7 @@ withEachNg1Version(() => {
|
||||
|
||||
setTimeout(() => { // Wait for the module to be bootstrapped.
|
||||
setTimeout(() => { // Wait for `$evalAsync()` to propagate inputs.
|
||||
const button = element.querySelector('button') !;
|
||||
const button = element.querySelector('button')!;
|
||||
expect(element.textContent).toBe('0');
|
||||
|
||||
button.click();
|
||||
@ -885,7 +908,9 @@ withEachNg1Version(() => {
|
||||
{selector: 'test', template: '{{ count }}<button (click)="increment()"></button>'})
|
||||
class TestComponent {
|
||||
count = 0;
|
||||
increment() { ++this.count; }
|
||||
increment() {
|
||||
++this.count;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -924,7 +949,7 @@ withEachNg1Version(() => {
|
||||
setTimeout(() => {
|
||||
// Create nested component asynchronously.
|
||||
$rootScope.$apply('showNg2 = true');
|
||||
const button = element.querySelector('button') !;
|
||||
const button = element.querySelector('button')!;
|
||||
|
||||
expect(element.textContent).toBe('0');
|
||||
|
||||
@ -948,21 +973,38 @@ withEachNg1Version(() => {
|
||||
<ng-content></ng-content>
|
||||
`
|
||||
})
|
||||
class Ng2Component implements AfterContentChecked,
|
||||
AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy,
|
||||
OnInit {
|
||||
class Ng2Component implements AfterContentChecked, AfterContentInit, AfterViewChecked,
|
||||
AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit {
|
||||
@Input() value = 'foo';
|
||||
|
||||
ngAfterContentChecked() { this.log('AfterContentChecked'); }
|
||||
ngAfterContentInit() { this.log('AfterContentInit'); }
|
||||
ngAfterViewChecked() { this.log('AfterViewChecked'); }
|
||||
ngAfterViewInit() { this.log('AfterViewInit'); }
|
||||
ngDoCheck() { this.log('DoCheck'); }
|
||||
ngOnChanges() { this.log('OnChanges'); }
|
||||
ngOnDestroy() { this.log('OnDestroy'); }
|
||||
ngOnInit() { this.log('OnInit'); }
|
||||
ngAfterContentChecked() {
|
||||
this.log('AfterContentChecked');
|
||||
}
|
||||
ngAfterContentInit() {
|
||||
this.log('AfterContentInit');
|
||||
}
|
||||
ngAfterViewChecked() {
|
||||
this.log('AfterViewChecked');
|
||||
}
|
||||
ngAfterViewInit() {
|
||||
this.log('AfterViewInit');
|
||||
}
|
||||
ngDoCheck() {
|
||||
this.log('DoCheck');
|
||||
}
|
||||
ngOnChanges() {
|
||||
this.log('OnChanges');
|
||||
}
|
||||
ngOnDestroy() {
|
||||
this.log('OnDestroy');
|
||||
}
|
||||
ngOnInit() {
|
||||
this.log('OnInit');
|
||||
}
|
||||
|
||||
private log(hook: string) { logs.push(`${hook}(${this.value})`); }
|
||||
private log(hook: string) {
|
||||
logs.push(`${hook}(${this.value})`);
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -991,7 +1033,7 @@ withEachNg1Version(() => {
|
||||
|
||||
setTimeout(() => { // Wait for the module to be bootstrapped.
|
||||
setTimeout(() => { // Wait for `$evalAsync()` to propagate inputs.
|
||||
const button = element.querySelector('button') !;
|
||||
const button = element.querySelector('button')!;
|
||||
|
||||
// Once initialized.
|
||||
expect(multiTrim(element.textContent)).toBe('bar Content');
|
||||
@ -1154,7 +1196,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
private count = ++count;
|
||||
private inTheZone = false;
|
||||
constructor() { this.inTheZone = NgZone.isInAngularZone(); }
|
||||
constructor() {
|
||||
this.inTheZone = NgZone.isInAngularZone();
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -1190,7 +1234,7 @@ withEachNg1Version(() => {
|
||||
tick(tickDelay); // Wait for the module to be bootstrapped and `$evalAsync()` to
|
||||
// propagate inputs.
|
||||
|
||||
const injector = ($injector.get(LAZY_MODULE_REF) as LazyModuleRef).injector !;
|
||||
const injector = ($injector.get(LAZY_MODULE_REF) as LazyModuleRef).injector!;
|
||||
const injectorGet = injector.get;
|
||||
spyOn(injector, 'get').and.callFake((...args: [any, any?]) => {
|
||||
expect(args[0]).not.toBe(NgZone);
|
||||
@ -1295,14 +1339,15 @@ withEachNg1Version(() => {
|
||||
// If the bootstrap process for other components/modules is not completed in time, there is
|
||||
// a chance that some global state is retained, possibly messing subsequent tests.
|
||||
// Explicitly clean up after each test to prevent that.
|
||||
afterEach(() => setTempInjectorRef(null !));
|
||||
afterEach(() => setTempInjectorRef(null!));
|
||||
|
||||
it('should throw if no downgraded module is included', async(() => {
|
||||
const ng1Module = angular.module_('ng1', [])
|
||||
.value($EXCEPTION_HANDLER, errorSpy)
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2CompA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2CompB,
|
||||
@ -1334,11 +1379,13 @@ withEachNg1Version(() => {
|
||||
.value($EXCEPTION_HANDLER, errorSpy)
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2CompA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2CompB,
|
||||
downgradedModule: downModB, propagateDigest,
|
||||
downgradedModule: downModB,
|
||||
propagateDigest,
|
||||
}));
|
||||
|
||||
const element = html('<ng2-a></ng2-a> | <ng2-b></ng2-b>');
|
||||
@ -1360,7 +1407,8 @@ withEachNg1Version(() => {
|
||||
.value($EXCEPTION_HANDLER, errorSpy)
|
||||
.directive('ng2A', downgradeComponent({
|
||||
component: Ng2CompA,
|
||||
downgradedModule: downModA, propagateDigest,
|
||||
downgradedModule: downModA,
|
||||
propagateDigest,
|
||||
}))
|
||||
.directive('ng2B', downgradeComponent({
|
||||
component: Ng2CompB,
|
||||
|
@ -6,11 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Directive, ElementRef, Injector, Input, NgModule, destroyPlatform} from '@angular/core';
|
||||
import {Component, destroyPlatform, Directive, ElementRef, Injector, Input, NgModule} from '@angular/core';
|
||||
import {async} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '@angular/upgrade/static';
|
||||
import {downgradeComponent, UpgradeComponent, UpgradeModule} from '@angular/upgrade/static';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {html, multiTrim, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
@ -19,7 +19,6 @@ import {bootstrap} from './static_test_helpers';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('examples', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -27,13 +26,12 @@ withEachNg1Version(() => {
|
||||
() => expect(angular.getAngularJSGlobal().version.major).toBe(1));
|
||||
|
||||
it('should verify UpgradeAdapter example', async(() => {
|
||||
|
||||
// This is wrapping (upgrading) an AngularJS component to be used in an Angular
|
||||
// component
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1Component extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() title !: string;
|
||||
@Input() title!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -47,7 +45,7 @@ withEachNg1Version(() => {
|
||||
})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input('name') nameProp !: string;
|
||||
@Input('name') nameProp!: string;
|
||||
}
|
||||
|
||||
// This module represents the Angular pieces of the application
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {InjectionToken, Injector, NgModule, destroyPlatform} from '@angular/core';
|
||||
import {destroyPlatform, InjectionToken, Injector, NgModule} from '@angular/core';
|
||||
import {async} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
@ -14,13 +14,12 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {$INJECTOR, INJECTOR_KEY} from '../../../src/common/src/constants';
|
||||
import {html, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
import {UpgradeModule, downgradeInjectable, getAngularJSGlobal, setAngularJSGlobal} from '../../index';
|
||||
import {downgradeInjectable, getAngularJSGlobal, setAngularJSGlobal, UpgradeModule} from '../../index';
|
||||
|
||||
import {bootstrap} from './static_test_helpers';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('injection', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
|
@ -19,7 +19,9 @@ export function bootstrap(
|
||||
const ngZone = ref.injector.get<NgZone>(NgZone);
|
||||
const upgrade = ref.injector.get(UpgradeModule);
|
||||
const failHardModule: any = ($provide: angular.IProvideService) => {
|
||||
$provide.value($EXCEPTION_HANDLER, (err: any) => { throw err; });
|
||||
$provide.value($EXCEPTION_HANDLER, (err: any) => {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
// The `bootstrap()` helper is used for convenience in tests, so that we don't have to inject
|
||||
|
@ -6,20 +6,20 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgModule, Testability, destroyPlatform} from '@angular/core';
|
||||
import {destroyPlatform, NgModule, Testability} from '@angular/core';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {fakeAsync, flush, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {UpgradeModule} from '@angular/upgrade/static';
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {html, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
|
||||
import {bootstrap} from './static_test_helpers';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('testability', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -30,7 +30,7 @@ withEachNg1Version(() => {
|
||||
|
||||
it('should handle deferred bootstrap', fakeAsync(() => {
|
||||
let applicationRunning = false;
|
||||
let stayedInTheZone: boolean = undefined !;
|
||||
let stayedInTheZone: boolean = undefined!;
|
||||
const ng1Module = angular.module_('ng1', []).run(() => {
|
||||
applicationRunning = true;
|
||||
stayedInTheZone = NgZone.isInAngularZone();
|
||||
@ -41,7 +41,9 @@ withEachNg1Version(() => {
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module);
|
||||
|
||||
setTimeout(() => { (<any>window).angular.resumeBootstrap(); }, 100);
|
||||
setTimeout(() => {
|
||||
(<any>window).angular.resumeBootstrap();
|
||||
}, 100);
|
||||
|
||||
expect(applicationRunning).toEqual(false);
|
||||
tick(100);
|
||||
@ -53,7 +55,10 @@ withEachNg1Version(() => {
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
let a1Injector: angular.IInjectorService|undefined;
|
||||
ng1Module.run([
|
||||
'$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; }
|
||||
'$injector',
|
||||
function($injector: angular.IInjectorService) {
|
||||
a1Injector = $injector;
|
||||
}
|
||||
]);
|
||||
const element = html('<div></div>');
|
||||
window.name = 'NG_DEFER_BOOTSTRAP!' + window.name;
|
||||
@ -73,13 +78,14 @@ withEachNg1Version(() => {
|
||||
const element = html('<div></div>');
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => {
|
||||
|
||||
const ng2Testability: Testability = upgrade.injector.get(Testability);
|
||||
ng2Testability.increasePendingRequestCount();
|
||||
let ng2Stable = false;
|
||||
let ng1Stable = false;
|
||||
|
||||
angular.getTestability(element).whenStable(() => { ng1Stable = true; });
|
||||
angular.getTestability(element).whenStable(() => {
|
||||
ng1Stable = true;
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
ng2Stable = true;
|
||||
@ -99,7 +105,6 @@ withEachNg1Version(() => {
|
||||
const element = html('<div></div>');
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => {
|
||||
|
||||
const ng2Testability: Testability = upgrade.injector.get(Testability);
|
||||
const $interval: angular.IIntervalService = upgrade.$injector.get('$interval');
|
||||
|
||||
@ -115,7 +120,9 @@ withEachNg1Version(() => {
|
||||
expect(arg).toEqual('passed argument');
|
||||
}, 200, 0, true, 'passed argument');
|
||||
|
||||
ng2Testability.whenStable(() => { ng2Stable = true; });
|
||||
ng2Testability.whenStable(() => {
|
||||
ng2Stable = true;
|
||||
});
|
||||
|
||||
tick(100);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Directive, ElementRef, EventEmitter, Inject, Injector, Input, NO_ERRORS_SCHEMA, NgModule, Output, SimpleChanges, destroyPlatform} from '@angular/core';
|
||||
import {Component, destroyPlatform, Directive, ElementRef, EventEmitter, Inject, Injector, Input, NgModule, NO_ERRORS_SCHEMA, Output, SimpleChanges} from '@angular/core';
|
||||
import {async, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
@ -14,14 +14,13 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import * as angular from '../../../src/common/src/angular1';
|
||||
import {$EXCEPTION_HANDLER, $SCOPE} from '../../../src/common/src/constants';
|
||||
import {html, multiTrim, withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
import {UpgradeComponent, UpgradeModule, downgradeComponent} from '../../index';
|
||||
import {downgradeComponent, UpgradeComponent, UpgradeModule} from '../../index';
|
||||
|
||||
import {$digest, bootstrap} from './static_test_helpers';
|
||||
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('upgrade ng1 component', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
@ -319,7 +318,7 @@ withEachNg1Version(() => {
|
||||
'$httpBackend',
|
||||
(method: string, url: string, post?: any, callback?: Function) =>
|
||||
setTimeout(
|
||||
() => callback !(200, `${method}:${url}`.toLowerCase()), 1000));
|
||||
() => callback!(200, `${method}:${url}`.toLowerCase()), 1000));
|
||||
|
||||
// Define `Ng2Module`
|
||||
@NgModule({
|
||||
@ -370,7 +369,7 @@ withEachNg1Version(() => {
|
||||
'$httpBackend',
|
||||
(method: string, url: string, post?: any, callback?: Function) =>
|
||||
setTimeout(
|
||||
() => callback !(200, `${method}:${url}`.toLowerCase()), 1000));
|
||||
() => callback!(200, `${method}:${url}`.toLowerCase()), 1000));
|
||||
|
||||
// Define `Ng2Module`
|
||||
@NgModule({
|
||||
@ -404,19 +403,27 @@ withEachNg1Version(() => {
|
||||
// Define `Ng1ComponentFacade`s
|
||||
@Directive({selector: 'ng1A'})
|
||||
class Ng1ComponentAFacade extends UpgradeComponent {
|
||||
constructor(e: ElementRef, i: Injector) { super('ng1A', e, i); }
|
||||
constructor(e: ElementRef, i: Injector) {
|
||||
super('ng1A', e, i);
|
||||
}
|
||||
}
|
||||
@Directive({selector: 'ng1B'})
|
||||
class Ng1ComponentBFacade extends UpgradeComponent {
|
||||
constructor(e: ElementRef, i: Injector) { super('ng1B', e, i); }
|
||||
constructor(e: ElementRef, i: Injector) {
|
||||
super('ng1B', e, i);
|
||||
}
|
||||
}
|
||||
@Directive({selector: 'ng1C'})
|
||||
class Ng1ComponentCFacade extends UpgradeComponent {
|
||||
constructor(e: ElementRef, i: Injector) { super('ng1C', e, i); }
|
||||
constructor(e: ElementRef, i: Injector) {
|
||||
super('ng1C', e, i);
|
||||
}
|
||||
}
|
||||
@Directive({selector: 'ng1D'})
|
||||
class Ng1ComponentDFacade extends UpgradeComponent {
|
||||
constructor(e: ElementRef, i: Injector) { super('ng1D', e, i); }
|
||||
constructor(e: ElementRef, i: Injector) {
|
||||
super('ng1D', e, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Define `Ng2Component`
|
||||
@ -480,9 +487,9 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input('inputAttrA') inputA !: string;
|
||||
@Input('inputAttrA') inputA!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() inputB !: string;
|
||||
@Input() inputB!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -501,7 +508,9 @@ withEachNg1Version(() => {
|
||||
dataA = 'foo';
|
||||
dataB = 'bar';
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -523,8 +532,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -557,9 +566,9 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input('inputAttrA') inputA !: string;
|
||||
@Input('inputAttrA') inputA!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() inputB !: string;
|
||||
@Input() inputB!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -578,7 +587,9 @@ withEachNg1Version(() => {
|
||||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -600,8 +611,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -634,13 +645,13 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input('inputAttrA') inputA !: string;
|
||||
@Input('inputAttrA') inputA!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output('inputAttrAChange') inputAChange !: EventEmitter<any>;
|
||||
@Output('inputAttrAChange') inputAChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() inputB !: string;
|
||||
@Input() inputB!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() inputBChange !: EventEmitter<any>;
|
||||
@Output() inputBChange!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -659,7 +670,9 @@ withEachNg1Version(() => {
|
||||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -681,8 +694,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
@ -713,9 +726,9 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output('outputAttrA') outputA !: EventEmitter<any>;
|
||||
@Output('outputAttrA') outputA!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() outputB !: EventEmitter<any>;
|
||||
@Output() outputB!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -754,8 +767,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(() => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: - | Outside: foo, bar');
|
||||
|
||||
@ -797,16 +810,16 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() fullName !: string;
|
||||
@Input() fullName!: string;
|
||||
@Input('dataA') modelA: any;
|
||||
@Input('dataB') modelB: any;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output('dataBChange') modelBChange !: EventEmitter<any>;
|
||||
@Output('dataBChange') modelBChange!: EventEmitter<any>;
|
||||
@Input() modelC: any;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() modelCChange !: EventEmitter<any>;
|
||||
@Output() modelCChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() event !: EventEmitter<any>;
|
||||
@Output() event!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -880,17 +893,17 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input('inputAttrA') inputA !: string;
|
||||
@Input('inputAttrA') inputA!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output('inputAttrAChange') inputAChange !: EventEmitter<any>;
|
||||
@Output('inputAttrAChange') inputAChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() inputB !: string;
|
||||
@Input() inputB!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() inputBChange !: EventEmitter<any>;
|
||||
@Output() inputBChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output('outputAttrA') outputA !: EventEmitter<any>;
|
||||
@Output('outputAttrA') outputA!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() outputB !: EventEmitter<any>;
|
||||
@Output() outputB!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -912,7 +925,9 @@ withEachNg1Version(() => {
|
||||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
updateDataB(value: any) { this.dataB.value = value; }
|
||||
updateDataB(value: any) {
|
||||
this.dataB.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -934,10 +949,10 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
const ng1s = element.querySelectorAll('ng1') !;
|
||||
const ng1Controller0 = angular.element(ng1s[0]).controller !('ng1');
|
||||
const ng1Controller1 = angular.element(ng1s[1]).controller !('ng1');
|
||||
const ng1Controller2 = angular.element(ng1s[2]).controller !('ng1');
|
||||
const ng1s = element.querySelectorAll('ng1')!;
|
||||
const ng1Controller0 = angular.element(ng1s[0]).controller!('ng1');
|
||||
const ng1Controller1 = angular.element(ng1s[1]).controller!('ng1');
|
||||
const ng1Controller2 = angular.element(ng1s[2]).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent))
|
||||
.toBe(
|
||||
@ -981,11 +996,11 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: '[ng1]'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() inputA !: string;
|
||||
@Input() inputA!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() inputAChange !: EventEmitter<any>;
|
||||
@Output() inputAChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() outputA !: EventEmitter<any>;
|
||||
@Output() outputA!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -1024,8 +1039,8 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
const ng1 = element.querySelector('[ng1]') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('[ng1]')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent))
|
||||
.toBe('ng1 - Data: [1,2,3] - Length: 3 | ng2 - Data: 1,2,3 - Length: 3');
|
||||
@ -1055,7 +1070,7 @@ withEachNg1Version(() => {
|
||||
const ng1ComponentA: angular.IComponent = {template: 'ng1A(<ng1-b></ng1-b>)'};
|
||||
const ng1DirectiveB: angular.IDirective = {
|
||||
compile: tElem => {
|
||||
grandParentNodeName = tElem.parent !().parent !()[0].nodeName;
|
||||
grandParentNodeName = tElem.parent!().parent!()[0].nodeName;
|
||||
return {};
|
||||
}
|
||||
};
|
||||
@ -1106,7 +1121,11 @@ withEachNg1Version(() => {
|
||||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: {pre: () => log.push('ng1-pre')},
|
||||
controller: class {constructor() { log.push('ng1-ctrl'); }}
|
||||
controller: class {
|
||||
constructor() {
|
||||
log.push('ng1-ctrl');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -1296,7 +1315,11 @@ withEachNg1Version(() => {
|
||||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: () => log.push('ng1-post'),
|
||||
controller: class {$postLink() { log.push('ng1-$post'); }}
|
||||
controller: class {
|
||||
$postLink() {
|
||||
log.push('ng1-$post');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -1346,7 +1369,7 @@ withEachNg1Version(() => {
|
||||
controllerAs: 'vm',
|
||||
controller: class {
|
||||
hasElement: string; // TODO(issue/24571): remove '!'.
|
||||
isClass !: string;
|
||||
isClass!: string;
|
||||
scope: string;
|
||||
|
||||
constructor(public $element: angular.IAugmentedJQuery, $scope: angular.IScope) {
|
||||
@ -1357,10 +1380,12 @@ withEachNg1Version(() => {
|
||||
}
|
||||
|
||||
isPublished() {
|
||||
return this.$element.controller !('ng1') === this ? 'published' : 'not-published';
|
||||
return this.$element.controller!('ng1') === this ? 'published' : 'not-published';
|
||||
}
|
||||
|
||||
verifyIAmAClass() { this.isClass = 'isClass'; }
|
||||
verifyIAmAClass() {
|
||||
this.isClass = 'isClass';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1422,7 +1447,7 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1A'})
|
||||
class Ng1ComponentAFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() title !: string;
|
||||
@Input() title!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1A', elementRef, injector);
|
||||
@ -1432,7 +1457,7 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1B'})
|
||||
class Ng1ComponentBFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() title !: string;
|
||||
@Input() title!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1B', elementRef, injector);
|
||||
@ -1490,7 +1515,7 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() title !: string;
|
||||
@Input() title!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -1540,7 +1565,7 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1'})
|
||||
class Ng1ComponentFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() title !: string;
|
||||
@Input() title!: string;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1', elementRef, injector);
|
||||
@ -1554,7 +1579,11 @@ withEachNg1Version(() => {
|
||||
|
||||
// Define `ng1Module`
|
||||
const ng1Module = angular.module_('ng1Module', [])
|
||||
.controller('Ng1Controller', class { text = 'GREAT'; })
|
||||
.controller(
|
||||
'Ng1Controller',
|
||||
class {
|
||||
text = 'GREAT';
|
||||
})
|
||||
.directive('ng1', () => ng1Directive)
|
||||
.directive('ng2', downgradeComponent({component: Ng2Component}));
|
||||
|
||||
@ -1587,7 +1616,7 @@ withEachNg1Version(() => {
|
||||
name = 'world';
|
||||
|
||||
constructor($element: angular.IAugmentedJQuery) {
|
||||
getCurrentContent = () => $element.text !();
|
||||
getCurrentContent = () => $element.text!();
|
||||
compiledContent = getCurrentContent();
|
||||
}
|
||||
}
|
||||
@ -1638,7 +1667,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Directive`
|
||||
const ng1Directive: angular.IDirective = {
|
||||
template: 'Pre: {{ pre }} | Post: {{ post }}',
|
||||
controller: class {value = 'foo';},
|
||||
controller: class {
|
||||
value = 'foo';
|
||||
},
|
||||
link: {
|
||||
pre: function(scope: any, elem: any, attrs: any, ctrl: any) {
|
||||
scope['pre'] = ctrl.value;
|
||||
@ -1693,7 +1724,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: '<ng1-b></ng1-b>',
|
||||
controller: class {value = 'ng1A';}
|
||||
controller: class {
|
||||
value = 'ng1A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
@ -1881,7 +1914,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: 'ng1A(<div><ng2></ng2></div>)',
|
||||
controller: class {value = 'A';}
|
||||
controller: class {
|
||||
value = 'A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
@ -1957,7 +1992,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: 'ng1A(<div><ng2></ng2></div>)',
|
||||
controller: class {value = 'A';}
|
||||
controller: class {
|
||||
value = 'A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
@ -1977,7 +2014,9 @@ withEachNg1Version(() => {
|
||||
ng1BSelfUp: '^ng1B',
|
||||
ng1BParentUp: '?^^ng1B',
|
||||
},
|
||||
controller: class {value = 'B';}
|
||||
controller: class {
|
||||
value = 'B';
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -2023,7 +2062,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: '<ng2></ng2>',
|
||||
controller: class {value = 'ng1A';}
|
||||
controller: class {
|
||||
value = 'ng1A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
@ -2078,11 +2119,17 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: '<ng1-b></ng1-b>',
|
||||
controller: class {value = 'A';}
|
||||
controller: class {
|
||||
value = 'A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB:
|
||||
angular.IComponent = {template: '<ng2></ng2>', controller: class {value = 'B';}};
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
template: '<ng2></ng2>',
|
||||
controller: class {
|
||||
value = 'B';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentC: angular.IComponent = {
|
||||
template:
|
||||
@ -2092,7 +2139,9 @@ withEachNg1Version(() => {
|
||||
ng1B: '?^',
|
||||
ng1C: '',
|
||||
},
|
||||
controller: class {value = 'C';}
|
||||
controller: class {
|
||||
value = 'C';
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -2160,13 +2209,17 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
value = 'foo';
|
||||
showB = false;
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: 'ng2B({{ value }})'})
|
||||
class Ng2ComponentB {
|
||||
value = 'bar';
|
||||
constructor() { ng2ComponentBInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentBInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2211,8 +2264,12 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
template: 'ng1(<div ng-transclude>{{ $ctrl.value }}</div>)',
|
||||
transclude: true,
|
||||
controller:
|
||||
class {value = 'from-ng1'; constructor() { ng1ControllerInstances.push(this); }}
|
||||
controller: class {
|
||||
value = 'from-ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -2227,7 +2284,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: 'ng2(<ng1>{{ value }}</ng1> | <ng1></ng1>)'})
|
||||
class Ng2Component {
|
||||
value = 'from-ng2';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2293,7 +2352,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2334,8 +2395,12 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
template: 'ng1(default(<div ng-transclude="">fallback-{{ $ctrl.value }}</div>))',
|
||||
transclude: {slotX: 'contentX', slotY: 'contentY'},
|
||||
controller:
|
||||
class {value = 'ng1'; constructor() { ng1ControllerInstances.push(this); }}
|
||||
controller: class {
|
||||
value = 'ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -2368,7 +2433,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2417,7 +2484,11 @@ withEachNg1Version(() => {
|
||||
)`,
|
||||
transclude: {slotX: '?contentX', slotY: '?contentY'},
|
||||
controller: class {
|
||||
x = 'ng1X'; y = 'ng1Y'; constructor() { ng1ControllerInstances.push(this); }
|
||||
x = 'ng1X';
|
||||
y = 'ng1Y';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -2441,7 +2512,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
x = 'ng2X';
|
||||
y = 'ng2Y';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2563,7 +2636,9 @@ withEachNg1Version(() => {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
show = true;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2616,8 +2691,11 @@ withEachNg1Version(() => {
|
||||
scope: {inputA: '<'},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller:
|
||||
class {$onChanges(changes: SimpleChanges) { controllerOnChangesA(changes); }}
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) {
|
||||
controllerOnChangesA(changes);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const ng1DirectiveB: angular.IDirective = {
|
||||
@ -2625,8 +2703,11 @@ withEachNg1Version(() => {
|
||||
scope: {inputB: '<'},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller:
|
||||
class {$onChanges(changes: SimpleChanges) { controllerOnChangesB(changes); }}
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) {
|
||||
controllerOnChangesB(changes);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -2656,7 +2737,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
data = {foo: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2809,7 +2892,9 @@ withEachNg1Version(() => {
|
||||
class Ng2Component {
|
||||
data = {foo: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -2905,9 +2990,13 @@ withEachNg1Version(() => {
|
||||
template: 'Called: {{ called }}',
|
||||
bindToController: false,
|
||||
controller: class {
|
||||
constructor(private $scope: angular.IScope) { $scope['called'] = 'no'; }
|
||||
constructor(private $scope: angular.IScope) {
|
||||
$scope['called'] = 'no';
|
||||
}
|
||||
|
||||
$onInit() { this.$scope['called'] = 'yes'; }
|
||||
$onInit() {
|
||||
this.$scope['called'] = 'yes';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3042,9 +3131,13 @@ withEachNg1Version(() => {
|
||||
template: 'Called: {{ called }}',
|
||||
bindToController: false,
|
||||
controller: class {
|
||||
constructor(private $scope: angular.IScope) { $scope['called'] = 'no'; }
|
||||
constructor(private $scope: angular.IScope) {
|
||||
$scope['called'] = 'no';
|
||||
}
|
||||
|
||||
$postLink() { this.$scope['called'] = 'yes'; }
|
||||
$postLink() {
|
||||
this.$scope['called'] = 'yes';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3182,13 +3275,21 @@ withEachNg1Version(() => {
|
||||
const ng1DirectiveA: angular.IDirective = {
|
||||
template: 'ng1A',
|
||||
bindToController: false,
|
||||
controller: class {$doCheck() { controllerDoCheckA(); }}
|
||||
controller: class {
|
||||
$doCheck() {
|
||||
controllerDoCheckA();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const ng1DirectiveB: angular.IDirective = {
|
||||
template: 'ng1B',
|
||||
bindToController: true,
|
||||
controller: class {constructor() { (this as any)['$doCheck'] = controllerDoCheckB; }}
|
||||
controller: class {
|
||||
constructor() {
|
||||
(this as any)['$doCheck'] = controllerDoCheckB;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -3261,7 +3362,9 @@ withEachNg1Version(() => {
|
||||
template: 'ng1A',
|
||||
bindToController: false,
|
||||
controller: class {
|
||||
constructor(private $scope: angular.IScope) { $scope['$doCheck'] = scopeDoCheck; }
|
||||
constructor(private $scope: angular.IScope) {
|
||||
$scope['$doCheck'] = scopeDoCheck;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3269,7 +3372,9 @@ withEachNg1Version(() => {
|
||||
template: 'ng1B',
|
||||
bindToController: true,
|
||||
controller: class {
|
||||
constructor(private $scope: angular.IScope) { $scope['$doCheck'] = scopeDoCheck; }
|
||||
constructor(private $scope: angular.IScope) {
|
||||
$scope['$doCheck'] = scopeDoCheck;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3337,7 +3442,11 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$onDestroy() { controllerOnDestroyA(); }}
|
||||
controller: class {
|
||||
$onDestroy() {
|
||||
controllerOnDestroyA();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const ng1DirectiveB: angular.IDirective = {
|
||||
@ -3345,8 +3454,11 @@ withEachNg1Version(() => {
|
||||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller:
|
||||
class {constructor() { (this as any)['$onDestroy'] = controllerOnDestroyB; }}
|
||||
controller: class {
|
||||
constructor() {
|
||||
(this as any)['$onDestroy'] = controllerOnDestroyB;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@ -3369,7 +3481,7 @@ withEachNg1Version(() => {
|
||||
{selector: 'ng2', template: '<div *ngIf="show"><ng1A></ng1A> | <ng1B></ng1B></div>'})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() show !: boolean;
|
||||
@Input() show!: boolean;
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -3470,7 +3582,7 @@ withEachNg1Version(() => {
|
||||
{selector: 'ng2', template: '<div *ngIf="show"><ng1A></ng1A> | <ng1B></ng1B></div>'})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() show !: boolean;
|
||||
@Input() show!: boolean;
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -3526,13 +3638,21 @@ withEachNg1Version(() => {
|
||||
controller: class {
|
||||
calls: string[] = [];
|
||||
|
||||
$onChanges() { this.calls.push('$onChanges'); }
|
||||
$onChanges() {
|
||||
this.calls.push('$onChanges');
|
||||
}
|
||||
|
||||
$onInit() { this.calls.push('$onInit'); }
|
||||
$onInit() {
|
||||
this.calls.push('$onInit');
|
||||
}
|
||||
|
||||
$doCheck() { this.calls.push('$doCheck'); }
|
||||
$doCheck() {
|
||||
this.calls.push('$doCheck');
|
||||
}
|
||||
|
||||
$postLink() { this.calls.push('$postLink'); }
|
||||
$postLink() {
|
||||
this.calls.push('$postLink');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3584,7 +3704,9 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor($scope: angular.IScope) { $scope.$on('$destroy', scopeDestroyListener); }
|
||||
constructor($scope: angular.IScope) {
|
||||
$scope.$on('$destroy', scopeDestroyListener);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -3601,7 +3723,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -3645,8 +3769,8 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor($element: angular.IAugmentedJQuery) {
|
||||
$element.on !('$destroy', elementDestroyListener);
|
||||
$element.contents !().on !('$destroy', descendantDestroyListener);
|
||||
$element.on!('$destroy', elementDestroyListener);
|
||||
$element.contents!().on!('$destroy', descendantDestroyListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
@ -3665,7 +3789,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -3710,8 +3836,8 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor($element: angular.IAugmentedJQuery) {
|
||||
$element.data !('test', 1);
|
||||
$element.contents !().data !('test', 2);
|
||||
$element.data!('test', 1);
|
||||
$element.contents!().data!('test', 2);
|
||||
|
||||
ng1ComponentElement = $element;
|
||||
}
|
||||
@ -3732,7 +3858,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -3758,14 +3886,14 @@ withEachNg1Version(() => {
|
||||
const element = html(`<ng2-a></ng2-a>`);
|
||||
|
||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(adapter => {
|
||||
expect(ng1ComponentElement.data !('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBe(2);
|
||||
expect(ng1ComponentElement.data!('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBe(2);
|
||||
|
||||
ng2ComponentAInstance.destroyIt = true;
|
||||
$digest(adapter);
|
||||
|
||||
expect(ng1ComponentElement.data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.data!('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBeUndefined();
|
||||
});
|
||||
}));
|
||||
|
||||
@ -3779,10 +3907,10 @@ withEachNg1Version(() => {
|
||||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor($element: angular.IAugmentedJQuery) {
|
||||
ng1DescendantElement = $element.contents !();
|
||||
ng1DescendantElement = $element.contents!();
|
||||
|
||||
$element.on !('click', elementClickListener);
|
||||
ng1DescendantElement.on !('click', descendantClickListener);
|
||||
$element.on!('click', elementClickListener);
|
||||
ng1DescendantElement.on!('click', descendantClickListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
@ -3801,7 +3929,9 @@ withEachNg1Version(() => {
|
||||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
@ -3844,8 +3974,12 @@ withEachNg1Version(() => {
|
||||
let ng2Component: Ng2Component;
|
||||
|
||||
// Define `ng1Component`
|
||||
const ng1Component:
|
||||
angular.IComponent = {template: 'ng1', controller: class {$doCheck() {}}};
|
||||
const ng1Component: angular.IComponent = {
|
||||
template: 'ng1',
|
||||
controller: class {
|
||||
$doCheck() {}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
@Directive({selector: 'ng1'})
|
||||
@ -3859,7 +3993,9 @@ withEachNg1Version(() => {
|
||||
@Component({selector: 'ng2', template: '<ng1 *ngIf="doShow"></ng1>'})
|
||||
class Ng2Component {
|
||||
doShow: boolean = false;
|
||||
constructor(@Inject($SCOPE) public $scope: angular.IScope) { ng2Component = this; }
|
||||
constructor(@Inject($SCOPE) public $scope: angular.IScope) {
|
||||
ng2Component = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -3959,11 +4095,13 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
class Ng1ControllerX {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
ng1XInputA !: string;
|
||||
ng1XInputA!: string;
|
||||
ng1XInputB: any;
|
||||
ng1XInputC: any;
|
||||
|
||||
constructor() { ng1ControllerXInstance = this; }
|
||||
constructor() {
|
||||
ng1ControllerXInstance = this;
|
||||
}
|
||||
}
|
||||
const ng1Component: angular.IComponent = {
|
||||
template: `
|
||||
@ -3988,15 +4126,15 @@ withEachNg1Version(() => {
|
||||
@Directive({selector: 'ng1X'})
|
||||
class Ng1ComponentXFacade extends UpgradeComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() ng1XInputA !: string;
|
||||
@Input() ng1XInputA!: string;
|
||||
@Input() ng1XInputB: any;
|
||||
@Input() ng1XInputC: any;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() ng1XInputCChange !: EventEmitter<any>;
|
||||
@Output() ng1XInputCChange!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() ng1XOutputA !: EventEmitter<any>;
|
||||
@Output() ng1XOutputA!: EventEmitter<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Output() ng1XOutputB !: EventEmitter<any>;
|
||||
@Output() ng1XOutputB!: EventEmitter<any>;
|
||||
|
||||
constructor(elementRef: ElementRef, injector: Injector) {
|
||||
super('ng1X', elementRef, injector);
|
||||
@ -4022,7 +4160,9 @@ withEachNg1Version(() => {
|
||||
ng2ADataB = {value: 'bar'};
|
||||
ng2ADataC = {value: 'baz'};
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2-b', template: 'ng2B({{ ng2BInputA }}, {{ ng2BInputC }})'})
|
||||
@ -4031,7 +4171,9 @@ withEachNg1Version(() => {
|
||||
@Input() ng2BInputC: any;
|
||||
@Output() ng2BOutputC = new EventEmitter();
|
||||
|
||||
constructor() { ng2ComponentBInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentBInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
@ -4145,14 +4287,18 @@ withEachNg1Version(() => {
|
||||
// Define `ng1Component`
|
||||
const ng1ComponentA: angular.IComponent = {
|
||||
template: 'ng1A(<ng2-b></ng2-b>)',
|
||||
controller: class {value = 'ng1A';}
|
||||
controller: class {
|
||||
value = 'ng1A';
|
||||
}
|
||||
};
|
||||
|
||||
const ng1ComponentB: angular.IComponent = {
|
||||
template:
|
||||
'ng1B(^^ng1A: {{ $ctrl.ng1A.value }} | ?^^ng1B: {{ $ctrl.ng1B.value }} | ^ng1B: {{ $ctrl.ng1BSelf.value }})',
|
||||
require: {ng1A: '^^', ng1B: '?^^', ng1BSelf: '^ng1B'},
|
||||
controller: class {value = 'ng1B';}
|
||||
controller: class {
|
||||
value = 'ng1B';
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng1ComponentFacade`
|
||||
|
@ -21,7 +21,9 @@ export function $injectorFactory() {
|
||||
|
||||
@NgModule({providers: [{provide: $INJECTOR, useFactory: $injectorFactory}]})
|
||||
export class AngularTestingModule {
|
||||
constructor(i: Injector) { injector = i; }
|
||||
constructor(i: Injector) {
|
||||
injector = i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import {$INJECTOR} from '../../../src/common/src/constants';
|
||||
import {withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
import {createAngularTestingModule} from '../src/create_angular_testing_module';
|
||||
|
||||
import {AppModule, Inventory, defineAppModule, serverRequestInstance} from './mocks';
|
||||
import {AppModule, defineAppModule, Inventory, serverRequestInstance} from './mocks';
|
||||
|
||||
withEachNg1Version(() => {
|
||||
describe('Angular entry point', () => {
|
||||
|
@ -10,7 +10,7 @@ import {getAngularJSGlobal} from '../../../src/common/src/angular1';
|
||||
import {withEachNg1Version} from '../../../src/common/test/helpers/common_test_helpers';
|
||||
import {createAngularJSTestingModule} from '../src/create_angularjs_testing_module';
|
||||
|
||||
import {AppModule, Inventory, defineAppModule} from './mocks';
|
||||
import {AppModule, defineAppModule, Inventory} from './mocks';
|
||||
|
||||
|
||||
withEachNg1Version(() => {
|
||||
@ -26,7 +26,9 @@ withEachNg1Version(() => {
|
||||
// Configure an AngularJS module that has the AngularJS and Angular injector wired up
|
||||
module(createAngularJSTestingModule([AppModule]));
|
||||
let inventory: any = undefined;
|
||||
inject(function(shoppingCart: any) { inventory = shoppingCart.inventory; });
|
||||
inject(function(shoppingCart: any) {
|
||||
inventory = shoppingCart.inventory;
|
||||
});
|
||||
expect(inventory).toEqual(jasmine.any(Inventory));
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user