[英]AngularJS - Fire $timeout event on ng-change only once
[英]AngularJS - fire ng-change on every drop down selection
我有一個下拉列表,用於選擇要生成的報告,因此當用戶從下拉菜單中選擇報告時,它會生成並報告移動設備。 使用ng-change,它只會在用戶想要生成不同的報告時獲取。 我喜歡它,所以他們可以選擇相同的下拉項目兩次,讓它下載報告兩次。
我有類似這樣的代碼:
標記:
<div>
<select ng-model="currentlySelected"
ng-options="opt as opt.label for opt in options"
ng-change="logResult()">
</select>
The value selected is {{ currentlySelected.value }}.
</div>
使用Javascript:
angular.module('demoApp', []).controller('DemoController', function($scope) {
$scope.options = [
{ label: 'one', value: 1 },
{ label: 'two', value: 2 }
];
$scope.currentlySelected = $scope.options[1];
$scope.logResult = function() {
console.log($scope.currentlySelected);
}
});
小提琴 : http : //jsfiddle.net/KyleMuir/cf59ypyw/
我期望兩次選擇“兩個”並將結果記錄到控制台兩次。 這是可行的還是我應該使用不同的指令呢?
添加按鈕肯定會有所幫助,它也會帶走任何額外的編程,它只是一個額外的元素:
http://jsfiddle.net/ootnh0sz/1/
<select ng-model="currentlySelected" ng-options="opt as opt.label for opt in options" ng-change="logResult()"></select>
<button ng-click="logResult()"> Go </button>
更新。
重置表單似乎是唯一的選擇。
http://jsfiddle.net/ootnh0sz/3/
$scope.logResult = function() {
console.log($scope.currentlySelected);
// once downloaded
$scope.currentlySelected = null;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.