模块未找到

时间:2016-06-16 07:22:25

标签: angularjs module ng-app

我收到找不到名为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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

您的代码存在问题: 而不是','你用'; '在$ http方法和网址中。 请使用更新的代码。请更正功能定义。

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