2016-02-28 49 views
0

我有以下代碼發佈標籤列表,當我在我的標籤中輸入像3453453,345345,345345,567567676這樣的數字列表時input角度帖子僅列出一個數字:如何通過一個輸入角度發佈數組

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"> 

角碼:

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

您的模型必須作爲數組 –

+0

我該如何解決它? – Amirali

回答

1

可添加模型標記輸入解決您的問題。

<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> 
+1

您已經使用了ng-model兩次,請修復並正確回答。 –

+0

但如何解決角碼? $ scope。$ watch('tags',function(tags)if(angular.isArray(tags)){scope.post.phones = tags.map(function(tags){ return parseInt(tags。文本,10); });} 其他{$ scope.post.phones = [];} });' – Amirali

+0

amirAli我覺得你並不需要$ $範圍的手錶。數據錄入完成後,標籤輸入您可以發佈您的數據。 –