如何以角度 2 分割字符串 [英] How to split a string in angular 2
本文介绍了如何以角度 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">
现在我希望当用户在输入框中输入多个 emailId 时以逗号分隔,然后在我的模型中,'Tos' 值应该绑定在一个字符串数组中.喜欢: ["abc@gmail,com" , "xyz@gmail.com"].
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.
推荐答案
需要使用split()函数.
You need to use split() function.
组件
let toArray = this.email.Tos.split(",");
变量 toArray 将包含一组电子邮件.
variable toArray will contain an array of emails.
请查看split
这篇关于如何以角度 2 分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文