0

I am creating a single page app (mobile/desktop) using AngularJS. Based on the limited knowledge I have of AngularJS, I think the routing for the apps/websites is based on urls and $location/$location.path directive is used. However, in mobile or desktop apps, there is no browser. So how does AngularJS routing work in this case if views need to be switched?

Thanks

Daan van Hulst
  • 1,426
  • 15
  • 32
AgentHunt
  • 669
  • 3
  • 11
  • 28
  • you can check screen size – Afsar Feb 11 '16 at 08:00
  • Not sure how that will help. If it's a web app, we can easily use $routeprovider to assign routes based on url. But the problem for a phone app is, there is no url or browser. – AgentHunt Feb 11 '16 at 08:05
  • I assume you will be using a wrapper to execute your scripts etc right? E.g. Phonegap/Cordova. This uses a webview to render your app, so routing still works as expected, even though it is essentially a phone app. – Matthijs Feb 11 '16 at 08:18
  • I am building this as a Universal Windows app in visual studio. So, it is targeted towards desktop and phone. – AgentHunt Feb 15 '16 at 19:52

3 Answers3

0

If you are talking about an Angular application by itself, it will always need something to be interpreted by something. Angular is written in JavaScript which means it will have to be interpreted by something which understands JavaScript. I am using the word interpreted instead of compiled, because JavaScript is not a compiled language.

But then how does something that interprets JavaScript display it on my screen you ask? For this you'll need a bit of background information.

The DOM

This is where we got to the Document Object Model DOM. From W3c:

The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. This is an overview of DOM-related materials here at W3C and around the web.

To dumb the quote above down:

you have a document (web page) which is being displayed and the DOM allows you to change this document which is being displayed.

JavaScript Engine

The link between JavaScript and the DOM is provided by an Engine. Every browser uses a JavaScript Engine. For example Chrome uses the V8 JavaScript engine. From an introduction of V8:

JavaScript is most commonly used for client-side scripting in a browser, being used to manipulate Document Object Model (DOM) objects for example. The DOM is not, however, typically provided by the JavaScript engine but instead by a browser. The same is true of V8—Google Chrome provides the DOM. V8 does however provide all the data types, operators, objects and functions specified in the ECMA standard.

How does this translate to your question?

Everything that wants to display a JavaScript application, needs to have a JavaScript Engine and a DOM. This could be a browser like Chrome, but could also be any other application.

A simple explanation of what a router does, is change the DOM to display different "documents". So plainly said: any application, be it a mobile or desktop application, which has a DOM understands how to use Angular's routing system.

Community
  • 1
  • 1
Daan van Hulst
  • 1,426
  • 15
  • 32
0

Outside the browser means only application you are speaking about?. angular is tied to HTML pages in general. So its a framework for managing(not exactly appropriate word) the html pages to make them into Single Page Applications so that browser does not need to reload the entire the web application on request of a single page, it helps to invoke the html pages into the main html pages, this makes the application not to reload the entire, but to make available requested pages. this is where the routing comes.

0

Angular will work just fine there. In fact there is an Ionic project that is based on top of angular. E.g. if you are using Cordova, then the app is rendered inside a browser (or at least with the browser engine). So as far as I know it will behave exactly the same way with the exception of user not being able to type in URL or click back/forward.

Moreover I build an application for browser where I do not user URL as much as possible. E.g. I transition only between states and don't have direct url's in my application at all. Of course I need to support to the extent that a user can type in the url, but the ui-router does that on it's own if you map routes properly. But it seems much more beneficial not to rely on the urls at all for SPA (for internal stuff as you still have the edit url as I said before).

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207