0

I have a issue on updating a input value based on another input value. I've "J" input and "U" input. When J is changed I need the values updated in U input. And I want to do this with angularjs. I've done a simple angularj js controller to get the values from database:

<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;});
    }

});

But it doesn't work. How can I make the controller to update the data after a input is changed? I've tried with $('#inputJ').change(function () { the code above}); and it doesn't work. And Google didn't helped me too much for this question. THank you

lin
  • 17,956
  • 4
  • 59
  • 83
Sasu Andrei
  • 11
  • 1
  • 4
  • 1
    Please take a look at http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background – lin Feb 19 '17 at 14:33
  • Nice article. Ok so. jquery it's not a "brother" for angular :) SO I've done in my code above the $scop.OnChangejudet function - and I have a " Cannot read property 'copy' of undefined". I don't understand why. – Sasu Andrei Feb 19 '17 at 15:03
  • Somewhere you try access a property called `copy` and it is undefined. – lin Feb 19 '17 at 15:08

1 Answers1

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>

This is the working code !

Sasu Andrei
  • 11
  • 1
  • 4