在Angular JS中获取错误

时间:2016-05-26 17:50:07

标签: angularjs

我是Angular JS的新手,并且实现了保存数据的功能。这是我的代码 - 的script.js

function EmpCtrl($scope) {
  $scope.save = function () {
        $.ajax({
            type: "POST",
            url: "EmpWebService.asmx/SaveEmployee",
            data: "{'name':'" + $scope.EmpName + "','age':'" + $scope.EmpAge + "','city':'" + $scope.EmpCity + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (msg) {
                alert(msg.d);
            }
        });
    };
}

Employee.aspx

<html  xmlns="http://www.w3.org/1999/xhtml" ng-app>
<head runat="server">
    <title></title>
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/jquery-1.8.3.min.js"></script>
    <script src="Script.js"></script>

</head>
<body>
    <form id="form1" ng-controller="EmpCtrl" ng-submit="save()">
        <div style="font-family: Verdana; font-size: 12px; margin-left: 450px;">
            <table>

                <tr>
                    <td style="text-align: right;"> Name :
                    </td>
                    <td>
                        <input type="text" id="txtEmpName" ng-model="EmpName" />
                    </td>
                </tr>
//rest code

按下F12后,我收到以下错误 - 论证&#39; EmpCtrl&#39;不是一个功能,未定义

1 个答案:

答案 0 :(得分:0)

你必须声明一个Angular控制器如此:

angular.module('myModule', [])
  .controller('EmpCtrl', EmpCtrl);