Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeahead doesn't work with [formControl] #1595

Closed
Andikki opened this issue Feb 2, 2017 · 4 comments
Closed

typeahead doesn't work with [formControl] #1595

Andikki opened this issue Feb 2, 2017 · 4 comments

Comments

@Andikki
Copy link

Andikki commented Feb 2, 2017

When using reactive forms, it is possible to bind typeahead's value to a formGroup's control with formControlName attribute, but not to a standalone control with [formControl] attribute. If you attempt to set [formControl] attribute you get an error:

Can't bind to 'typeahead' since it isn't a known property of 'input'.
@valorkin
Copy link
Member

valorkin commented Feb 2, 2017

it should be possible https://github.com/valor-software/ng2-bootstrap/blob/development/src/typeahead/typeahead.directive.ts#L23
are you sure you have imported TypeaheadModule.forRoot() like described in docs?

@Andikki
Copy link
Author

Andikki commented Feb 2, 2017

I'm sure. I just confirmed it by creating a fresh angular-cli project. Installed bootstrap and ng2-bootstrap.

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { TypeaheadModule } from 'ng2-bootstrap/typeahead';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    HttpModule,
    TypeaheadModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  public myControl: FormControl = new FormControl();
  public myForm: FormGroup = new FormGroup({ 'myControl': this.myControl });
  public myOptions: string[] = ['a', 'b', 'c'];
}

app.component.html

<div>
  <input [formControl]="myControl" [typeahead]="myOptions" typeaheadOptionsLimit="7" typeaheadMinLength="0" placeholder="Typeahead inside a form"
    class="form-control">
</div>
<!--<form [formGroup]="myForm">
  <input formControlName="myControl" [typeahead]="myOptions" typeaheadOptionsLimit="7" typeaheadMinLength="0" placeholder="Typeahead inside a form"
    class="form-control">
</form>-->

This gives the error:
Can't bind to 'typeahead' since it isn't a known property of 'input'.
However, if you delete the typeahead input and uncomment the form, it works just fine.

Is that line of yours missing the [typeahead][formControl] entry?

@valorkin
Copy link
Member

valorkin commented Feb 3, 2017

please try v1.3.3

@Andikki
Copy link
Author

Andikki commented Feb 3, 2017

Fixed. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants