2016-08-21 5 views
1

AngularJSのルーティングについて多くの情報がありました。例えば、this 1this 2this 3this 4など、stackoverflowで質問がありました。しかし、結果はありません。AngularJS routeproviderが呼び出されていません

私はAngularJS 1.5.8.jsangular-route.jsを含めました。

HTML:

<!doctype html> 
<html ng-app="employeesApp"> 
    <head> 
     <title>Injecting view</title>    
    </head> 
    <body > 

     <p>Hey! View should be injected between these statements</p> 
     <div ng-view></div> 
     <p>Hey! View should be injected between these statements</p> 

     <script src="scripts/angular.js"></script> 
     <script src="scripts/angular-route.js"></script> 
     <script src="app/app.js"></script> 
     <script src="app/controllers/employeesController.js"> </script> 
    </body> 
</html> 

Employees.html:

<h2>Employees</h2> 
<article>This is employee view!:)</article 

employeesController.js:

(function() 
{ 
    var employeesController=function($scope, foo, bar) {//THIS CODE SNIPPET IS NOT CALLED 
       alert('a1'); 
       debugger; 
       $scope.sortBy='name'; 
       $scope.reverse=false; 

       $scope.employees= [ 
    {joined:'2010-12-02', name:'Jon', city:'Reading', orderTotal:49.9956}, 
    {joined:'1995-01-25', name:'Ben', city:'Las Vegas', orderTotal:519.99}, 
    {joined:'1994-06-15', name:'Joseph', city:'New York', orderTotal:344.99}, 
    {joined:'1998-03-18', name:'Adam', city:'Seattle', orderTotal:1021.5} 
       ]; 

       $scope.doSort=function(propName){ 
        $scope.sortBy = propName; 
        $scope.reverse=!$scope.reverse; 
       }; 
      }; 

    employeesController.$inject=['$scope']; 
    angular.module('employeesApp',[]).controller('employeesController', 
        employeesController); 
}()); 

app.js:

(function() { 
    debugger;  //this code snippet works  
    var app=angular.module('employeesApp',['ngRoute']); //this code snippet works 

    app.config(function($routeProvider){ //THIS CODE SNIPPET IS NOT CALLED 
      alert('in'); 
      debugger; 
      $routeProvider 
      .when('/', { 
      templateUrl: 'app/views/employees.html', 
      controller: 'employeesController' 
     }) 
     .otherwise({ redirectTo: '/' });      
     }); 
}()); 

私は、二重しかしemployee.htmlが注入されていない、すべてのディレクティブとコードをチェックします。
誰かが私が間違っていることを知っていますか?私はAngularJS 1.5.8.jsを使用しています。

答えて

2

私が見る唯一の問題は、あなたが

angular.module('employeesApp', []).controller('employeesController', employeesController); 

あなたのコントローラにemployeesAppを再定義しているされてあなたは一度だけあなたのモジュールを定義[]一部

angular.module('employeesApp').controller('employeesController', employeesController); 

を省略します。使用方法angular.module('modulename', arrayofdependencies or empty array)

他にもgetter構文を使用して、モジュール、コントローラ、ディレクティブなどのパーツを追加するだけです。ここでは配列を使わないでください。 angular.module('modulename').controller

+0

男、ありがとう! :) あなたは素晴らしいです! :) – StepUp

関連する問題