如何在 meanjs 控制器中访问 $route
How to get access to $route in meanjs controller
我正在尝试访问当前路线,因为我在上面添加了标题。
所以路线看起来像
state('reports', {
title: 'Reports',
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
}).
我想访问标题。所以我可以把它放在我的页面上 Header。所以在 Header 控制器中我想我可以把它从我的
上拿下来
angular.module('core').controller('HeaderController', ['$rootScope', '$route', '$scope', 'Authentication', 'Menus',
function($rootScope, $route, $scope, Authentication, Menus) {
$scope.authentication = Authentication;
$scope.isCollapsed = false;
$scope.menu = Menus.getMenu('topbar');
$scope.$route = $route;
console.log ('typeof($route) = ' + typeof($route));
console.log ('typeof($route.current) = ' + typeof($route.current));
我收到以下错误
错误:[$injector:unpr] 未知提供者:$routeProvider <- $route
所以我添加了 ngRoute
ApplicationConfiguration.registerModule('core', ['ngRoute']);
然后我得到以下错误
Uncaught Error: [$injector:modulerr] Failed to instantiate module r2h
due to: Error: [$injector:modulerr] Failed to instantiate module core
due to: Error: [$injector:modulerr] Failed to instantiate module
ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not
available! You either misspelled the module name or forgot to load it.
If registering a module ensure that you specify the dependencies as
the second argument.
我应该如何正确地包含它? meanjs 的方式?
我觉得你很困惑,MeanJS 标准配置使用 Angular UI Router
对于AngularUI路由器
您需要 angular-ui-router.js
然后将 ui.router
包含在您的应用依赖项中
之后在配置中使用 $stateProvider
注册您的 state
语法
app.config(function($stateProvider){
$stateProvider.state('reports', {
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
})
})
动态添加标题可以参考this SO Answer
请参考
.这可以解决您的问题。
检查您加载 angular 文件的顺序。
顺序必须是:
angular.js
angular-route.js
finally your angular scripts
我正在尝试访问当前路线,因为我在上面添加了标题。
所以路线看起来像
state('reports', {
title: 'Reports',
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
}).
我想访问标题。所以我可以把它放在我的页面上 Header。所以在 Header 控制器中我想我可以把它从我的
上拿下来angular.module('core').controller('HeaderController', ['$rootScope', '$route', '$scope', 'Authentication', 'Menus',
function($rootScope, $route, $scope, Authentication, Menus) {
$scope.authentication = Authentication;
$scope.isCollapsed = false;
$scope.menu = Menus.getMenu('topbar');
$scope.$route = $route;
console.log ('typeof($route) = ' + typeof($route));
console.log ('typeof($route.current) = ' + typeof($route.current));
我收到以下错误
错误:[$injector:unpr] 未知提供者:$routeProvider <- $route
所以我添加了 ngRoute
ApplicationConfiguration.registerModule('core', ['ngRoute']);
然后我得到以下错误
Uncaught Error: [$injector:modulerr] Failed to instantiate module r2h due to: Error: [$injector:modulerr] Failed to instantiate module core due to: Error: [$injector:modulerr] Failed to instantiate module ngRoute due to: Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
我应该如何正确地包含它? meanjs 的方式?
我觉得你很困惑,MeanJS 标准配置使用 Angular UI Router
对于AngularUI路由器
您需要 angular-ui-router.js
然后将 ui.router
包含在您的应用依赖项中
之后在配置中使用 $stateProvider
state
语法
app.config(function($stateProvider){
$stateProvider.state('reports', {
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
})
})
动态添加标题可以参考this SO Answer
请参考
检查您加载 angular 文件的顺序。 顺序必须是:
angular.js
angular-route.js
finally your angular scripts