我用的是md芯片。现在我想把角色限制为10。
我尝试了md-maxlength,一个custome指令来限制字符,但是它都在文本区域中工作,而不是在芯片中输入。
发布于 2016-08-29 05:40:24
芯片极限
限制您可以添加到“芯片”模型中的芯片数量:
<md-chips ng-model="myItems" placeholder="Add an item" md-max-chips="5">
</md-chips>演示:https://jsfiddle.net/suunyz3e/290/
您不能在该输入中添加超过5个芯片。
不幸的是,对于md-chips指令几乎没有验证控制:
来自(AngularJS材料)
验证
字符芯片限制
如果你追求的是一个字符限制,你可以这样做:
<md-chips ng-model="myItems" placeholder="Add an item" md-max-chips="5" md-on-add="validateChip($chip)">
</md-chips>主计长:
angular.module('sandbox', ['ngMaterial']).controller('testCtrl', function($scope) {
$scope.myItems = [];
$scope.validateChip = validateChip;
var characterLimit = 10;
function validateChip($chip) {
if (!$chip) return;
// check if the current string length is greater than or equal to a character limit.
if ($chip.length >= characterLimit) {
alert('whooaaa, you breached the limit yo!');
// remove the last added item.
$scope.myItems.pop();
}
}
});https://stackoverflow.com/questions/39198798
复制相似问题