I'm having some problems on Angular 1.5.8 This is my Script:
var app = angular.module('myApp', []);
app.controller('MyController', function($scope,$http) {
$scope.getDataFromServer = function() {
$http({
method : 'GET',
url : 'javaAngularJS'
}).success(function(data, status, headers, config) {
$scope.person = data;
// this callback will be called asynchronously
// when the response is available
}).error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
};
but when i call it, i get this error on chrome console:
angular.js:13920 Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?p0=MyController&p1=not%20a%20function%2C%20got%20undefined
at angular.js:38
at sb (angular.js:1892)
at Pa (angular.js:1902)
at angular.js:10330
at ag (angular.js:9451)
at p (angular.js:9232)
at g (angular.js:8620)
at angular.js:8500
at angular.js:1763
at m.$eval (angular.js:17682)
This is my code in jsp:
<div ng-app="myApp">
<div ng-controller="MyController">
<button ng-click="getDataFromServer()">Fetch data from server</button>
<p>First Name : {{person.firstName}} </p>
<p>Last Name : {{person.lastName}} </p>
</div>
</div>
Obviously i have Person Class and added servlet path in web.xml. I think my problem is my bad code in Angular. What's the correct way to write controller and function in js file? THX