Alright, I think I finally figured it out...
Let me give you a little background first:
I needed to integrate Angular with Node Express and use Jade to process my partials.
Here's what you need to do...
(first, drink some beer and spend more than 20 hours on it!!!)...
When setting up your module, make sure to save the $routeProvider
globally:
// app.js:
var routeProvider
, app = angular.module('Isomorph', ['ngResource']).config(function($routeProvider){
routeProvider = $routeProvider;
$routeProvider
.when('/', {templateUrl: '/login', controller: 'AppCtrl'})
// More route configurations here
.otherwise({redirectTo: '/login'});
});
// ctrls.js
...
app.controller('EditTaskCtrl', function($scope, $routeParams, $location, $http){
var idParam = $routeParams.id;
routeProvider.when('/tasks/:id/edit/', {templateUrl: '/tasks/' + idParam + '/edit'});
$location.path('/tasks/' + idParam + '/edit/');
});
...
That might be more information than necessary...
Essentially, store your Module's $routeProvider
variable globally as routeProvider
so that Controllers can access it.
Then simply use routeProvider
to create a NEW route (you cannot 'RESET a route' or 'REpromise'; you must create a new one), adding a slash (/) at the end for semantic consistency.
In the Controller, set the templateUrl
to the desired view.
Avoid including the controller
property in the .when()
object to prevent an infinite request loop.
Finally (still in the Controller), use $location.path()
to redirect to the newly created route.
If you're curious about integrating an Angular app with an Express app, feel free to clone my repository here: https://github.com/cScarlson/isomorph.
This approach also allows you to maintain AngularJS Bidirectional Data-Bindings if you intend to bind your HTML to your database using WebSockets; otherwise, without this method, Angular data-bindings will just display {{model.param}}
.
If you decide to clone it now, ensure you have mongoDB installed on your machine to run it.
I hope this resolves your issue!
Cody
And remember, don't drink your bathwater.