Inspired from Jason Watmore's AngularJS example project, decided to tryout stateproviders in it. And it became successful. The next attempt was to try ocLazyLoad and that too worked while providing the configurations in app.config. Then tried to load the state config's from a json file. The below tutorials helped in understanding the concepts.
AngularJS - UI-router - How to configure dynamic views
Dynamic ui-router with ocLazyLoad using multiple modules in resolve
But couldn't find success. Please check the below plunker link and help in knowing the mistake that i might have done.
http://plnkr.co/edit/eyantFVBs8e1L68gWzSi
(function () {
'use strict';
var $urlRouterProviderRef = null,
$stateProviderRef = null
angular
.module('app', ['ui.router', 'ngCookies', 'oc.lazyLoad'])
.config(config)
.run(run);
config.$inject = ['$stateProvider', '$urlRouterProvider', '$ocLazyLoadProvider', '$locationProvider'];
function config($stateProvider, $urlRouterProvider, $ocLazyLoadProvider, $locationProvider) {
$urlRouterProviderRef = $urlRouterProvider;
$locationProvider.html5Mode(false);
$stateProviderRef = $stateProvider;
}
run.$inject = ['$state', '$rootScope', '$location', '$cookieStore', '$http', '$ocLazyLoad'];
function run($state, $rootScope, $location, $cookieStore, $http, $ocLazyLoad) {
$http.get("route-config.json")
.success(function (data) {
angular.forEach(data, function (value, key) {
var state = {
"url": value.url,
"parent": value.parent,
"abstract": value.abstract,
"controller":value.controller,
"templateUrl": value.templateUrl,
"resolve": {}
};
state.resolve[value.dependencies.module] = function ($ocLazyLoad) {
return $ocLazyLoad.load(result)
};
$stateProviderRef.state(value.name, state);
});
$state.go("login");
});
}
})();
Below is the JSON i'm trying to load
[
{
"name": "login",
"url": "/login",
"abstract": "",
"parent": "",
"controller": "LoginController as vm",
"templateUrl": "login/login.view.html",
"resolve": {},
"dependencies": {
"module": "login",
"files": [
"login/login.controller.js",
"app-services/authentication.service.js",
"app-services/flash.service.js",
"app-services/user.service.local-storage.js"
]
}
}
]