【问题标题】:UI-Router injector module errorUI-Router 注入器模块错误
【发布时间】:2016-01-14 17:57:29
【问题描述】:

var myApp = angular.module('myApp',['ui.router'])
myApp.config(function($stateProvider, $urlRouterProvider){
   // $urlRouterProvider.otherwise('/home');
    $stateprovider
    //Home states and nested views
    
            .state('home',{
                url: '/home',
                templateUrl: 'index.html'
            })
            
           
    
});
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Modern Business - Start Bootstrap Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/modern-business.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
   
</head>

<body ng-app="myApp">
    <div ng-include='"templates/header.html"'></div>
    <div ui-view></div>
     <div ng-include='"templates/footer.html"'></div>
    
    
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
    <script src="js/app.js"></script>
     <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Contact Form JavaScript -->
    <!-- Do not edit these files! In order to set the email address and subject line for the contact form go to the bin/contact_me.php file. -->
    <script src="js/jqBootstrapValidation.js"></script>
    <script src="js/contact_me.js"></script>
</body>

</html>

这是我正在使用 UIRouter 的 HTML 和 app.js。我收到注射器模块的错误,但无法弄清楚。我是AngularJS的新手,所以请帮帮我。是的,我的 ng-include 也不起作用。运行 index.html 文件时没有显示任何结果。

【问题讨论】:

    标签: html css angularjs angular-ui-router angular-ui


    【解决方案1】:

    a working plunker

    外壳是必不可少的。它是 $stateProvider 而不是 $stateprovider。这必须是状态定义:

    var myApp = angular.module('myApp', ['ui.router'])
    myApp.config(function($stateProvider, $urlRouterProvider) {
      $urlRouterProvider.otherwise('/home');
      //$stateprovider
      $stateProvider
       //Home states and nested views
        .state('home', {
        url: '/home',
        //templateUrl: 'index.html'
        template: "<h1>hello from home</h1>",
      })
    });
    

    查看here

    注意:当您开发时...不要使用最小版本。只有 full 才能给你漂亮且易于理解的异常...

    【讨论】:

    • 很高兴看到,享受令人惊叹的 UI-Router ;)
    【解决方案2】:

    $stateprovider 应该是$stateProvider

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 2017-08-12
      • 2019-04-20
      • 1970-01-01
      • 2016-05-30
      相关资源
      最近更新 更多