controller是未定义的错误(已经在javascript文件中定义)

时间:2015-03-27 08:56:36

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat angular-ui-router

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module app.Firstpage due to:
ReferenceError: loginController is not defined
    at routerChange (http://127.0.0.1:1139/www/js/Firstpage/route.js:9:41)
    at Object.invoke (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12110:17)
    at runInvokeQueue (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12016:35)
    at http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12025:11
    at forEach (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:8248:20)
    at loadModules (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12006:5)
    at http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12023:40
    at forEach (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:8248:20)
    at loadModules (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:12006:5)
    at createInjector (http://127.0.0.1:1139/www/lib/ionic/js/ionic.bundle.js:11932:11)

您好 我正在尝试制作有角度的应用程序。但是我收到的错误是我的控制器未定义。你能不能告诉我我做错了什么?我收到了上述错误 here is my codehttps://dl.dropbox.com/s/zipm6g0ewqf7xg4/ionic_web.zip?dl=0

我正在尝试加载 index.html 文件。请运行 index.html 文件以获取错误

<html ng-app="app">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>First app</title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">

    <!-- libraray--->
     <script src="lib/ionic/js/ionic.bundle.js" type="application/javascript"></script>  




    <!-- module  -->
   <script src="js/Firstpage/module.js" type="application/javascript"></script>




    <!-- controller  -->
<script src="js/Firstpage/controller/firstcontroller.js" type="application/javascript"></script>

     <!-- router -->
    <script src="js/Firstpage/route.js" type="application/javascript"></script>


    <script src="js/app.js" type="application/javascript"></script>

</head>
<body>

    <ion-nav-bar class="bar-balanced">
        <ion-nav-back-button class="">
        </ion-nav-back-button>
    </ion-nav-bar>

    <ion-nav-view></ion-nav-view>




</body>
</html>

这是我的整个代码

https://dl.dropbox.com/s/zipm6g0ewqf7xg4/ionic_web.zip?dl=0

1 个答案:

答案 0 :(得分:2)

以前:

在Route.js中 -

(function(){
   'use strict';
   angular.module('app.Firstpage').config(routerChange);
    routerChange.$inject=['$stateProvider', '$urlRouterProvider'];
    function routerChange($stateProvider,$urlRouterProvider){
        $stateProvider.state('login',{
                             url:'/login',
                             templateUrl:"js/Firstpage/template/login.html",
                             controller:'loginController'

        })

        $urlRouterProvider.otherwise('/login')
    }


})(); 

现在Route.js:

(function(){
   'use strict';
   angular.module('app.Firstpage').config(routerChange);
    routerChange.$inject=['$stateProvider', '$urlRouterProvider'];
    function routerChange($stateProvider,$urlRouterProvider){
        $stateProvider.state('login',{
                             url:'/login',
                             templateUrl:"js/Firstpage/template/login.html",
                             controller:'loginController'

        })

        $urlRouterProvider.otherwise('/login')
    }


})();
你错过了单引号。

<强>控制器:&#39;的LoginController&#39;

输出屏幕截图: Output image