How to split a string in angular 2

陌路散爱 提交于 2019-12-10 02:36:47

问题


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" , "xyz@gmail.com"].

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


回答1:


You need to use split() function.

Component

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

variable toArray will contain an array of emails.

Please check split



来源:https://stackoverflow.com/questions/43863506/how-to-split-a-string-in-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!