2016-06-21 12 views
0

I am using state provider in ng-app and in myCtrl1.js ,the error occurred likeエラー:[NG:AREQ]:[NG:AREQ]引数が 'myCtrl1' 関数ではありません、未定義

エラーまし引数 'をmyCtrl1' 関数ではありません、未定義だ、以下の私のコード..です

MainApp.js

 'use strict'; 
     var mainApp=angular.module('mainApp',['ui.router']); 
     angular.module('mainApp',['ui.router']).config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { 
      $urlRouterProvider.otherwise('/'); 
      $stateProvider 
      .state('Emergency Message', { 
       url: '/', 
       templateUrl:'msg/setting.html', 
       controller:'myCtrl1'/*This one generates an error which i have explained above..*/ 
      }) 
      .state('setting', { 
       url: '/setting', 
       templateUrl: 'setting/cchk.html', 
       controller:'myCtrl'/*this works*/    
      }) 
      .state('message', { 
       url: '/message', 
       templateUrl: 'msg/setting.html', 
       controller:'myCtrl1'/*same This one also generates an error which i have explained above.. */ 
      }); 
     }]); 

Below file in which error occurs

myCtrl1.js

 'use strict'; 
     angular.module('mainApp',[]).controller('myCtrl1',function($scope,$http){ 
     }); 

Below is my index page

Index.html

This is my html page in and it has all the js,css and all file which are required.

<!DOCTYPE html> 
     <html ng-app="mainApp"> 
      <head 

これはあなたがこれを実行しなければならない代わりにangular.module('mainApp',[]),controller(...)

  </head> 
      <body> 
       <center> 
        <a id="a1" ui-sref=".message">Message</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <a id="a2" ui-sref=".setting">Setting</a> 
       </center> 
       <br><br><br><br> 
       <div ui-view></div> 





      </body> 
     </html> 

This all are the files please help me out...

+0

これは、angular.module( 'mainApp')と同じようにコントローラを登録する必要があります。コントローラ(...)は、同様にangular.module( 'mainApp')を実行する必要があります。config – gaurav5430

+0

myCtrlは、どの作品ですか?コントローラ( 'myCtrl'、function($ scope、$ http){}); – gaurav5430

+0

angular.module( 'mainApp')。 –

答えて

0

を含めるためのスクリプトとcssファイル一部です:他の場所のための

angular.module('mainApp').controller(...) 

同じ、ここでは、angular.moduleを使用しています。 あなただけが行っているように、一度モジュールを初期化する必要があります。この後

var mainApp=angular.module('mainApp',['ui.router']); 

あなたは

angular.module('myApp') 

を使用する必要がありますどこでもので、あなたのコードは次のようになります。

'use strict'; 
var mainApp=angular.module('mainApp',['ui.router']); 
angular.module('mainApp').config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { 
    $urlRouterProvider.otherwise('/'); 
    $stateProvider 
    .state('Emergency Message', { 
     url: '/', 
     templateUrl:'msg/setting.html', 
     controller:'myCtrl1'/*This one generates an error which i have explained above..*/ 
    }) 
    .state('setting', { 
     url: '/setting', 
     templateUrl: 'setting/cchk.html', 
     controller:'myCtrl'/*this works*/    
    }) 
    .state('message', { 
     url: '/message', 
     templateUrl: 'msg/setting.html', 
     controller:'myCtrl1'/*same This one also generates an error which i have explained above.. */ 
    }); 
}]); 

と:

'use strict'; 
angular.module('mainApp').controller('myCtrl1',function($scope,$http){ 
}); 
+0

私は試しましたが、angular.js:68のようなエラーが出ました:Uncaught Error:[$ injector:nomod]モジュール 'mainApp'は利用できません!モジュール名のスペルが間違っているか、モジュール名を読み込めませんでした。モジュールを登録する場合は、依存関係を2番目の引数として指定するようにしてください。 –

+0

設定をangular.module( 'myApp')に変更しましたか? – gaurav5430

0

再度

angular.module('mainApp').controller('myCtrl1',function($scope,$http){ 
}); 
+0

はい依存関係を再度使用しませんでした –

+0

このrefrenceを削除することができますvar mainApp = 代わりにmainApp.controller( 'myCtrl1'、function($スコープ、$ http){ }); – abdoutelb

0

depndanciesを定義するべきではありません私の問題は、私は私のスクリプトファイルを添付されたときので、私はこの問題に直面していた、解決されているので、シーケンスは、したがって、私はこの問題に直面していた間違っていました。

+0

ありがとう@gouravとAbdou Telb –

関連する問題