Home > Mobile >  ngfor with li : how to trigger update call and send the value to component
ngfor with li : how to trigger update call and send the value to component

Time:11-22

How do I send 'countryCode.Display' value with updateCountryCode() call.

<div >
     <button  type="button" data-toggle="dropdown">{{ SelectedCountryCode }}</button>
        <ul >
            <li *ngFor="let countryCode of AllEuCountryCodeValues"><a (click)="updateCountryCode('countryCode.Display')">{{countryCode.Display}}</a></li>
        </ul>
</div>

CodePudding user response:

You just need to pass the reference to the object in, not a string.

<li *ngFor="let countryCode of AllEuCountryCodeValues">
  <a (click)="updateCountryCode(countryCode.Display)">{{countryCode.Display}}</a>
</li>

updateCountryCode(countryCode.Display) vs updateCountryCode('countryCode.Display'), the second option passes a string, the first one whatever the value of the object is.

  • Related