我试图通过ng-options获取ng-change上的当前对象,并且我得到了undefiend
<select class="form-control" ng-model="currentDrawResults" ng-options="(draw.drawDate | date:'MMM d, y' ) for draw in lot.lastDraws track by draw.drawDate" ng-change="changeDraw(draw)">
</select>
我正在尝试从这个网站获得一些答案,但仍然无法正常工作。 这个问题是什么?
答案 0 :(得分:0)
将ng-change="changeDraw(draw)"
更改为ng-change="changeDraw(currentDrawResults)
var app = angular.module('app', []);
app.controller('fCtrl', function($scope) {
$scope.lot = {
lastDraws: [{
drawDate: "2011-10-28T09:30:24.673Z"
}, {
drawDate: "2012-09-28T09:30:24.673Z"
}, {
drawDate: "2014-05-28T09:30:24.673Z"
},
]
};
$scope.changeDraw = function(draw) {
alert(draw.drawDate)
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="fCtrl">
<select class="form-control" ng-model="currentDrawResults" ng-options="(draw.drawDate | date:'MMM d, y' ) for draw in lot.lastDraws track by draw.drawDate" ng-change="changeDraw(currentDrawResults)">
</select>
</div>
</div>