我有下面的代码来发布标签列表,当我在标签中输入诸如 3453453,345345,345345,567567676 之类的数字列表时,input
Angular 仅发布列表中的一个数字:
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 代码:
$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 = [];
}
});
最佳答案
可以将模型添加到标签输入来解决您的问题。
<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>
关于javascript - 如何通过一个输入 Angular 发布数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35680808/