gpt4 book ai didi

javascript - AngularJS - 将 typeahead 与 ngTagsInput 结合使用

转载 作者:行者123 更新时间:2023-12-03 09:04:50 25 4
gpt4 key购买 nike

这是我的index.html

            <form ng-controller = "emailViewController">
<tags-input placeholder="To" ng-model="select" typeahead="toPerson for toPerson in to | filter:$viewValue" style="width:95%;">
</tags-input>
<br />
<input type="text" placeholder="Subject" style="width:95%;"><br />
<textarea style="width:95%;" rows="10"></textarea>
</form>

emailViewController.js

(function() {
'use strict';

var emailViewController = function (fetchDataService,$scope,$filter) {
var url = 'app/mock/emails.json';

fetchDataService.getContent(url)
.then(function(response){
$scope.emails = response.data;

$scope.to = [];

angular.forEach($scope.emails, function(key, value) {
$scope.to.push(key.to);
})

$scope.loadEmails('Primary');
});
}

angular.module('iisEmail')
.controller ('emailViewController',
['fetchDataService', '$scope','$filter', emailViewController]);
}());

Typeahead工作正常,直到我删除 input标签(它是一个属性)并添加 tags-input指示。所以,我有 <input placeholder="To" ng-model="select" typeahead="toPerson for toPerson in to | filter:$viewValue" style="width:95%;">早些时候。现在,我有<tags-input placeholder="To" ng-model="select" typeahead="toPerson for toPerson in to | filter:$viewValue" style="width:95%;">它不起作用。

我认为发生这种情况是因为 typeahead仅适用于 input tags 。有谁知道如何制作typeaheadngTagsInput 合作?

为了避免任何混淆,我想澄清一下,我知道如何使用 autocompletengTagsInput 。我的问题是专门针对我使用 typeahead 所面临的问题与 ngTagsInput .

这是一个骗子:http://plnkr.co/edit/B1aV9TLu58a2iGhpTUrN?p=preview

更新

我使用angular-tags解决了这个问题而不是ngTagsInputngTagsInput不适用于 typeahead 。选择的最佳答案很好地解释了为什么会出现这种情况。这是使用 angular-tags 解决此问题的 Plunker。 -http://plnkr.co/edit/PaG1k5N37BTOflObnN7K?p=preview

最佳答案

ngTagsInput 无法与 ui.bootstrap.typeahead 一起使用,因为它本身生成输入元素,并且 typeahead 属性最终不会出现在生成的输入元素上。

<tags-input placeholder="To" ng-model="select" typeahead="toPerson for toPerson in to | filter:$viewValue" style="width:95%;">

最终是:

<tags-input placeholder="To" ng-model="select" typeahead="toPerson for toPerson in to | filter:$viewValue" style="width:95%;" class="ng-pristine ng-untouched ng-valid ng-isolate-scope ng-valid-max-tags ng-valid-min-tags ng-valid-leftover-text" aria-autocomplete="list"
aria-expanded="false" aria-owns="typeahead-5-8574">
<div class="host" tabindex="-1" ng-click="eventHandlers.host.click()" ti-transclude-append="">
<div class="tags" ng-class="{focused: hasFocus}">
<ul class="tag-list">
<!-- ngRepeat: tag in tagList.items track by track(tag) -->
</ul>
<input class="input ng-pristine ng-untouched ng-valid" autocomplete="off" ng-model="newTag.text" ng-model-options="{getterSetter: true}" ng-keydown="eventHandlers.input.keydown($event)" ng-focus="eventHandlers.input.focus($event)" ng-blur="eventHandlers.input.blur($event)"
ng-paste="eventHandlers.input.paste($event)" ng-trim="false" ng-class="{'invalid-tag': newTag.invalid}" ng-disabled="disabled" ti-bind-attrs="{type: options.type, placeholder: options.placeholder, tabindex: options.tabindex, spellcheck: options.spellcheck}"
ti-autosize="" type="text" placeholder="To" spellcheck="true" style="width: 20px;"><span class="input" style="visibility: hidden; width: auto; white-space: pre; display: none;">To</span>
</div>
</div>
</tags-input>

ngTagsInput 似乎也没有提供实现此目的的方法。由于它提供了自己的搜索机制,因此可能不允许使用外部搜索机制。

关于javascript - AngularJS - 将 typeahead 与 ngTagsInput 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32212730/

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