angularjs - Controller not being found -
angularjs - Controller not being found -
i'm giving angular try. i'm defining controller in customerscontroller.js. but, when run error "error: error:areq bad argument". customerscontroller not beingness found. appreciated. thanks.
here html file:
<!doctype html> <html lang="en" data-ng-app> <head> <meta charset="utf-8"> <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='http://fonts.googleapis.com/css?family=open+sans:400italic,400,600,700,800,300' rel='stylesheet' type='text/css'> </head> <body ng-controller="customerscontroller"> <h2>customers</h2> filter: <input type="text" ng-model="customerfilter.name" /> <table> <tr> <th ng-click="dosort('name')">name</th> <th ng-click="dosort('city')">city</th> <th ng-click="dosort('ordertotal')">order total</th> <th ng-click="dosort('joined')">joined</th> </tr> <tr ng-repeat="cust in customers | filter:customerfilter | orderby:sortby:reverse"> <td>{{ cust.name }}</td> <td>{{ cust.city }}</td> <td>{{ cust.ordertotal | currency }}</td> <td>{{ cust.joined | date }}</td> </tr> </table> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script> <script src="app/controllers/customerscontroller.js"></script> </body> </html>
and here customercontroller.js
function customerscontroller($scope){ $scope.sortby = 'name'; $scope.reverse = false; $scope.customers = [ { joined: "2000-12-24", name: "charles", city: "fairfax", ordertotal: "12414432.45" }, { joined: "2000-09-12", name: "jack", city: "altamonte springs", ordertotal: "5.9943" }, { joined: "2000-01-25", name: "bill", city: "waldorf", ordertotal: "100" } ], $scope.dosort = function(propname){ $scope.sortby = propname; $scope.reverse = !$scope.reverse; }; }
please add together line customercontroller.js
angular.module("app", []).controller("customerscontroller", customerscontroller);
class="snippet-code-js lang-js prettyprint-override">angular.module("app", []).controller("customerscontroller", customerscontroller); function customerscontroller($scope) { $scope.sortby = 'name'; $scope.reverse = false; $scope.customers = [{ joined: "2000-12-24", name: "charles", city: "fairfax", ordertotal: "12414432.45" }, { joined: "2000-09-12", name: "jack", city: "altamonte springs", ordertotal: "5.9943" }, { joined: "2000-01-25", name: "bill", city: "waldorf", ordertotal: "100" }], $scope.dosort = function(propname) { $scope.sortby = propname; $scope.reverse = !$scope.reverse; }; }
class="snippet-code-html lang-html prettyprint-override"><!doctype html> <html lang="en" data-ng-app="app"> <head> <meta charset="utf-8"> <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='http://fonts.googleapis.com/css?family=open+sans:400italic,400,600,700,800,300' rel='stylesheet' type='text/css'> </head> <body ng-controller="customerscontroller"> <h2>customers</h2> filter: <input type="text" ng-model="customerfilter.name" /> <table> <tr> <th ng-click="dosort('name')">name</th> <th ng-click="dosort('city')">city</th> <th ng-click="dosort('ordertotal')">order total</th> <th ng-click="dosort('joined')">joined</th> </tr> <tr ng-repeat="cust in customers | filter:customerfilter | orderby:sortby:reverse"> <td>{{ cust.name }}</td> <td>{{ cust.city }}</td> <td>{{ cust.ordertotal | currency }}</td> <td>{{ cust.joined | date }}</td> </tr> </table> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script> <script src="app/controllers/customerscontroller.js"></script> </body> </html>
angularjs
Comments
Post a Comment