【发布时间】:2015-11-13 15:33:22
【问题描述】:
AngularJS 应用程序使用 ui-router。有两种类型的页面:
- 在 routes.js 中明确指定的路由
- 按需动态派生的路由
当页面加载时,应用程序会请求数据(类型、变量)。如何根据类型加载模板和页面控制器?
/**
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’)
目前尚不清楚如何加载模板,并且存在此解决方案的性能问题。或许有更好的解决方案?
【问题讨论】:
标签: javascript angularjs angular-ui-router url-routing