2016-03-24 8 views
1

Unter Controller Ordner, ich habe CustomerController.js erstellt:

(function() { 
    angular.module('CustomerApp').controller('CustomerController', function ($scope) { 

     $scope.customers = [ 
      {name: 'Sumit', age: 27, salary: 27000, address: 'Katwaria Sarai', joined: '2016-09-21'}, 
      {name: 'Ankit', age: 25, salary: 34000, address: 'Katwaria Sarai', joined: '2016-06-22'}, 
      {name: 'Kuldeep', age: 26, salary: 27000, address: 'Sangam Vihar', joined: '2016-01-21'}, 
      {name: 'Ashutosh', age: 27, salary: 27000, address: 'Vasundara', joined: '206-09-21'}, 
      {name: 'Rashid', age: 17, salary: 17000, address: 'Pune', joined: '2016-09-21'}, 
      {name: 'Shifali', age: 27, salary: 17000, address: 'Katwaria Sarai', joined: '2016-09-21'}, 
      {name: 'Anita', age: 27, salary: 19000, address: 'Katwaria Sarai', joined: '2016-09-17'}, 
      {name: 'Deepak', age: 27, salary: 29000, address: 'Mahipalpur', joined: '2016-09-15'}, 
      {name: 'Abhishek', age: 27, salary: 27000, address: 'Darjeeling', joined: '2016-09-19'}, 
      {name: 'Binetesh', age: 27, salary: 30000, address: 'Kishangar', joined: '2016-09-23'}, 
      {name: 'Devendra', age: 27, salary: 9000, address: 'Bangalore', joined: '2016-09-22'}, 
      {name: 'Himanshu', age: 27, salary: 15000, address: 'Sangam Vihar', joined: '2016-03-29'}, 
      {name: 'Parry', age: 27, salary: 12000, address: 'Siri', joined: '2016-01-07'}, 
      {name: 'Amit', age: 27, salary: 17000, address: 'Katwaria Sarai', joined: '2016-01-11'} 
     ]; 
    }); 
}()); 

` Unter Modulordner habe ich eine Datei app.js. Der Code ist wie folgt:

(function(){ 
    var CustomerApp = angular.module('CustomerApp',[]); 
    }()); 

Dies ist meine index.jsp Datei, die wie folgt beschrieben wird:

<html ng-app="CustomerApp"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <link rel="sylesheet" href="css/mystyle.css"> 
    <script src="js/angular.js"></script> 
    <title>Customer Page</title> 
</head> 
<body ng-controller="CustomerController"> 
<h2>Customer Data</h2> 
Filter: <input type="text"> 
<br><br> 
<table border="1"> 
    <tr> 
     <th>NAME</th> 
     <th>AGE</th> 
     <th>SALARY</th> 
     <th>ADDRESS</th> 
     <th>JOINED</th> 
    </tr> 
    <tr ng-repeat="cust in customers"> 
     <td>{{cust.name | uppercase}}</td> 
     <td>{{cust.age | number}}</td> 
     <td>{{cust.salary | currency}}</td> 
     <td>{{cust.address}}</td> 
     <td>{{cust.joined | date}}</td> 
    </tr> 
</table> 
<script src="controller/CustomerController.js"></script> 
<script src="module/app.js"></script> 
</body> 
</html> 

ich Angularjs Datei bin mit der Version 1.5.0

Wenn ich bin diesen Code ausgeführt wird, gibt es dies als Fehler:

Uncaught Error: [$injector:nomod] Module 'CustomerApp' is not available or its not loaded

Bitte helfen sie mir. Ich habe viel versucht und immer noch keine Lösung.

Antwort

2

Last app.js vor controller.js,

Damit CustomerAppmodule Winkelmodul verfügbar sein für controller.js Modul CustomerApp Modul mit Controllerkomponente zu erweitern.

<script src="module/app.js"></script> 
<script src="controller/CustomerController.js"></script> 

Demo Here

+0

Pankaj @ Danke Ich habe dieses Konzept wusste aber ich habe vergessen zu platziert Vielen Dank – sumit810

+0

@ sumit810 do [akzeptieren Antwort] (http://meta.stackexchange.com/questions/ 5234/how-is-accepting-an-answer-work) .. wenn es das Problem löst. Vielen Dank :-) –

Verwandte Themen