简单的ng-click在AngularJS中不起作用。这里有什么基本的东西吗?

时间:2017-09-28 09:12:18

标签: angularjs

这是我的aspx:

<body ng-controller="myController">
    <form id="form1" runat="server">
        <div>
        <input type="button" value="Press" ng-click="incrementCount()" ng-init="count=0"/>
        <span>{{ count }}</span>
        </div>
    </form>
</body>

以下是JS:

    angular.module('myModule', [])
    .controller('myController', function ($scope, $http) {  

    $scope.incrementCount = function () {
        $scope.count = $scope.count + 2;
    };
});

我的代码有什么问题? 当我点击“按下”按钮时,它不能正常工作。

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
angular.module('myModule', []) .controller('myController', function ($scope, $http) {
$scope.incrementCount = function () {
    $scope.count = $scope.count + 2;
};
});
&#13;
<!DOCTYPE html>
<html lang="en-US">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myModule" ng-controller="myController">
    <form id="form1" runat="server">
        <div>
        <input type="button" value="Press" ng-click="incrementCount()" ng-init="count=0"/>
        <span>{{ count }}</span>
        </div>
    </form>
</body>
</html>
&#13;
&#13;
&#13;

它正常工作!单击“运行”。