primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Templating fails when using any *ng directives

Open brian428 opened this issue 9 years ago • 9 comments

I'm submitting a ... (check one with "x")

[ X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports) Plunkr to demonstrate the bug with PrimeNG 1.1.1: https://plnkr.co/edit/BQAjYy?p=preview

Current behavior If *ngIf is used in a <template> inside <p-dataList> (and p-orderList, and probably other components that iterate over a template), the render of the initial data seems correct. However, adding new items to the list causes the template rendering to fail.

Expected behavior Template should render correctly when *ngIf is used in the template.

Minimal reproduction of the problem with instructions Plunker at https://plnkr.co/edit/BQAjYy?p=preview reproduces the issue.

  • Angular version: Plunkr uses latest from npm.

  • PrimeNG version: 1.1.1

  • Browser: all

  • Language: all

brian428 avatar Dec 22 '16 06:12 brian428

Have the same problem. Initial render works OK but when change items list it fails.

Prontsevich avatar Dec 28 '16 10:12 Prontsevich

Also when *ngIf is used in a <template> inside <p-autocomplete>

Prontsevich avatar Dec 30 '16 15:12 Prontsevich

+1

stusquared avatar Jan 02 '17 20:01 stusquared

Same at [email protected]

ilianiv avatar Jan 05 '17 12:01 ilianiv

When we reviewed the NgFor, NgIf, and NgSwitch built-in directives, we called out an oddity of the syntax: the asterisk (*) that appears before the directive names.

The * is a bit of syntactic sugar that makes it easier to read and write directives that modify HTML layout with the help of templates. NgFor, NgIf, and NgSwitch all add and remove element subtrees that are wrapped in <template> tags.

We didn't see the <template> tags because the * prefix syntax allowed us to skip those tags and focus directly on the HTML element that we are including, excluding, or repeating.

Reed more on Angular.io

The problem was in declaration of template variable in controls: @ContentChild(TemplateRef) itemTemplate: TemplateRef<any>;

For the first run everything works good, but when we try to change items collection the itemTemplate take template of NgFor, NgIf, or NgSwitch. And that's why we have broken view.

In my fix I replaced variable declaration to: @ContentChild('itemTemplate') itemTemplate: TemplateRef<any>; Autocomplete, Carousel, Chips, Datagrid, Datalist, Datascroller, Dropdown, Listbox, Orderlist and Picklist require a <template #itemTemplate> element and we'll get the correct templateRef in all these controls.

For example:

<p-dataList [value]="cars">
        <p-header>
            List of Cars
        </p-header>
        <template let-car #itemTemplate>
            {{car.brand}}
        </template>
</p-dataList>

Prontsevich avatar Jan 06 '17 14:01 Prontsevich

Great, thanks! Any idea when this will get pushed out in a release?

brian428 avatar Jan 06 '17 16:01 brian428

pTemplate is required now;

<template let-car pTemplate="item"

item name is optional but suggested to separate with other potential template types in future the component may get.

Note that this is a breaking change.

cagataycivici avatar Jan 09 '17 07:01 cagataycivici

Great! Any idea when this will get pushed out in a release?

Prontsevich avatar Jan 09 '17 08:01 Prontsevich

23rd, next week.

cagataycivici avatar Jan 18 '17 07:01 cagataycivici