UI Bootstrap Typeahead未显示返回async的值

时间:2015-04-10 20:14:03

标签: angularjs angular-ui angular-ui-typeahead

我正在尝试使用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">

控制器

$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 : "";
  };

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);
  });
};

响应

[{ _id: 5525662b74100eb40f13ce00,
  name: 'test 2',
  description: 'Gdoc 02.02.00-00',
  __v: 0,
  services: 
   [ { name: 'Alfresco',
       context: '/alfresco',
       parameterURL: 'prmGdocServiceUrl',
       _id: 5525662b74100eb40f13ce03 },
     { name: 'ri-rest',
       context: '/iserver',
       parameterURL: 'prmUrlIntegrationServer',
       _id: 5525662b74100eb40f13ce02 },
     { name: 'ldap',
       parameterURL: 'prmLdapUrl',
       parameterUser: 'prmLdapPrincipal',
       parameterPassword: 'prmLdapPassword',
       _id: 5525662b74100eb40f13ce01 } ],
  tables: 
   [ { _id: 5525662b74100eb40f13ce06, name: 'esegsistema' },
     { _id: 5525662b74100eb40f13ce05, name: 'esegusuario' },
     { _id: 5525662b74100eb40f13ce04, name: 'XPTO' } ],
  parameters: 
   [ { name: 'prmUrlBaseServidorHTTP',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce0e },
     { name: 'prmTamanhoMaximoArquivo',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce0d },
     { name: 'prmGdocServiceUrl',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce0c },
     { name: 'prmLdapUrl',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce0b },
     { name: 'prmLdapPrincipal',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce0a },
     { name: 'prmLdapPassword',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce09 },
     { name: 'prmDomainSufix',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce08 },
     { name: 'xxxxx',
       systemCode: '314',
       _id: 5525662b74100eb40f13ce07 } ] }]

1 个答案:

答案 0 :(得分:5)

我发现了问题,我正在使用https://github.com/McNull/angular-block-ui并且它与组件冲突。

解决方案:我从angular blockui创建了一个requestFilter,不阻止将组件发送到API的请求。