How to get element in nativescript?


#1

Dear sir/madam.

Thanks for your attention.
I have one problem due to developing my app using nativescript.
I used searchbar in one page.

<SearchBar #sb hint=“search” [text]=“SearchPharase” (submit)=“onSubmit(sb.text)” class=“searchbox” style=“horizontal-align:center”>

Next, I tried to remove focus from the searchbar.

@ViewChild(“sb”) SBref: ElementRef;

ngOnInit(){
this.SBref.nativeElement.android.setFoucus(false);
}

But I didn’t get my required effective.
Unfortunately, I don’t know about the reason and I decided to get your help here.
Please help me.

Thanks and regards.


#2

could you check your spelling:

this.SBref.nativeElement.android.setFoucus(false);

should be, I think,

this.SBref.nativeElement.android.setFocus(false);


#3

thanks for your attention.

I have another problem.
As I mentioned to developing nativescript app using typescript and angluar2.0.
I’m going to compose various template files for multiple screen sizes.
For example…

login.html
login.minWH320.html
login.minWH480.html
login.minWH600.html
login.minWH720.html

////login.component.ts
@Component({
selector: “my-app”,
providers:[UserService],
templateUrl:“pages/login/login.html” ,
styleUrls:[“pages/login/login-common.css”, “pages/login/login.css”]
})

is this right?

unfortunately, I don’t have android tablet and I use genymotion and phone.
I want to make different UI between tablet and smartphone.
Please let me know how can I impelement for that and how can I test?


#4

one thing at a time… did the previous solution work? If so, can you mark it as solved and open this new issue on a new thread? That will get you greater visibility. Thanks!


#5

thanks.

you mean I have to build two another apks?
I want only one apk.
Is it possible?


#6

no, I need you to have one topic on a given Forum thread, this is an administrative detail that will make helping you easier.


#7

I’m guessing the page with the searcher opens the keyboard on launch ? you can do the following to fix that

ngAfterViewInit(){
setTimeout(()=>{
this.SBref.nativeElement.dismissSoftInput();
},0);
}