尝试建立路由时出现注入错误

时间:2016-02-10 08:12:26

标签: angularjs ngroute

我正在测试Angular框架,我的上一次测试基于路由器。

我做了一个示例,其中我有典型的项目设置:index.html的源文件夹,其中包含:

<!DOCTYPE HTML>
<html ng-app="test">
    <head>
      <!-- Plugins/Frameworks !-->
      <script type="text/javascript" src="plugins/angular.js"></script>
      <script type="text/javascript" src="plugins/angular-route.js"></script>

      <!-- JS !-->
      <script type="text/javascript" src="js/app.js"></script>
      <script type="text/javascript" src="js/controllers.js"></script>
      <script type="text/javascript" src="js/directives.js"></script>
      <script type="text/javascript" src="js/services.js"></script>

      <!-- Stylesheets !-->
      <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
      <link rel="stylesheet" type="text/css" href="css/styles.css">
    </head>
    <body>
        <div ng-view>
        </div>
    </body>
</html>

然后,文件夹js(带有控制器,指令,模块定义......),css和插件(我有angular.js和angular-route.jos)。

这是我在js / app.js的模块定义中所拥有的:

var app = angular.module('test', ['ngRoute', 'controllers', 'directives', 'services']);

app.config(['$routeProvider',function($routeProvider) {
    $routeProvider.
    when('/index', {
        templateUrl: 'templates/main.html',
        controller: 'mainCtrl'
    }).
    otherwise({
        redirectTo: '/index'
    });

}]);

在输入localhost / testSite / index时,它应该有效,将我检索到此模板:

<div class="page-header">
  <h1>Test site<small>For test purposes</small></h1>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 sidebar">
    Test, test, test!
</div>

......不应该吗?好吧,它没有。

每次访问index.html时都会出现此错误:

错误:[$ injector:modulerr] http://errors.angularjs.org/1.5.0-rc.1/ $ injector / modulerr?p0 = test&amp; p1 =%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1。 5.0-RC.1%2F%24injector%2Fmodulerr%3Fp0%3Ddirectives%26P1%3D%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.0-RC.1%252F% 2524injector%252Fnomod%253Fp0%253Ddirectives%250AP%252F%253C%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A6%253A421%250Afe%252F%253C%252F%253C%252F%253C%2540http% 253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A25%253A136%250Ab%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A24%253A188%250Afe%252F%253C%252F%253C% 2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A24%253A1%250Ag%252F%253C%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A39%253A201%250An%2540http% 253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A7%253A364%250Ag%2540http%253A%252F%25 2Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A39%253A49%250Ag%252F%253C%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A39%253A218%250An%2540http%253A%252F%252Flocalhost% 252FtestSite%252Fplugins%252Fangular.js%253A7%253A364%250Ag%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A39%253A49%250Agb%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular。 JS%253A43%253A53%250Azc%252Fc%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A20%253A421%250Azc%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A21% 253A225%250Aae%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A20%253A41%250A%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A304%253A355%250Ab%2540http% 253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A181%253A440%250AMf%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fan gular.js%253A36%253A391%250ALf%252Fd%2540http%253A%252F%252Flocalhost%252FtestSite%252Fplugins%252Fangular.js%253A36%253A340%250A%0AP%2F%3C%40http%3A%2F%2Flocalhost%2FtestSite% 2Fplugins%2Fangular.js%3A6%3A421%0Ag%2F%3C%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A39%3A475%0AN%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins% 2Fangular.js%3A7%3A364%0Ag%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A39 3A49%%0Ag%2F%3C%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular。 JS%3A39%3A218%0AN%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A7%3A364%0Ag%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A39 3A49%% 0Agb%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A43 3A53%%0Azc%2FC%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A20%3A421%0Azc%40http% 3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A21%3A225%0Aae%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A20 3A41%%0A%40http%3A%2F%2Flocalhost% 2FtestSit È%2Fplugins%2Fangular.js%3A304%3A355%0AB%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A181%3A440%0AMf%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular。 JS%3A36%3A391%0ALf%2FD%40http%3A%2F%2Flocalhost%2FtestSite%2Fplugins%2Fangular.js%3A36%3A340%0A

可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:1)

这个错误消息真的很烦人,但这里是transclation:模块'test'没有mod'指令':

错误:[$ injector:modulerr] http://errors.angularjs.org/1.5.0-rc.1/ $ injector / modulerr?p0 = 测试&amp; p1 =%5B%24injector%3Amodulerr%5D%20http%3A%2F% 2Ferrors.angularjs.org%2F1.5.0-RC.1%2F%24injector%2Fmodulerr%3Fp0%3D的指令%26P1%3D%255B%2524injector%253A的 NOMOD % 255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.0-RC.1%252F%2524injector%252F的 NOMOD %253Fp0%253D的指令

请检查您的模块指令声明。