|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {ChangeDetectorRef, Compiler, Component, ComponentFactoryResolver, Directive, ElementRef, EventEmitter, Injector, Input, NgModule, NgModuleRef, OnChanges, OnDestroy, Output, SimpleChanges, destroyPlatform} from '@angular/core'; |
| 9 | +import {ChangeDetectionStrategy, ChangeDetectorRef, Compiler, Component, ComponentFactoryResolver, Directive, ElementRef, EventEmitter, Injector, Input, NgModule, NgModuleRef, OnChanges, OnDestroy, Output, SimpleChanges, destroyPlatform} from '@angular/core'; |
10 | 10 | import {async, fakeAsync, tick} from '@angular/core/testing';
|
11 | 11 | import {BrowserModule} from '@angular/platform-browser';
|
12 | 12 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
@@ -148,6 +148,51 @@ withEachNg1Version(() => {
|
148 | 148 | });
|
149 | 149 | }));
|
150 | 150 |
|
| 151 | + it('should bind properties to onpush components', async(() => { |
| 152 | + const ng1Module = |
| 153 | + angular.module('ng1', []).value('$exceptionHandler', (err: any) => { |
| 154 | + throw err; |
| 155 | + }).run(($rootScope: angular.IScope) => { |
| 156 | + $rootScope['dataB'] = 'B'; |
| 157 | + }); |
| 158 | + |
| 159 | + @Component({ |
| 160 | + selector: 'ng2', |
| 161 | + inputs: ['oneWayB'], |
| 162 | + template: 'oneWayB: {{oneWayB}}', |
| 163 | + changeDetection: ChangeDetectionStrategy.OnPush |
| 164 | + }) |
| 165 | + |
| 166 | + class Ng2Component { |
| 167 | + ngOnChangesCount = 0; |
| 168 | + oneWayB = '?'; |
| 169 | + } |
| 170 | + |
| 171 | + ng1Module.directive('ng2', downgradeComponent({ |
| 172 | + component: Ng2Component, |
| 173 | + })); |
| 174 | + |
| 175 | + @NgModule({ |
| 176 | + declarations: [Ng2Component], |
| 177 | + entryComponents: [Ng2Component], |
| 178 | + imports: [BrowserModule, UpgradeModule] |
| 179 | + }) |
| 180 | + class Ng2Module { |
| 181 | + ngDoBootstrap() {} |
| 182 | + } |
| 183 | + |
| 184 | + const element = html(` |
| 185 | + <div> |
| 186 | + <ng2 [one-way-b]="dataB"></ng2> |
| 187 | + </div>`); |
| 188 | + |
| 189 | + bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => { |
| 190 | + expect(multiTrim(document.body.textContent)).toEqual('oneWayB: B'); |
| 191 | + $apply(upgrade, 'dataB= "everyone"'); |
| 192 | + expect(multiTrim(document.body.textContent)).toEqual('oneWayB: everyone'); |
| 193 | + }); |
| 194 | + })); |
| 195 | + |
151 | 196 | it('should support two-way binding and event listener', async(() => {
|
152 | 197 | const listenerSpy = jasmine.createSpy('$rootScope.listener');
|
153 | 198 | const ng1Module = angular.module('ng1', []).run(($rootScope: angular.IScope) => {
|
|
0 commit comments