是否可以通过编程方式访问输入中剩余的文本?如果是,怎么办?
我只允许来自自动完成的标签(用作搜索过滤器),并且想使用剩余的文本作为附加关键字,这意味着我想知道它是否绑定(bind)到任何东西,以便我可以将它传递给搜索功能。
感谢帮助
最佳答案
这不是直接可行的,但您可以侵入该指令并使用辅助指令使其工作:
app.directive('bindInternalInputTo', function() {
return function(scope, element, attrs) {
var property = attrs.bindInternalInputTo,
input = element.find('input'),
inputScope = input.scope();
inputScope.$watch('newTag.text', function(value) {
scope[property] = value;
});
};
});
现在您可以通过执行以下操作将外部作用域中的一些变量绑定(bind)到内部输入:
<tags-input ng-model="tags" bind-internal-input-to="variable"></tags-input>
请注意,此解决方案不能保证适用于 future 版本的 ngTagsInput,因为它依赖于内部实现细节。
关于ng-tags-input - 如何访问 ng-tags-input 中的剩余文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25436267/