[英]How to get access to $route in meanjs controller
I am trying to get access to the current route since I added a title on it. 我试图访问当前路线,因为我在其上添加了标题。
So the route looks something like 所以路线看起来像
state('reports', {
title: 'Reports',
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
}).
I want to get access to the title. 我希望能够访问标题。 so I can put it on my page Header. 所以我可以把它放在我的页面标题上。 So in the Header controller I thought I could just get it off my 所以在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));
and I get the following error 我收到以下错误
Error: [$injector:unpr] Unknown provider: $routeProvider <- $route 错误:[$ injector:unpr]未知提供者:$ routeProvider < - $ route
so I add ngRoute 所以我添加了ngRoute
ApplicationConfiguration.registerModule('core', ['ngRoute']);
then I get the following error 然后我收到以下错误
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! 未捕获错误:[$ injector:modulerr]由于以下原因无法实例化模块r2h:错误:[$ injector:modulerr]由于以下原因无法实例化模块核心:错误:[$ injector:modulerr]由于以下原因无法实例化模块ngRoute:Error :[$ injector:nomod]模块'ngRoute'不可用! 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. 如果注册模块,请确保将依赖项指定为第二个参数。
How am I supposed to include this properly? 我该如何正确地包括这个? the meanjs way? meanjs的方式?
I think you are confused, MeanJS standard configuration uses Angular UI Router 我觉得你很困惑,MeanJS标准配置使用Angular UI Router
You need to angular-ui-router.js
then include ui.router
inside your app dependency 您需要angular-ui-router.js
然后在您的app依赖项中包含ui.router
After that in configuration do register your state
using $stateProvider
在配置之后,使用$stateProvider
注册您的state
Syntax 句法
app.config(function($stateProvider){
$stateProvider.state('reports', {
url: '/reports',
templateUrl: 'modules/feeditems/views/reports.client.view.html'
})
})
For adding title dynamically you could refer this SO Answer 要动态添加标题,您可以参考此SO答案
Kindly refer to https://stackoverflow.com/a/28252931/4380266 . 请参阅https://stackoverflow.com/a/28252931/4380266 。 This has the solution to your problem. 这可以解决您的问题。
Check the sequence you loaded your angular files. 检查加载角度文件的顺序。 The sequence must be : 顺序必须是:
angular.js
angular-route.js
finally your angular scripts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.