angularjs函数未被调用

angularjs函数未被调用,angularjs,Angularjs,我对AngularJS是新手。我创建了一个简单的场景来开始学习,但由于某些原因,以下代码不起作用: var app = angular.module("myModule", []).controller("myController", function($scope) { $scope.addIneger = function (a, b) { alert(); $scope.output= a + b; } }); 这是我的html代码: &l

我对AngularJS是新手。我创建了一个简单的场景来开始学习,但由于某些原因,以下代码不起作用:

var app = angular.module("myModule", []).controller("myController", function($scope) {
    $scope.addIneger = function (a, b) {
        alert();
        $scope.output= a + b;
    }
});
这是我的html代码:

<html>
<head>
  <Script src="javascript/angular.js"> </Script>
  <Script src="javascript/script.js"> </Script>
  <title>Insert title here</title>
</head>
<body ng-app="myModule">
  <table ng-cntroller="myController">
    <th>
      <td><input type="text" ng-model="a"/></td>
      <td><input type="text" ng-model="b"/></td>
    </th>
    <th>
        <td><input type="text" ng-model="output"/></td>
    </th>
    <th>
      <td>
        <button type="button" ng-click="addIneger(a,b)" />
      </td>
   </th>
 </table>

在此处插入标题

如您所见,两个文本框获得数字,单击按钮后,结果应显示出来


有人能帮忙吗?

您可以按以下方式更改代码。问题应该是,当AddInger(a,b)调用时,它不会发送a和b的值

var app=angular.module("myModule",[]).controller("myController", function($scope){
    $scope.addIneger=function(){
    alert();
    $scope.output= $scope.a+$scope.b;
    }
    });

<html>
<head>
 <Script src="javascript/angular.js"> </Script>
 <Script src="javascript/script.js"> </Script>
 <title>Insert title here</title>
</head>
<body ng-app="myModule">
<table ng-cntroller="myController">
<th>
     <td><input type="text" ng-model="a"/></td>
    <td><input type="text" ng-model="b"/></td>
     </th>
    <th>
        <td><input type="text" ng-model="output"/></td>
    </th>
        <th>
     <td>

      <button type="button" ng-click="addIneger()" />

     </td>
   </th>
  </table>
    </body>
     </html>
var-app=angular.module(“myModule”,[]).controller(“myController”,function($scope){
$scope.addIneger=函数(){
警惕();
$scope.output=$scope.a+$scope.b;
}
});
在此处插入标题

尝试使用以下代码:

$scope.output = parseInt(a) + parseInt(b);

您犯了语法错误/输入错误:

<table ng-cntroller="myController">
因此,当你把它们相加时,它将两个值合在一起
“2”+“3”=“23”
。您需要将输入更改为
type=“number”

工作完美:

angular.module('App',[]);
角度。模块('App')。控制器('controller')[
“$scope”,
职能($范围){
$scope.addInteger=函数(a,b){
$scope.output=a+b;
}
}
]);



加整数


谢谢,但由于我正在努力学习,我很好奇如何与addInteger(a,b)合作仍然不工作,似乎连函数都没有被调用。谢谢你,当我只是把那些字段改成数字时,我的代码仍然不工作,我理解你的javascript代码有点不同,但我找不到我的错误,我的javascript代码怎么了?我的代码甚至没有调用方法
<table ng-controller="myController">
<input type="text" ng-model="a" />
<input type="text" ng-model="b" />
 <input type="number" ng-model="a" /><br>
 <input type="number" ng-model="b" /><br>
$scope.addInteger = function (a, b) {
    $scope.output= new Number(a) + new Number(b);
}

// or

$scope.addInteger = function (a, b) {
    $scope.output= parseInt(a) + new parseInt(b);
}