sengirab / ngAutocomplete

Light-weight autocomplete component for Angular.
MIT License
52 stars 24 forks source link

Cannot use SelectItem inside NgActiveModal (Bootstrap) #18

Closed famu1hundred closed 6 years ago

famu1hundred commented 6 years ago

When autocomplete is inside a NgActiveModal, I am unable to use the SelectItem to set the default option. The completer is never initialized and I see the following error in the console

image

@ViewChild(NgAutocompleteComponent) public offerType: NgAutocompleteComponent; public offerTypeOpts = [ CreateNewAutocompleteGroup( 'Select', 'offerType', [ {title: 'Standalone', id: 'Standalone'}, {title: 'ABN', id: 'ABN'} ], {titleKey: 'title', childrenKey: null }, '', false ), ];

this.offerType.SelectItem('offerType', 'Standalone');

I have tried putting the last line of code into ngOnInit, ngAfterContentInit, & ngAfterViewInit. Even when I wrote a custom function to check if the element was visible first, then run the SelectItem...it still throws the error

famu1hundred commented 6 years ago

Nvm this was because I had multiple ngautocomplete components on the page and only 1 ViewChild defined. It appears to work now