Search code examples
angulartypescriptangular7

Concatenate in Angular HTML Input Variables


How do I concatenate strings in Angular HTML Input? The following is creating dropdown. What we want is have txtField be concatenation of addressCode + ' ' + addressDescription, trying placing into input, did not work. Looking for way in html first, before trying in angular typescript if possible.

Original:

<app-drop-down 
  [listItems]="'addressList'"
  [txtField]="'addressCode'"
  [txtValue]="'addressId'"
</app-drop-down>

Attempt

<app-drop-down 
  [listItems]="'addressList'"
  [txtField]="'addressCode' + 'addressDescription'"
  [txtValue]="'addressId'"
</app-drop-down>

Solution

  • You can try like this -

    <app-drop-down 
      [listItems]="addressList"
      txtField="{{addressCode + addressDescription}}"
      [txtValue]="addressId"
    </app-drop-down>
    

    But following way also should work , as you mentioned in your question.

    <app-drop-down 
      [listItems]="addressList"
      [txtField]="addressCode + addressDescription"
      [txtValue]="addressId"
    </app-drop-down>
    

    Here is the demo - https://stackblitz.com/edit/angular-59242999 Hope this helps, Let me know still if it does not work for you.