Skip to content

Local template variable initialization to reduce code redundancy #14985

@phil294

Description

@phil294

I'm submitting a ...

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current way of using laborious variable calls
Consider this code template:

<td *ngFor="let attribute of attributes">
		<p>{{ product.productData.get(attribute.id).value }}</p>
		<p>{{ product.productData.get(attribute.id).date }}</p>
		<p>{{ product.productData.get(attribute.id).something }}</p>
</td>

That's an awful lot of repeated typing for repeated logic. It doesn't feel to me like it would make sense to create a sub-component for these two lines. So I want to suggest the introduction of local variable assignment. The above could then look like the following:

Suggested syntax

<td *ngFor="let attribute of attributes" #values="product.productData.get(attribute.id)">
		<p>{{ values.value }}</p>
		<p>{{ values.date }}</p>
		<p>{{ values.something }}</p>
</td>

I deliberately used the #x="y"-syntax, even though it is currently not meant to be used like that (and will throw an error).

  • Angular version: 2.4.9

  • Browser: all

  • Language: all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions