AngularJS - 为什么选择下拉列表在更改时没有$ event

mou*_*man 5 html javascript angularjs

我是AngularJS的新手.我有一个问题,为什么不ng-change通过$事件?

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>
Run Code Online (Sandbox Code Playgroud)

脚本

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
    }
}
Run Code Online (Sandbox Code Playgroud)

看看这个小提琴http://jsfiddle.net/QfZZH/.Click传递有效的$事件但change不传递.有人可以解释这种行为吗?

Jon*_*on7 5

只是陈述显而易见的,文档说ngClick会传递事件,但ngChange没有这样的文档.

那么,你问的是为什么Angular的设计师选择这样做?我的想法是因为ngClick点击而发生火灾,因此有一个与指令触发相关的鼠标事件是有意义的.ngChange另一方面,是任何改变模型的用户操作的结果,可以与各种事件而不是一个特定事件相关联.