<html ng-app>
<head>
<script language="javascript" src="./angular-1.0.6/angular.js"></script>
<script language="javascript">
function scopeReady(s) {
document.getElementById("btn").addEventListener("click", function(event) {
alert(s.items);
s.btnClick();
alert(s.items);
});
}
function ctrl($scope) {
$scope.items = ["abc", "def", "ghi"];
$scope.btnClick = function() {
$scope.items.push("one more");
};
scopeReady($scope);
}
</script>
</head>
<body ng-controller="ctrl">
<li ng-repeat="item in items">{{item}}</li>
<button id="btn">Event Handler</button>
<button ng-click="btnClick()">Angular ngClick</button>
</body>
</html>
正如代码片段所示,为什么单击第一个按钮不会触发 DOM 的更新?ng-click 和事件处理程序都调用相同的函数来继续。这让我很困惑。