File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
compiler/src/view_compiler Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -576,7 +576,7 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
576
576
}
577
577
stmts . push ( ...view . detectChangesRenderPropertiesMethod . finish ( ) ) ;
578
578
view . viewChildren . forEach ( ( viewChild ) => {
579
- stmts . push ( viewChild . callMethod ( 'detectChanges ' , [ DetectChangesVars . throwOnChange ] ) . toStmt ( ) ) ;
579
+ stmts . push ( viewChild . callMethod ( 'internalDetectChanges ' , [ DetectChangesVars . throwOnChange ] ) . toStmt ( ) ) ;
580
580
} ) ;
581
581
const afterViewStmts =
582
582
view . updateViewQueriesMethod . finish ( ) . concat ( view . afterViewLifecycleCallbacksMethod . finish ( ) ) ;
Original file line number Diff line number Diff line change @@ -312,11 +312,16 @@ export abstract class AppView<T> {
312
312
*/
313
313
dirtyParentQueriesInternal ( ) : void { }
314
314
315
+ internalDetectChanges ( throwOnChange : boolean ) : void {
316
+ if ( this . cdMode !== ChangeDetectorStatus . Detached ) {
317
+ this . detectChanges ( throwOnChange ) ;
318
+ }
319
+ }
320
+
315
321
detectChanges ( throwOnChange : boolean ) : void {
316
322
const s = _scope_check ( this . clazz ) ;
317
323
if ( this . cdMode === ChangeDetectorStatus . Checked ||
318
- this . cdMode === ChangeDetectorStatus . Errored ||
319
- this . cdMode === ChangeDetectorStatus . Detached )
324
+ this . cdMode === ChangeDetectorStatus . Errored )
320
325
return ;
321
326
if ( this . cdMode === ChangeDetectorStatus . Destroyed ) {
322
327
this . throwDestroyedError ( 'detectChanges' ) ;
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ export function main() {
82
82
AnotherComponent ,
83
83
TestLocals ,
84
84
CompWithRef ,
85
+ WrapCompWithRef ,
85
86
EmitterDirective ,
86
87
PushComp ,
87
88
OnDestroyDirective ,
@@ -1133,6 +1134,23 @@ export function main() {
1133
1134
expect ( renderLog . log ) . toEqual ( [ ] ) ;
1134
1135
} ) ) ;
1135
1136
1137
+ it ( 'Detached view can be checked locally' , fakeAsync ( ( ) => {
1138
+ const ctx = createCompFixture ( '<wrap-comp-with-ref></wrap-comp-with-ref>' ) ;
1139
+ const cmp : CompWithRef = queryDirs ( ctx . debugElement , CompWithRef ) [ 0 ] ;
1140
+ cmp . value = 'hello' ;
1141
+ cmp . changeDetectorRef . detach ( ) ;
1142
+ expect ( renderLog . log ) . toEqual ( [ ] ) ;
1143
+
1144
+ ctx . detectChanges ( ) ;
1145
+
1146
+ expect ( renderLog . log ) . toEqual ( [ ] ) ;
1147
+
1148
+ cmp . changeDetectorRef . detectChanges ( ) ;
1149
+
1150
+ expect ( renderLog . log ) . toEqual ( [ '{{hello}}' ] ) ;
1151
+ } ) ) ;
1152
+
1153
+
1136
1154
it ( 'Reattaches' , fakeAsync ( ( ) => {
1137
1155
const ctx = createCompFixture ( '<comp-with-ref></comp-with-ref>' ) ;
1138
1156
const cmp : CompWithRef = queryDirs ( ctx . debugElement , CompWithRef ) [ 0 ] ;
@@ -1346,6 +1364,14 @@ class CompWithRef {
1346
1364
noop ( ) { }
1347
1365
}
1348
1366
1367
+ @Component ( {
1368
+ selector : 'wrap-comp-with-ref' ,
1369
+ template : '<comp-with-ref></comp-with-ref>'
1370
+ } )
1371
+ class WrapCompWithRef {
1372
+ constructor ( public changeDetectorRef : ChangeDetectorRef ) { }
1373
+ }
1374
+
1349
1375
@Component ( {
1350
1376
selector : 'push-cmp' ,
1351
1377
template : '<div (event)="noop()" emitterDirective></div>{{value}}{{renderIncrement}}' ,
You can’t perform that action at this time.
0 commit comments