0

我找不到名为 myapp 的模块,实际上模块创建和使用脚本代码映射模块是正确的,那么为什么我会遇到这个问题。

<!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>
4

2 回答 2

0

这是工作版本。不要;在对象中使用您的 http 调用。你的函数定义也是错误的。

<!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>
于 2016-06-16T07:34:05.497 回答
0

您的代码有问题:您使用了 ' 而不是 ' ; ' 在 $http 方法和 url 中。请使用更新后的代码。请同时更正函数定义。

<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>

于 2016-06-16T07:35:16.773 回答