Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays JSON对象的angular 4形式数组_Arrays_Angular_Object_Angular Reactive Forms_Typeahead - Fatal编程技术网

Arrays JSON对象的angular 4形式数组

Arrays JSON对象的angular 4形式数组,arrays,angular,object,angular-reactive-forms,typeahead,Arrays,Angular,Object,Angular Reactive Forms,Typeahead,我有一个表单,它有一个输入字段,该字段采用预先输入的格式。我从API调用中获得一个JSON对象数组: allPeople = [{"id":1,"first_name":"Abba","last_name":"Lee","current_position":"Travel Expert"}, {"id":2,"first_name":"Abbey","last_name":"Joe","current_position":"water keeper"}] 但是当我开始打字时,我得到的是

我有一个表单,它有一个输入字段,该字段采用预先输入的格式。我从API调用中获得一个JSON对象数组:

allPeople = [{"id":1,"first_name":"Abba","last_name":"Lee","current_position":"Travel Expert"}, {"id":2,"first_name":"Abbey","last_name":"Joe","current_position":"water keeper"}]    
但是当我开始打字时,我得到的是
[object object]

这就是我现在拥有的:

<input formControlName="person" [typeahead]="allPeople" [typeaheadOptionsLimit]="10" [typeaheadMinLength]="0" type="text">   

当我开始键入时,如何获取输入以显示/建议我的名字和姓氏?

您的数组是自定义数组,因此您需要指定需要在打字机中显示的键

<input [(ngModel)]="customSelected"
       [typeahead]="allPeople"
       typeaheadOptionField="first_name"
       class="form-control">


您需要使用
typeaheadOptionField
,在这里您需要给出key name where is value,因此在这里您必须使用
first\u name

您正在使用哪个typeahead库?谢谢,它正在为first name工作。有可能同时获得名字和姓氏吗?我想你不可能在全名键中合并名字和姓氏,并在TypeHeadheads中显示全名键。谢谢你的帮助。!
Uncaught Error: Template parse errors:
Parser Error: Unexpected token 'as' at column 5 in [inf as inf.first_name for inf in allPeople | filter:{first_name:$viewValue}] in ...   
<input [(ngModel)]="customSelected"
       [typeahead]="allPeople"
       typeaheadOptionField="first_name"
       class="form-control">