admin管理员组文章数量:1325380
I am newbie to AngularJS. I have a question, why does ng-change
doesn't passes the $event?
HTML
<div ng-controller="foo">
<select ng-model="item" ng-options="opts as opts.name for opts in sels" ng-change="lstViewChange($event)" ng-click="listViewClick($event)"></select>
</div>
Script
var myApp = angular.module('myApp', []);
angular.element(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
function foo($scope) {
$scope.sels = [{id: 1, name: 'a'}, {id: 2, name: 'b'}];
$scope.lstViewChange = function($event){
console.log('change', $event); //undefined
}
$scope.listViewClick = function($event){
console.log('click', $event); //object
}
}
Have a look at this fiddle /. Click
passes a valid $event but change
doesn't. Can someone explain this behavior?
I am newbie to AngularJS. I have a question, why does ng-change
doesn't passes the $event?
HTML
<div ng-controller="foo">
<select ng-model="item" ng-options="opts as opts.name for opts in sels" ng-change="lstViewChange($event)" ng-click="listViewClick($event)"></select>
</div>
Script
var myApp = angular.module('myApp', []);
angular.element(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
function foo($scope) {
$scope.sels = [{id: 1, name: 'a'}, {id: 2, name: 'b'}];
$scope.lstViewChange = function($event){
console.log('change', $event); //undefined
}
$scope.listViewClick = function($event){
console.log('click', $event); //object
}
}
Have a look at this fiddle http://jsfiddle/QfZZH/. Click
passes a valid $event but change
doesn't. Can someone explain this behavior?
1 Answer
Reset to default 5Just to state the obvious, the docs say that ngClick
will pass the event, but ngChange
has no such documentation.
So, what you're asking is why Angular's designers chose to do this? My thought is that ngClick
fires as a result of a click, so it make sense that there would be a mouse event associated with the directive firing. ngChange
on the other hand is a result of any user action that changes the model, which could be associated with all sorts of events rather than one specific event.
本文标签: javascriptAngularJSWhy select drop down doesn39t have event on changeStack Overflow
版权声明:本文标题:javascript - AngularJS - Why select drop down doesn't have $event on change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742191936a2430376.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论