Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ivy): ngtsc should correctly bind to context in nested template w… #28982

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: \`
<div *ngFor="let d of _data; let i = index" (click)="_handleClick(d, i)"></div>
\`
})
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: {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/src/render3/view/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions tools/material-ci/angular_material_test_blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,30 +665,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"
Expand Down