我创建了一个动态加载路由的应用程序,然后是控制器。
我的控制器在我的索引文件中使用ng-repeat添加,然后手动引导。
我遇到的问题是当我刷新时,有时我的路由会加载并尝试在加载控制器之前重定向到给定路由。
我的问题是,有没有办法检测控制器是否使用某种事件加载?
动态加载我的控制器:
<script ng-repeat="script in clientScripts" ng-src="{{script}}"></script>
手动引导控制器
app.config(function($provide, $compileProvider, $controllerProvider, $routeProvider, $httpProvider, uiGmapGoogleMapApiProvider, $injector, toastrConfig, constant) {
app.$$registerFactory = $provide.factory;
app.$$registerService = $provide.service;
app.$$registerCtrl = $controllerProvider.register;
app.$$routeProviderRef = $routeProvider;
app.$$httpProviderRef = $httpProvider;
app.$$registerDirective = $compileProvider.directive;
...
...
初始化我的控制器
app.$$registerCtrl('AchievementsController', AchievementsController);
动态加载我的路线
/*
// DYNAMIC CLIENT ROUTING
// ======================
// corresponding controllers and factories need
// to be added in the client config.json
*/
$rootScope.$watch('config', function(x, y, z) {
if ($rootScope.config) {
// get route json and start adding routes
$http.get('../content/' + $rootScope.config.contentFolder + '/config/route.json').then(function(response) {
angular.forEach(response.data, function(value) {
// Add routes from client route.json
angular.module('dashboard').$$routeProviderRef.when(value.route, {
caseInsensitiveMatch: value.vars.caseInsensitiveMatch,
templateUrl: value.vars.templateUrl,
resolve: {
auth: function(AuthFactory) {
return value.requiresAuthentication === true ? AuthFactory.IsAuthenticated() : AuthFactory.IsAnnonymous();
}
}
});
});
var route = SessionStorage.getObject('route');
if (route && $route.current.originalPath != route && route != '/dashboard') {
$location.path(route);
}
});
}
});