Building an Angular application, I am a fan of using an ng controller and custom directives to structure the application, for example:
<nav ng-controller="NavController"></nav> <date-picker></date-picker>
I like these templates because they are declarative and very easy to follow - you know exactly where to look for support logic.
On the other hand, using ng-view or even the ui-router plugin (in my opinion) abstracts some functions and makes them difficult to read.
However, my preferred pattern gives me a problem when it comes to responding to changing URLs in an application logically. I would like each part of the user interface to respond appropriately to changes to the URL, but I don't know where to put the code. I suggested that I have two options:
- Respond to $ location changes separately in each controller or directive
- Encapsulate this in another class or service that is responsible for listening for URL changes.
I canโt figure out how to do this.
Option one gives me full control, but I can't use the ng-route parsing options, etc. I really need to collapse on my own when it comes to checking URL changes.
With the second option, I cannot refer to any of my controllers, because they are already declared!
In a broader sense, my concern is not to find a solution to this right away, that I should think about things wrong. Is this fundamentally wrong?
EDIT: For the avoidance of doubt, I talk a lot about SPA, and more specifically, this is what I'm trying to do:
<nav ng-controller="NavController"></nav> <div ng-controller="VideoController"></div> <div ng-controller="CommentController" ng-show="Active"></div>
Now suppose I go to: "/ video /: key /" - I want the VideoController to pick up the video key and do what it needs to download the video. I want the NavController to highlight which menu item is active, etc.
If I go to "/ video /: videokey / comment" - I want the VideoController to download the video, and the NavController to highlight what is active, and the CommentController to load comments / appearances in the video, etc.
I have no head for this idea - an answer to changing URLs in two controllers, each of which is responsible for a separate part of the user interface in a single-page application.