I'm trying to load states dynamically from a JSON file using ui-router-extras
. The JSON file looks like the following:
[
{
"name": "app",
"url": "/app",
"abstract": "true",
"resolve": "helper.resolveFor('fastclick', 'modernizr', 'icons')"
},
{
"name": "login",
"url": "/login",
"title": "User Login",
"templateUrl": "",
"redirectToLogin": "true"
},
{
"name": "dashboard",
"url": "/dashboard",
"title": "Dashboard",
"templateUrl": "helper.basepath('dashboard.html')",
"resolve": "helper.resolveFor('flot-chart', 'flot-chart-plugins', 'weather-icons')"
}
]
The following is the routes config file:
(function () {
'use strict';
angular
.module('app.routes')
.config(routesConfig);
routesConfig.$inject = ['$stateProvider', '$locationProvider', '$urlRouterProvider', 'RouteHelpersProvider', '$stateProvider', '$futureStateProvider'];
function routesConfig($stateProvider, $locationProvider, $urlRouterProvider, helper, $sp, $fsp) {
$locationProvider.html5Mode(false);
var futureStateResolve = function($http) {
return $http.get("states.json").then(function (response) {
console.log(response.data);
angular.forEach(response.data, function (state) {
$sp.state(state);
})
})
}
$fsp.addResolve(futureStateResolve);
// defaults to dashboard
$urlRouterProvider.otherwise('/app/login');
}
})();
The /login
state works ok, but the others don't work and give the error 'invocables must be object'. I think this is because helper.basepath()
and helper.resolveFor()
functions are not working, as they are coming as strings from the JSON.
What should I do?