I'm learning AngularJS and assuming this is possible, so what is the best way to create routes dynamically based on the results of an API call?
I have a controller which returns an array of folders:
controllers.controller('FoldersCtrl', function($scope, $http) {
$http.jsonp('https://api....=JSON_CALLBACK').then(function (shaggy){
$scope.list=shaggy.data;
});
I've seen several examples of $routeProvider
which look something like this:
app.config(function ($routeProvider) {
$routeProvider
.when('/somePath', {controller:"SomePathCtrl", templateUrl: "partials/somePath.html" })
.otherwise({redirectTo: "/homePath"})
});
But I've yet to encounter an example where the '/somePath'
is derived from the result of an API call. I'd like to do something like this:
app.config(function ($routeProvider) {
$routeProvider
.when({{shaggy.data.folder}}, {controller:"FolderCtrl", templateUrl: "partials/folder.html" })
.otherwise({redirectTo: "/homePath"})
});
Then ideally, both FolderCtrl
and partials/folder.html
would be populated with code generic enough to display the objects in each folder so some how the would have to be aware of the {{shaggy.data.folder}}
that I passed to the route. Any thoughts?
Thanks in advance.