JavaScript ngx-bootstrap typeahead with FormControl angular 2 bootstrap typeahead with ajax call,bootstrap typeahead with multiple values,

here is a simple problem I can't find a solution to. I have a typeahead directive in input which lets a user to choose a category ( category array example -> [{ id: 1as1d, name: 'some category'},...]

How to set the id value to the FormControl field (which will appear in the submitted form) and display the name on the input (which will be showed in on the input while user is choosing)? Is there a way to separate what will be in the sent form and what is being showed while using FormControl?

I could only find a way to display and set the same variable either only id or only name.

<input 
    formControlName="category"
    [formControl]="userForm.controls['category']"
    [typeahead]="categoriesObservable"
    (typeaheadLoading)="toggleLoadingCategories($event)"
    (typeaheadNoResults)="toggleNoCategoriesFound($event)"
    (typeaheadOnBlur)="categoryFieldSelected($event)"
    (typeaheadOnSelect)="categoryFieldSelected($event)"
    typeaheadOptionsLimit="7"
    typeaheadOptionField="name"
    placeholder="Choose a category"
    class="form-control"/>
Answer:1

What you want to do is use a template for the options.

Taken from the documentation at http://valor-software.com/ngx-bootstrap/#/typeahead:

<ng-template #customItemTemplate let-model="item" let-index="index">
   <h5>This is: {{model | json}} Index: {{ index }}</h5>
</ng-template>

<pre class="card card-block card-header">Model: {{selected | json}}</pre>
<input [(ngModel)]="selected"
   [typeahead]="states"
   [typeaheadItemTemplate]="customItemTemplate"
   class="form-control">

In this example the customItemTemplate is used to display the model and index but any property of the model can be used. On selection the whole object of your selection can be sent, then in the function it is sent to you can take the id out of the object and use it for anything you need.

Answer:2

You use template like in a prevous answer to choose how you want to show options in the dropdown and you use function categoryFieldSelected(v: any) to choose what happens when you select one of the options. This way the input field witll have the value of the id+name of the selected category, but the selectedCategoryCode will be the value you use when you submit the form.

private selectedCategoryCode: string = '';

categoryFieldSelected(v: any): void {
    this.selectedCategoryCode = v.item.id;
    this.form.get('category').setValue(v.item.id+' '+v.item.name);
}
Answer:3

I am trying to make a real time application. I am using NodeJS as a server and Socket.IO, to achieve my real time functionality. The problem is I am getting error as: WebSocket connection to 'wss://...

I am trying to make a real time application. I am using NodeJS as a server and Socket.IO, to achieve my real time functionality. The problem is I am getting error as: WebSocket connection to 'wss://...

  1. invalid frame header websocket
  2. invalid frame header websocket chrome
  3. invalid frame header headeru003d'' syslog-ng
  4. invalid frame header socket.io
  5. invalid frame header syslog-ng
  6. invalid frame header chrome
  7. invalid frame header signalr
  8. failed invalid frame header
  9. failed invalid frame header websocket
  10. ws invalid frame header
  11. failed invalid frame header socket.io
  12. syslog invalid frame header
  13. socket invalid frame header
  14. sockjs invalid frame header
  15. websocket invalid frame header
  16. flac invalid frame header
  17. websocket connection invalid frame header
  18. sockjs-node invalid frame header
  19. nginx websocket invalid frame header
  20. websocket error invalid frame header

I have the following express app which just renders the sample.ejs page. On that page when I press the button the attached script changes the div text to "THIS IS FROM J QUERY. I want the same thing ...

I have the following express app which just renders the sample.ejs page. On that page when I press the button the attached script changes the div text to "THIS IS FROM J QUERY. I want the same thing ...

  1. update part of html page
  2. update only part of html page

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

  1. javascript node this

I have an array ['2530491','2530491','2530491','2530492'] the 2530491 is duplicated thrice, and I want to remove a single value of 2530491 from 3 of them, so the output would be like : ['2530491','...

I have an array ['2530491','2530491','2530491','2530492'] the 2530491 is duplicated thrice, and I want to remove a single value of 2530491 from 3 of them, so the output would be like : ['2530491','...

  1. javascript remove only one class
  2. javascript remove only leading spaces
  3. javascript remove only leading whitespace
  4. javascript remove only tag
  5. javascript remove read only