I have this array called myArray in my Angular 2 component class:
@Component({
templateUrl: 'my.component.html'
})
export class MyComponent {
private myArray: Array<string>;
...
}
In my.component.html I have a single input element:
<input placeholder='write some tags' value=''>
What I want is to have the string elements of myArray inserted into the value attribute of the input element. The strings should be comma separated. Something like:
<input placeholder='write some tags' value='apple, orange, banana'>
I tried:
<input name='user-tag' placeholder='write some tags' value='*ngFor="let e of myArray"{{e}}'>
But that produced an error.
How can I do this?
No need to use *ngFor
, try using Array.join().
<input name='user-tag' placeholder='write some tags' value='{{ myArray.join(', ') }}'>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With