The AngularJS application uses the ui-router. There are two types of pages:
- Routes specified explicitly in routes.js
- Routes derived dynamically on demand
When the page loads the application makes a request for data (type, variables). How to load a template and the controller of the page based on its type?
/**
There is an option with this routing, but then it will not work the other routed to specified explicitly
*/
/* routes.js */
// definition of "page" state
/* PageController.js */
// getting type of page
$scope.type = res.data.type;
/* page.jade */
div(ng-if=«page.type == ‘index’»)
div(ng-controller=‘IndexController’)
div(ng-if=«page.type == ‘catalog’»)
div(ng-controller=‘IndexController’)
It is not clear how to load templates, and there is the question of the performance of this solution. Perhaps there is a better solution?