module is not finding

59 Views Asked by At

I am getting Cannot find module with name myapp, actually the module creation and mapping of module with script code is correct then why I am facing this issue.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>AJAX with Servlets using AngularJS</title>
<script type="text/javascript" src=js/angular.min.js></script>
<script>
angular.module("myapp", []).controller('mycontroller', function ($scope, $http){
    $scope.getDataFrmServer()=function(){
        $http({
            method:'GET';
            url:'NGServlet';
        }).success( function(data, status, header, config){
            $scope.person=data;
        }).error(function(data, status, header, config){

        });
    };
});
</script>
</head>
<body>
<div data-ng-app="myapp">
    <div data-ng-controller="mycontroller">
        <button data-ng-click="getDataFrmServer()">Fetch Data From Server</button>
        <p>First Name: {{person.firstName}}</p>
        <p>Second Name:{{person.secondName}}</p>
    </div>
</div>
</body>
</html>
2

There are 2 best solutions below

0
On

This is the working version. don't use ; in the object for your http call. Also your function definition was wrong.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>AJAX with Servlets using AngularJS</title>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script>
angular.module("myapp", []).controller('mycontroller', function ($scope, $http){
    $scope.getDataFrmServer = function(){
        $http({
            method:'GET',
            url:'NGServlet'
        }).success( function(data, status, header, config){
            $scope.person=data;
        }).error(function(data, status, header, config){

        });
    };
});
</script>
</head>
<body>
<div data-ng-app="myapp">
    <div data-ng-controller="mycontroller">
        <button data-ng-click="getDataFrmServer()">Fetch Data From Server</button>
        <p>First Name: {{person.firstName}}</p>
        <p>Second Name:{{person.secondName}}</p>
    </div>
</div>
</body>
</html>
0
On

Your code is having issues: Instead of ' , ' you have used ' ; ' in $http method and url . Please use the updated code. Please do correct the function definition also.

<script>
angular.module("myapp", []).controller('mycontroller', function ($scope, $http){
    $scope.getDataFrmServer = function(){
        $http({
            method:'GET',
            url:'NGServlet'
        }).success( function(data, status, header, config){
            $scope.person=data;
        }).error(function(data, status, header, config){

        });
    }
});
</script>

<body>
<div ng-app="myapp">
    <div data-ng-controller="mycontroller">
        <button data-ng-click="getDataFrmServer()">Fetch Data From Server</button>
        <p>First Name: {{person.firstName}}</p>
        <p>Second Name:{{person.secondName}}</p>
        </div>
</div>
</body>