I am trying to implement ngTagsInput in which I want to implement auto search for email. for that I write below code. but it not display auto search result
我正在尝试实现ngTagsInput,我想在其中实现自动搜索电子邮件。为此我写下面的代码。但它不显示自动搜索结果
HTML :
<tags-input ng-model="compose.receiver"
add-from-autocomplete-only="true"
min-length="1">
<auto-complete source="loadReceiver($query)"
min-length="0"
debounce-delay="0"
max-results-to-show="10"
loadOnEmpty="true">
</auto-complete>
</tags-input>
Controller :
$scope.loadReceiver = function(query){
return AdminInbox.loadReceiver(query);
}
Service :
angular.module('inboxes').factory('AdminInbox', ['$http','$q',
function($http,$q) {
return {
loadReceiver: function(query) {
console.log(query);
var deferred = $q.defer();
var receiver = $http.get('mailreceiver/'+query);
console.log(receiver);
return deferred.promise;
}
}
}
]);
and I successfully get response in below format:
我成功地得到以下格式的回复:
[{_id: "5579c9a4f3d71f8c2a4f1e3d" email: "abc@gmail.com"},
{_id: "557f2cd3a571f9a41e4168f2" email: "xyz@gmail.com"}]
1 个解决方案
#1
1
Have a valid JSON and set the display-property
and it works!
有一个有效的JSON并设置display-property,它的工作原理!
angular.module('app', ['ngTagsInput'])
.run(function($rootScope) {
$rootScope.source = [{
_id: "5579c9a4f3d71f8c2a4f1e3d",
email: "abc@gmail.com"
}, {
_id: "557f2cd3a571f9a41e4168f2",
email: "xyz@gmail.com"
}];
$rootScope.compose = {
receiver: []
};
});
<link rel="stylesheet" href="http://mbenford.github.io/ngTagsInput/css/ng-tags-input.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.3.0/ng-tags-input.js"></script>
<div ng-app="app">
<tags-input ng-model="compose.receiver" display-property="email" add-from-autocomplete-only="true" min-length="1">
<auto-complete source="source" min-length="0" debounce-delay="0" max-results-to-show="10" loadOnEmpty="true" displayProperty="email">
</auto-complete>
</tags-input>
</div>
#1
1
Have a valid JSON and set the display-property
and it works!
有一个有效的JSON并设置display-property,它的工作原理!
angular.module('app', ['ngTagsInput'])
.run(function($rootScope) {
$rootScope.source = [{
_id: "5579c9a4f3d71f8c2a4f1e3d",
email: "abc@gmail.com"
}, {
_id: "557f2cd3a571f9a41e4168f2",
email: "xyz@gmail.com"
}];
$rootScope.compose = {
receiver: []
};
});
<link rel="stylesheet" href="http://mbenford.github.io/ngTagsInput/css/ng-tags-input.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.3.0/ng-tags-input.js"></script>
<div ng-app="app">
<tags-input ng-model="compose.receiver" display-property="email" add-from-autocomplete-only="true" min-length="1">
<auto-complete source="source" min-length="0" debounce-delay="0" max-results-to-show="10" loadOnEmpty="true" displayProperty="email">
</auto-complete>
</tags-input>
</div>