diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts index 5af1113bca..b0ed81d0c7 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_template_spec.ts @@ -117,6 +117,63 @@ describe('compiler compliance: template', () => { expectEmit(result.source, template, 'Incorrect template'); }); + it('should correctly bind to context in nested template with many bindings', () => { + const files = { + app: { + 'spec.ts': ` + import {Component, NgModule} from '@angular/core'; + + @Component({ + selector: 'my-component', + template: \` +
+ \` + }) + export class MyComponent { + _data = [1,2,3]; + _handleClick(d: any, i: any) {} + } + + @NgModule({declarations: [MyComponent]}) + export class MyModule {} + ` + } + }; + + const template = ` + const $t0_attrs$ = ["ngFor", "", ${AttributeMarker.SelectOnly}, "ngForOf"]; + const $e_attrs$ = [${AttributeMarker.SelectOnly}, "click"]; + + function MyComponent_div_0_Template(rf, ctx) { + if (rf & 1) { + const $s$ = $r3$.ɵgetCurrentView(); + $r3$.ɵelementStart(0, "div", $e_attrs$); + $r3$.ɵlistener("click", function MyComponent_div_0_Template_div_click_0_listener($event) { + $r3$.ɵrestoreView($s$); + const $d$ = ctx.$implicit; + const $i$ = ctx.index; + const $comp$ = $r3$.ɵnextContext(); + return $comp$._handleClick($d$, $i$); + }); + $r3$.ɵelementEnd(); + } + } + // ... + template: function MyComponent_Template(rf, ctx) { + if (rf & 1) { + $r3$.ɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", $t0_attrs$); + } + if (rf & 2) { + $r3$.ɵelementProperty(0, "ngForOf", $r3$.ɵbind(ctx._data)); + } + } + `; + + const result = compile(files, angularFiles); + + expectEmit(result.source, template, 'Incorrect template'); + }); + it('should support ngFor context variables', () => { const files = { app: { diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index cd0f9474ce..fb0af532dc 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -1431,7 +1431,8 @@ export class BindingScope implements LocalResolver { } maybeGenerateSharedContextVar(value: BindingData) { - if (value.priority === DeclarationPriority.CONTEXT) { + if (value.priority === DeclarationPriority.CONTEXT && + value.retrievalLevel < this.bindingLevel) { const sharedCtxObj = this.map.get(SHARED_CONTEXT_KEY + value.retrievalLevel); if (sharedCtxObj) { sharedCtxObj.declare = true; diff --git a/tools/material-ci/angular_material_test_blocklist.js b/tools/material-ci/angular_material_test_blocklist.js index e924cf2ff4..03ff9d394e 100644 --- a/tools/material-ci/angular_material_test_blocklist.js +++ b/tools/material-ci/angular_material_test_blocklist.js @@ -597,30 +597,6 @@ window.testBlocklist = { "error": "TypeError: Cannot read property 'getBoundingClientRect' of null", "notes": "Unknown" }, - "MatTabGroup basic behavior should change selected index on click": { - "error": "Error: Expected 0 to be 1.", - "notes": "Unknown" - }, - "MatTabGroup basic behavior should support two-way binding for selectedIndex": { - "error": "TypeError: ctx_r16151._handleClick is not a function", - "notes": "Unknown" - }, - "MatTabGroup basic behavior should fire animation done event": { - "error": "TypeError: ctx_r16547._handleClick is not a function", - "notes": "Unknown" - }, - "MatTabGroup basic behavior should emit focusChange event on click": { - "error": "Error: Expected spy handleFocus to have been called once. It was called 0 times.", - "notes": "Unknown" - }, - "MatTabGroup basic behavior should emit focusChange on arrow key navigation": { - "error": "Error: Expected spy handleFocus to have been called once. It was called 0 times.", - "notes": "Unknown" - }, - "MatTabGroup lazy loaded tabs should lazy load the second tab": { - "error": "TypeError: ctx_r17471._handleClick is not a function", - "notes": "Unknown" - }, "Dialog should set the proper animation states": { "error": "TypeError: Cannot read property 'componentInstance' of null", "notes": "FW-1059: DebugNode.query should query nodes in the logical tree"