无法实例化控制器Angular New Router

Ale*_*u R 5 angularjs angularjs-new-router

我正在使用新的Angular路由器1.4,它为组件做一个简单的控制器时抛出一个错误:

angular.module('app.campaigns',['security', 'ngNewRouter'])
  .controller('CampaignsController', ['authService', '$rootScope', CampaignsController]);   


function CampaignsController (authService, $rootScope) {
    console.log ('this is campaigns controller');
    this.currentUser = $rootScope.authService.currentUser;
    this.authService = $rootScope.authService;
    this.logout = authService.logout;
}
Run Code Online (Sandbox Code Playgroud)

我试过没有注入$ rootScope并且是一样的.我究竟做错了什么?一个非常相似的组件就像魅力一样,但事实并非如此.

小智 0

这是与 Angular 1.5 一起使用的新路由器的最新示例,对于 1.4,您将无法使用 component() 我认为除非您自己添加它,否则它只是指令的包装器。

您应该使用从 Angular2 项目构建的 Angular_1_router.js,而不是安装 Angular-New-Router 包(直到更新),在下面的示例中,它们使用 Angular 1.5 并修复了它,以便您可以使用 Components() 和子路由等。

检查完整工作示例的链接: http://plnkr.co/edit/N3YP3dKMuljpZ6mWsVBT ?p=preview

应用程序.js

angular.module('app', ['ngComponentRouter', 'dialog', 'heroes', 'crisis-center'])

.config(function($locationProvider) {
  $locationProvider.html5Mode(true);
})

.run(function($router) {
  $router.config([
    { path: '/...', name: 'App', component: 'app', useAsDefault: true }
  ]);
  $router.navigate(['App']);
})

.component('app', {
  template:
    '<nav>\n' +
    '  <a ng-link="[\'CrisisCenter\']">Crisis Center</a>\n' +
    '  <a ng-link="[\'Heroes\']">Heroes</a>\n' +
    '</nav>\n' +
    '<ng-outlet></ng-outlet>\n',
  $routeConfig: [
    {path: '/crisis-center/...', name: 'CrisisCenter', component: 'crisisCenter', useAsDefault: true},
    {path: '/heroes/...', name: 'Heroes', component: 'heroes'},
    {path: '/disaster', name: 'Asteroid', redirectTo: ['CrisisCenter', 'CrisisDetail', {id:3}]}
  ]
});
Run Code Online (Sandbox Code Playgroud)