fix(ivy): correctly support ngProjectAs
on templates (#34200)
Prior to this commit, if a template (for example, generated using structural directive such as *ngIf) contains `ngProjectAs` attribute, it was not included into attributes array in generated code and as a result, these templates were not matched at runtime during content projection. This commit adds the logic to append `ngProjectAs` values into corresponding element's attribute arrays, so content projection works as expected. PR Close #34200
This commit is contained in:

committed by
Miško Hevery

parent
60b13d9948
commit
c50faa97ca
@ -1510,6 +1510,51 @@ describe('compiler compliance', () => {
|
||||
result.source, SimpleComponentDefinition, 'Incorrect SimpleComponent definition');
|
||||
});
|
||||
|
||||
it('should include parsed ngProjectAs selectors into template attrs', () => {
|
||||
const files = {
|
||||
app: {
|
||||
'spec.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: '<div *ngIf="show" ngProjectAs=".someclass"></div>'
|
||||
})
|
||||
export class MyApp {
|
||||
show = true;
|
||||
}
|
||||
`
|
||||
}
|
||||
};
|
||||
|
||||
const SimpleComponentDefinition = `
|
||||
MyApp.ɵcmp = i0.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [
|
||||
["my-app"]
|
||||
],
|
||||
decls: 1,
|
||||
vars: 1,
|
||||
consts: [
|
||||
["ngProjectAs", ".someclass", ${AttributeMarker.Template}, "ngIf", ${AttributeMarker.ProjectAs}, ["", 8, "someclass"]],
|
||||
["ngProjectAs", ".someclass", ${AttributeMarker.ProjectAs}, ["", 8, "someclass"]]
|
||||
],
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
i0.ɵɵtemplate(0, MyApp_div_0_Template, 1, 0, "div", 0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
i0.ɵɵproperty("ngIf", ctx.show);
|
||||
}
|
||||
},
|
||||
encapsulation: 2
|
||||
});
|
||||
`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
expectEmit(result.source, SimpleComponentDefinition, 'Incorrect MyApp definition');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('queries', () => {
|
||||
|
Reference in New Issue
Block a user