Javascript 未在ng更改中捕获事件
Javascript 未在ng更改中捕获事件,javascript,angularjs,Javascript,Angularjs,var-app=angular.module('myApp',[]); app.controller('OrderFormController',函数($scope、$http、$filter、$window、$location){ $scope.names=['test','test2']; $scope.retrieveSelectedClass=函数(newValue、oldValue、$event){ 警报($事件); } }); 选择选项 尝试ng change=“retrieveS
var-app=angular.module('myApp',[]);
app.controller('OrderFormController',函数($scope、$http、$filter、$window、$location){
$scope.names=['test','test2'];
$scope.retrieveSelectedClass=函数(newValue、oldValue、$event){
警报($事件);
}
});代码>
选择选项
尝试ng change=“retrieveSelectedClass(selectedName,{{{selectedName}}}',$event)”
ng change=“retrieveSelectedClass(selectedName,{{selectedName}}',event)”的瞬间
还有js
$scope.retrieveSelectedClass=函数(newValue、oldValue、事件){
}
您无法将事件传递给ng change
ng change不是用于处理更改事件的指令(我意识到给定名称会使人混淆),而是在调用ngModelController.$setViewValue()并更改值时发出通知(因为ng change向$viewChangeListeners集合添加了一个侦听器)。所以这是意料之中的
参考资料
解决方法:
请查看此内容。删除(单击)事件并尝试此操作
$scope.retrieveSelectedClass=函数(newValue$event){
警报($事件);
}
});
能否提供代码的可运行代码段?这将是容易和更快地实现debug@VicJordan我在问题中添加了一个片段。这永远不会起作用,因为ng change永远不会检测到$eventngMouse,ng change不提供事件对象。
我已经听过更改的值,但如何听按下ctrl键。我没有试图通过事件监听更改。@NagendraSingh当用户按下ctrl键时,
?是。当用户按下ctrl键时,我需要打开一个新的选项卡,正如我在问题中已经提到的,windows事件仅在chrome中有效,但当我使用windows事件时,跨浏览器兼容性失败。