thanks On 07/07/2016, Sander Elias <[email protected]> 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; > } > } > > working in plunk <http://plnkr.co/edit/jmZkzqxsAi55LsTCvTkV?p=preview> > > This works because the myVar is actually an object (to be precise, it's a > direct reference to the <span> element in the DOM) , and as in JS objects > are passed by reference, you can add/modify any proerty you like in your > controllers function. > > Hope this clarifies it a bit, > regards > Sander > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. >
-- [email protected] [email protected] [email protected] 0xC840F256B0F0FF9069E918d060063057AAaA6b36 -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
