gpt4 book ai didi

javascript - 未调用 AngularJS NgChange

转载 作者:太空狗 更新时间:2023-10-29 16:46:23 25 4
gpt4 key购买 nike

在 Angularjs 中,我添加了以下用于监听更改事件的选择控件

<select ng-model="Ruoli" ng-options="ruolo.Nome for ruolo in ruoli" class="form-control" ng-change="setNotRuolo(Ruoli.Id)"></select>

当我选择一个项目时的功能

setNotRuolo()

被正确调用,但是当我使用键盘上的向下键更改项目时,该函数未被调用。

我该如何解决这个问题?

最佳答案

这是一个已经在 GitHub 上讨论过的问题

看看这个

Working Demo

html

<div ng-app='myApp' ng-controller="Controller">
<label for="browsers">Pick A Name:</label>
<form name="myForm">
<select dselect required id="browsers" ng-model="selectValue" ng-options="browser for browser in browsers">
<option value="">Select One</option>
</select>
<br>
<button ng-click="submit()" ng-disabled="!myForm.$valid">submit</button>
</form>
<br>
<br>You Selected: {{selectValue || "You didn't pick"}}</div>
</div>

脚本

var app = angular.module('myApp', []);

app.controller('Controller', function ($scope) {
$scope.browsers = ['Manu', 'Mathew', 'Sunny'];
$scope.submit = function () {
alert("submit");
}
});
if (navigator.userAgent.indexOf("Sunny") !== -1) {
app.directive("select", function () {
return {
restrict: "E",
require: "?ngModel",
scope: false,
link: function (scope, element, attrs, ngModel) {
if (!ngModel) {
return;
}
element.bind("keyup", function () {
element.trigger("change");
})
}
}
})
}

关于javascript - 未调用 AngularJS NgChange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23514309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com