Studying the ion-searchbar code I see that it does reference its input element with #searchbarInput and tried to reference it with @ViewChild('searchbarInput') input; unsuccessfully too.
I have to master Angular 2 better, I know
Any thoughts please?
searchbarInput is documented as private, so the framework doesn’t want you accessing it directly. Is there no way to achieve what you are really trying to do using public properties?
I don’t know what is public on that directive, nor how to manipulate it correctly either.
I need the input element to pass it to google.maps.places.Autocomplete(input: HTMLInputElement)
I don’t think the API let me manipulate it as it seems:
Yeah, that does seem like something impossible to do with the public API, so might have to go off reservation here. OTHER PEOPLE READING THIS THREAD: DON’T DO THIS SORT OF STUFF UNTIL YOU HAVE EXHAUSTED ALL OTHER OPTIONS.
<ion-searchbar #searchbar></ion-searchbar>
export class MyPage {
@ViewChild('searchbar') searchbar:Searchbar;
ionViewLoaded():void {
let elem = this.searchbar._searchbarInput.nativeElement;
google.maps.places.Autocomplete(elem);
}
}
If you’re still getting undefined, there is some ancillary problem, because that works for me on a scratch project.
Error TS2341: Property '_searchbarInput' is private
and only accessible within class 'Searchbar'.
Could you try to implement it in a Modal page please?
I’m getting the undefined there, and now searching for some method on the ViewController to manipulate childs!
Well, I’ve seen build issues with Node 6, and the solution was to downgrade to 5.7…
Maybe the transpiled code can differ with some base libraries versions
Can you try it from my end and paste my code into a newly minted project? I used the tabs starter and put that popModal() function in the home page with a button to trigger it like this:
<button (click)="popModal()">pop modal</button>
If that doesn’t work, then it is an environmental thing. If it does, then it’s something else unusual about the rest of your project.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
cleaned up the node_modules folder and installed again:
sudo rm -Rf node_modules/
sudo npm install
and now I get the INPUT element
Node Version: v6.2.2
Thank you very very much @rapropos!!
Now I’m getting issues with the output of the build process hehehe,
but it runs on my phone, awesome!
now have to figure out if the Google Places autocompleter can work with ion-searchbar or not
You’re welcome!
odd enough I get undefined on the #searchbar viewchild
I opened a request to the SearchBar API to let us access the Input Element but Angular already allowed us to get it! details here: https://github.com/driftyco/ionic/issues/7223