In Nativescript With Angular, How Can I Get An Interface Element The Id?
I'm trying to avoid unexpected behavior in a NativeScript application. When I walk into any screen that has a search field (SearchBar) system puts the focus on the search field aut
Solution 1:
to expand on Nikolay's answer above this to use @ViewChild
add #foo to your stack layout so it looks like:
<StackLayout #foo ....
then:
@ViewChild('foo') stackLayout: ElementRef;
ngAfterViewInit() {
let yourStackLayoutInstance = this.stackLayout.nativeElement;
}
it won't get the element by ID but this is the more ng2 way of interacting with elements and keeps your code more loosely coupled to the DOM.
Solution 2:
To get element in your project you should use @ViewChild
decorator, which will help you to create new property that point at the SearchBar
. In regard to that you could review my project here and also to review this article: Building Apps with NativeScript and Angular 2
Post a Comment for "In Nativescript With Angular, How Can I Get An Interface Element The Id?"