我正在尝试使用UI Bootstrap Typeahead进行自动完成搜索,以从数据库中选择数据.
我的服务在我的响应中返回数据,但数据未在组件中列出.
当我在组件代码中放置断点时,列表就在那里,当我继续调试时,列表会显示,但如果它没有断点运行,则不会显示列表.
HTML
<input id="inputInstalation"
ng-model="profile.instalation"
typeahead-editable="false"
typeahead="installation as installation.name for installation in searchInstallation($viewValue)"
typeahead-input-formatter="formatLabel($model)"
ng-required="true">
Run Code Online (Sandbox Code Playgroud)
调节器
$scope.searchInstallation = function(text){
return $http.get('/api/installations/name/' + text).then(function(response){
return response.data;
});
};
$scope.formatLabel = function(model){
return model ? model.name : "";
};
Run Code Online (Sandbox Code Playgroud)
API NodeJS - DB Mongo
exports.findByName = function(req, res){
var connection = getConnection();
var Installation = getInstallationModel(connection);
Installation.find({name: new RegExp(req.params.name, "i")}, function (err, result) {
connection.close();
if(err) throw err;
res.json(result);
});
};
Run Code Online (Sandbox Code Playgroud)
响应
[{ _id: 5525662b74100eb40f13ce00,
name: 'test 2', …Run Code Online (Sandbox Code Playgroud)