[英]angular js ng-click not firing
I don't understand where I made a mistake. 我不明白我在哪里犯了错误。
<div ng-app="nameApp" ng-controller="nameCntrl">
<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">
<thead><tr><th>Name</th><th>Value</th></tr></thead><tbody>
<tr><td>Chris </td>
<td><input type="text" size="4" ng-model="numDays"/>
<input type="button" value="submit" ng-click="submitbutton"/></td></tr>
</table>
{{numDays}}
</div>
var app = angular.module('nameApp', []);
app.controller('nameCntrl',function($scope) {
console.log($scope);
$scope.numDays = 5;
$scope.submitbutton = function() {
alert($scope.numDays);
}
});
http://jsfiddle.net/srvdfv6y/1/
The application you wrote is correct, just beware to load angular script before the event DOM ready . 您编写的应用程序是正确的,只是要注意在事件DOM准备就绪之前加载角度脚本。
See updated fiddle 查看更新的小提琴
Also, as noticed by @TjGienger, ng-click="submitbutton"
should be ng-click="submitbutton()"
. 另外,如@TjGienger所注意到的, ng-click="submitbutton"
应该是ng-click="submitbutton()"
。
You need to specify submitbutton()
as ng-click
statement 您需要将submitbutton()
指定为ng-click
语句
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script> var app = angular.module('nameApp', []); app.controller('nameCntrl', function($scope) { console.log($scope); $scope.numcDays = 5; $scope.myValue = true; $scope.submitbutton = function() { alert($scope.numcDays); $scope.myValue = false; } }); </script> <body> <div ng-app="nameApp" ng-controller="nameCntrl"> <table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;"> <thead> <tr> <th>Name</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>Chris</td> <td> <input type="text" size="4" ng-model="numDays" /> <input type="button" value="submit" ng-click="submitbutton()" /> </td> </tr> </table>{{numDays}} <div ng-hide="myValue">Answer submitted</div> </div> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.