The following code reads via a service and shows on the web page a list of 'page' objects for a specific 'page category' (string). Using the resolve object property in $routeProvider.when(), I am able to postpone updating the view until the new value is ready. Two questions:
The code: app.js:
controllers.js:
services.js: The last pages read is stored in currentPages and its category in lastCat.
view.html
|
|||
Not exactly sure whether this would work in your code as you have $resource integration. But it may be worth to look into angular events: in html:
in controller (which defines the scope of the html above):
|
||||
The routing system for angular seems to be a bit limited.. Also, about the events triggering twice: if you setup a route do map to "a/b/c" angular automatically sets up another route, "a/b/c/" (with trailing slash) to redirect to the first (and vice versa), and both trigger events. I just test for a presence of route parameters. Regarding the limited condition of the routing sistem: there is this pull from angular, to extend it's capabilities. |
|||
You can also use the ng-show directive. Simply check whether you model is empty and display a DOM subset like so:
|
|||
You will want to use the
In that function set the Then use
To unset that variable. Complete reference here |
|||
I like the
_e |
||||
You can create a directive that will show based on a broadcast that you send before and after a service call, which you could put on $rootScope. So if you're calling a factory to handle dishing out generic POST/GET calls then right before the call you can call a function on $rootScope, such as "$rootScope.startLoading()" and when it finishes call "$rootScope.doneLoading()", where each of these methods broadcast an event for you to pick up on your directive. Then you just handle on your directive to catch the events, "scope.$on("startLoading", func(..." and have it insert/show a loading div template into the DOM and run, then also have a catch for done loading to remove/hide it. That way you can have a nice general loading overlay. |
|||
|
$routeChangeError
– Jan Aug 19 '13 at 10:15