我在根据其他输入值更新输入值时遇到问题。我" J"输入和" U"输入。当J被更改时,我需要在U输入中更新的值。我想用angularjs做这件事。我已经完成了一个简单的angularj js控制器来从数据库中获取值:
<script>
var tip = "uat_superior";
var judet = $('#judet').val();
var address = "cautare.php?tip=" + tip + "&judet="+judet;
var app = angular.module('myApp', []);
app.controller('uat_superior_data', function ($scope, $http) {
$http.get(address)
.then(function (response) {
$scope.rez = response.data.records;
});
$scope.OnChangeJudet=function()
{
$http.get(address)
.then(function (response) {
$scope.rez = response.data.records;});
}
});
但它不起作用。
如何在输入更改后让控制器更新数据?
我已尝试使用$('#inputJ').change(function () { the code above});
并且它无法正常工作。对于这个问题,谷歌并没有给我太多帮助。
谢谢你
答案 0 :(得分:0)
<div ng-app="myApp" ng-controller="uat_superior_data" id="uat_superior_data">
<div class="form-group">
<select name="judet" id="judet" ng-change="OnChangeJudet()" ng-model="myValue3">
<?php
$clasa_judet = new oras();
$judete = $clasa_judet->get_judet();
for ($b = 0; $b < count($judete); $b++) {
echo '<option value="' . $judete[$b]['id_judet'] . '">' . $judete[$b]['judet'] . ' </option>';
}
?>
</select>
</div>
<div class="form-group">
<select>
<option ng-repeat="x in rez">{{x.localitate_superioara}}</option>
</select>
</body>
<script>
var tip = "uat_superior";
var judet = $('#judet').val();
var address = "cautare.php?tip=" + tip + "&judet="+judet;
var app = angular.module('myApp', []);
app.controller('uat_superior_data', function ($scope, $http) {
$http.get(address)
.then(function (response) {
$scope.rez = response.data.records;
});
$scope.OnChangeJudet=function()
{
judet = $('#judet').val();
address = "cautare.php?tip=" + tip + "&judet="+judet;
$http.get(address)
.then(function (response) {
$scope.rez = response.data.records;});
}
});
</script>
这是工作代码!