1

I have email template where i have cc option , so for cc i want user to add email address with comma separated then push it to array $scope.notifyCtrl.cc. How i can achieve this task using angularjs 1.5 and above ? main.html

<div layout="row">
    <md-input-container flex="100">
        <label>Cc</label>
        <input ng-model="notifyCtrl.cc">
    </md-input-container>
</div>

ctrl.js

$scope.notifyCtrl = {};
$scope.notifyCtrl.cc = [];
2
  • what do you mean by with comma separated ? like this : a,b,c,@,... ? Commented May 9, 2017 at 14:04
  • @ThanhTùng [email protected],[email protected] like that Commented May 9, 2017 at 14:09

3 Answers 3

3

ngList will do exactly what you want

Text input that converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space - equivalent to ng-list=", ". You can specify a custom delimiter as the value of the ngList attribute - for example, ng-list=" | ".

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks ng-list helped to achieve the task.
1

I think you can use ng-change directive for this:

//ctrl.js
$scope.tempData = "";
$scope.func= ()=>{
    let arr = $scope.tempData.split(',');
    ...
};

//index.html
<div layout="row">
    <md-input-container flex="100">
        <label>Cc</label>
        <input ng-model="notifyCtrl.cc" ng-change="func()">
    </md-input-container>
</div>

Comments

0

You can use ngTagsInput to enter multiple string in an input separate by comma and them push all string into an array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.