javascript - Angularjs 和 typeahead,如何摆脱 [object Object]

标签 javascript angularjs

我有一个使用带有 uib-typeahead 的输入文本的 View 。 输入的文本是一个表单。

加载 View 时,输入文本显示“[object Object]”大约 5 秒,然后填充从远程服务器加载的数据。 从远程服务器加载数据后,一切正常。

在 View 完全加载来自服务器的数据之前,有没有办法避免这个 [object Object] 进入输入文本?

我试过 ng-cloak 但没有效果。

//标记

<div class="col-sm-9 col-lg-9" id="scrollable-dropdown-menu">
   <script type="text/ng-template" id="templatePac.html">
            <div class="col-sm-12">
               <a href>
                <span ng-bind-html="match.model.nome  | uibTypeaheadHighlight:query"></span>
                <span> - CPF:</span>
                <span ng-bind-html="match.model.cpf || 'sem cpf'"></span> 
               </a>
            </div>
   </script>
    <input type="text" ng-model="paciente"  required
    uib-typeahead="item as item.nome for item in getPacientesByName($viewValue)" 
    ng-model-options="{ updateOn: 'default blur', debounce: {'default': 500, 'blur': 0}}" 
    typeahead-editable="false" typeahead-select-on-exact="true" query="query"  typeahead-wait-ms="300"  typeahead-loading="loadingLocationsPac"   typeahead-template-url="templatePac.html" typeahead-no-results="noResultsPac" class="form-control">
    <div>
      <i ng-show="loadingLocationsPac" class="glyphicon glyphicon-refresh"></i>
      <div ng-show="noResultsPac">
        <i class="glyphicon glyphicon-remove"></i> Sem resultados
      </div>
    </div>
</div>

//js Controller

angular.module('clinang').controller('menuPacientesEvolAtendAddController',  function($scope,$state,$http) {
 $scope.paciente={primeiro_atendimento:{prescricao_adotada:{medicamentos:[]}}};
 ...
 ...

 $scope.getPacientesByName=function(val){
              return $http.get(urlBase+'/configuracao',{params:val}).then( (response)=>{
                   return response.data
               }, (erro)=>{
                      console.log(erro);
              })
        }

    }  

最佳答案

您能否修改 $scope.paciente 的初始值使其具有“nome”,根据输入中的 typeahead 值字段,以便 typeahead 可以正确解析它? 例如

$scope.paciente={nome: "", primeiro_atendimento:{prescricao_adotada:{medicamentos:[]}}};

关于javascript - Angularjs 和 typeahead,如何摆脱 [object Object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46498493/

相关文章:

javascript - 将项目附加到 JSON 对象中的列表的最佳方法?

javascript - 从 Angular 中的 ngList 中删除项目

javascript - $watch 监听器被调用一次而不改变表达式

angularjs - 如何使用 ng-style 访问当前元素

javascript - 使用 JS 抓取特定的电子邮件

javascript - 如何定期更新 VueJS 中的组件

javascript - 具有多个图表和动态图例的 Flot Chart Crosshair 插件

javascript - 使用 Web API Get() 正确格式化 JSON

javascript - Angular 替换模板中变量的字符

javascript - ZingChart 不支持 wordcloud 图表(标签图表)中的 utf 字符