Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string in angular 2

I have an email sending scenario in which there is an input box of 'To'(whom you want to send a message).

app.html

 <input type="text" class="form-control" [(ngModel)]="email.Tos"> 

Now I want that when a user input the multiple emailId in input box by comma separated, then in my model, 'Tos' value should bind in an Array of string. Like : ["abc@gmail,com" , "[email protected]"].

Now, please tell me how to split the input box value as per my requirement.

like image 487
Er Vipin Sharma Avatar asked May 09 '17 07:05

Er Vipin Sharma


1 Answers

You need to use split() function.

Component

let toArray =  this.email.Tos.split(",");

variable toArray will contain an array of emails.

Please check split

like image 121
Jayakrishnan Avatar answered Oct 20 '22 21:10

Jayakrishnan