gpt4 book ai didi

javascript - ngTagsInput - 设置 onTagAdding 回调

转载 作者:行者123 更新时间:2023-11-30 12:11:05 26 4
gpt4 key购买 nike

我正在尝试使用 tagsInputConfig 提供程序为 onTagAdding 回调设置默认函数。没有成功。

tagsInputConfig.setDefaults('tagsInput', {
placeholder: 'Search',
maxTags: 10,
minLength: 5,
maxLength: 40,
replaceSpacesWithDashes: false,
onTagAdding: function (x,y,z) {
debugger; // breakpoint is never called
}
});

所有其他默认选项都设置正确,除了回调。另一方面,当我将它配置为属性时,它会起作用:

<tags-input on-tag-adding="onTagAdding($tag)" ng-model="search"></tags-input>

有没有办法为这个回调设置一个默认函数?

最佳答案

您可以将范围内的任何函数定义为回调,这是一个示例

# test.html
<div ng-controller="MyCtrl">
<tags-input on-tag-adding="myFunction($tag)" ng-model="search"></tags-input>
</div>

在js文件中

angular.module('myModule').controller('MyCtrl', function($scope) {
$scope.myFunction = function($tag) {
console.log($tag);
return false;
};
});

希望对您有所帮助!

关于javascript - ngTagsInput - 设置 onTagAdding 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33785884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com