我在這個指令中有一些問題;第一個是我看不到列表中的任何項目。然後有時它說ngRepeat有重複的值,然後即使我能夠看到我不能選擇它並將其放在輸入上!怎麼可能?這裏有一個plunkerng-tags-input無法從自動完成中選擇一個選項
http://plnkr.co/edit/vTwOqcN4pm3FgKLYlLu9?p=preview
順便說一句,這是HTML代碼的一部分:
<body ng-controller="MainCtrl">
<tags-input ng-model="tags"add-from-autocomplete-only="true">
<auto-complete min-length="1"
source="loadTags($query)"
template="my-custom-template"></auto-complete>
</tags-input>
<p>Model: {{tags}}</p>
<script type="text/ng-template" id="my-custom-template">
<div class="right-panel>
<span ng-bind-html="$highlight($getDisplayText())"></span>
<h1 style="font-size: 15px!important" class="uk-margin-remove">
{{data.name}}
</h1>
</div>
</script>
</body>
這裏的角:
var app = angular.module('plunker', ['ngTagsInput']);
app.controller('MainCtrl', function($scope, $http) {
$scope.tags = [];
$scope.loadTags = function(query) {
return $http.get('tags.json', {
cache: true
}).then(function(data) {
$scope.names = data.data.data;
return $scope.names;
});
};
});
所以這個指令只適用於json中的「text」字段? –
您可以通過在標記輸入指令中將display-property屬性設置爲display-property =「name」來覆蓋該屬性。 – GPicazo
雖然你在這裏,你也應該設置key-property =「id」,因爲它也默認爲文本。 keyProperty是控件用於明確識別不同項目的內容。 – GPicazo