简体   繁体   English

AngularJS中的ui.router问题

[英]Issues with ui.router in angularjs

I have discovered ui.router for building Single Page Application, but following a guide: 我发现用于构建单页应用程序的ui.router,但遵循以下指南:

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module routerApp due to:(…)(anonymous function) @ angular.js:68(anonymous function) @ angular.js:4640forEach @ angular.js:321loadModules @ angular.js:4601createInjector @ angular.js:4523doBootstrap @ angular.js:1758bootstrap @ angular.js:1779angularInit @ angular.js:1664(anonymous function) @ angular.js:31763trigger @ angular.js:3207defaultHandlerWrapper @ angular.js:3497eventHandler @ angular.js:3485

This is the index.html page: 这是index.html页面:

  <html>
  <head>
    <script src="lib/angular.js"></script>
    <script src="lib/angular-ui-router.js"></script>
    <script src="app.js"></script>

    <style>.active { color: red; font-weight: bold; }</style>
  </head>

  <body ng-app="routerApp">
    <a ui-sref="table">Table</a>

    <div ui-view></div>
  </body>
  </html>

This is the app.js: 这是app.js:

var routerApp = angular.module("routerApp", ['ui.router']);
routerApp.config('$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
    .state('table', {
        url : '/',
        templateUrl : 'views/table.html'
    });
});

Thank you anticipately for the help, i really can't see the error.. 期待您的帮助,我真的看不到错误。

Injections should be an array. 注入应该是一个数组。

Try add these like 尝试添加这些像

var routerApp = angular.module("routerApp", ['ui.router']);
routerApp.config( [  '$stateProvider', '$urlRouterProvider', 
// -------------- ^  ---------------
function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
    .state('table', {
        url : '/',
        templateUrl : 'views/table.html'
    });
}   ]   );
//  ^ and this -------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM