On 07/07/2016, Sander Elias <
sande...@gmail.com> wrote:
> Hi Apurv.
>
> The #xxx assigns the element that it is on to a local variable. That means
> it is already an assignment, and you can't reassign it. Setting local
> variables is (for now) prohibited in template syntax.
> That does not mean you are out of luck. However keep in mind that this is a
>
> bad practice, and should be used with extreme care. (the downside is hard
> to maintain and tightly coupled code!) You are better off creating a new
> component that takes the value as an parameter, and handles it from there.
>
> import { Component } from '@angular/core';
>
> @Component({
> selector: 'my-app',
> template: `
> <li *ngFor="let x of y">
> <span #myVar>{{x}}-{{read(x,myVar)}} {{myVar|json}}</span>
> </li>
> `
> })
> export class AppComponent {
> y = [1,2,3];
> read(x,ref) {
> console.log(ref)
> ref.value = +x*2
> return +x*2;
> }
> }
>