bitcodr
bitcodr

Reputation: 1454

How to post array by one input angular

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 = [];
    }
});

Upvotes: 0

Views: 83

Answers (1)

Hadi
Hadi

Reputation: 17289

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>

Upvotes: 1

Related Questions