【发布时间】:2014-09-10 11:57:57
【问题描述】:
基本上,如何在 html 中访问未命名状态的控制器?我正在使用循环生成状态,包括我的 SPA 中的未命名控制器。尽管路由工作正常,主页 ng-include 了每个状态,但显然没有加载 /home 路由上的每个状态控制器。
这是我想要的示例,当我按预期导航到 /about 和 {{thisData}} = 'about Data' 时效果很好,但我希望 $scope 也位于具有 ng-include 的 /home 路由上.
<div ng-include="'views/about.html'" ng-controller="the about state's controller"></div>
在我的 app.js..
var routes, setRoutes;
routes = ['home','about','services','clients','articles','media','admin', '404'];
setRoutes = function(route) {
var state, config;
state = route;
config = {
url: '/' + route,
templateUrl: 'views/' + route + '.html',
controller: function($scope, $state){
$scope.thisData = route + " Data";
}
}
$stateProvider.state(state, config);
return $stateProvider;
};
routes.forEach(function(route) {
console.log(route);
return setRoutes(route);
});
【问题讨论】:
标签: angularjs angular-ui-router