0

I have below code to post a tags list , when I am typing a list of numbers like 3453453,345345,345345,567567676 in my tags input angular posts only one number from the list:

HTML

 <tags-input placeholder="{{placeholder}}"
                        min-length="1"
                        max-length="11"
                        ng-class="{'read-input': tags.length > 6}"
                        allowed-tags-pattern="^[0-9]+$" max-tags="6" ng-model="tags"></tags-input>


                <input type="hidden" ng-model="post.phones">

Angular code :

$scope.$watch('tags', function (tags) {
    if (angular.isArray(tags)) {
        $scope.post.phones = tags.map(function (tags) {
            return parseInt(tags.text, 10);
        });
    } else {
        $scope.post.phones = [];
    }
});
1
  • your model must be as an array Commented Feb 28, 2016 at 9:35

1 Answer 1

1

may be add model to tags-input resolve your problem.

<tags-input
ng-model="post.phones"
placeholder="{{placeholder}}"
min-length="1"
max-length="11"
ng-class="{'read-input': tags.length > 6}"
allowed-tags-pattern="^[0-9]+$"
max-tags="6"></tags-input>
Sign up to request clarification or add additional context in comments.

12 Comments

you have used ng-model twice, please fix and answer properly.
but how to fix the angular code? $scope.$watch('tags', function (tags) { if (angular.isArray(tags)) { $scope.post.phones = tags.map(function (tags) { return parseInt(tags.text, 10); }); } else { $scope.post.phones = []; } });
amirAli I think u don't need to $scope.$watch . after data entry finish in tags-input u could post your data.
I need this to remove text : from array and array just be a number list
befor posting form convert string array to number array.
|

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.