1

I am building a NativeScript-Angular app which displays a link than needs to open in a new browser on both the web and mobile.

For Angular, I can use window.open("http://example.com", "_blank"); - which does not work for NativeScript.

For NativeScript I can use utilityModule.openUrl(http://example.com); where var utilityModule = require("utils/utils"); - but this does not work with Angular (and it can't resolve and tns modules).

Is there any way I can use a single method in the my component to launch the default browser on a mobile and also open a new tab on a web browser?

1 Answer 1

1

Define a Service and have two implementations of it in your code you import "service"

  • service.ts: this will have the WEB version on how to open the link.
  • service.tns.ts: this will have the nativescript version on how to open the link.
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Jose. Haven't given it a go yet but sounds like exactly what's needed.
Hi Jose, I haven't yet marked this as the answer as it seems like the .tns version of my service is not being picked up. Should this happen automatically? Or do I need to ad something else to a configuration file. The tsconfig.tns.ts already has entry "paths": { "@src/*": [ "src/*.tns.ts", "src/*.ts" ] }
The error I am getting is System.err: Error: Unexpected value '[object Object]' imported by the module 'AppModule'
Issue was obviously user error :-) I had to remove all references to utils/utils and will start that over

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.