1

i am creating a web app in which i have two dropdownlist

<tr style="width:80%; border:1px solid black;">
              <td style="text-align:center; width:50%;">
                  Comname
              </td>
              <td style="width:50%; border:1px solid black; padding:3px; text-align:center;">
                  <select ng-change="gbrandname()" ng-init="ucomname='comname'" ng-model="ucomname">
                      <option ng-repeat="o in comnamelistfun" value="comname">{{o.comname}}</option>
                  </select>
              </td>
          </tr>
          <tr style="width:80%; border:1px solid black;">
              <td style="text-align:center; width:50%;">
                  Brand Name
              </td>
              <td style="width:50%; border:1px solid black; padding:3px; text-align:center;">
                  <select ng-change="getzone()" ng-init="ubrandname='select'" ng-model="ubrandname">
                      <option ng-repeat="o in gbrand" value="brandname">{{o.brandname}}</option>
                  </select>
              </td>
          </tr>

on comname change i want to call the data from my database as per the selected company of my first dropdownlist

here is my function

//brandname
        $scope.gbrandname = function () {
            $http.get('/csuv5.asmx/getbrand', {
                params: {
                    log: 'admin',
                    comname: 'QED Productions Pvt Ltd',
                    pm: 'admin'
                }
            })

            .then(function (response) {
                {
                    $scope.gbrand = response.data.brandname;
                    console.log(response.data.branname);
                }
            });
    }

i pass those parameters in my function and print it but it is not showing me any data on my second dropdownlist

but when i pass static parameters in my function its working

this is my function with static parameter, this is working fine

//brandname
        //$scope.gbrandname = function () {
            $http.get('/csuv5.asmx/getbrand', {
                params: {
                    log: 'admin',
                    comname: 'QED Productions Pvt Ltd',
                    pm: 'admin'
                }
            })

            .then(function (response) {
                {
                    $scope.gbrand = response.data.brandname;
                    console.log(response.data.branname);
                }
            });
    //}

and even ng-click also working

what is wrong with ng-change?

2
  • Can you add your code in Plunker or JSFiddle? Commented Oct 17, 2016 at 9:10
  • @RutvikBhatt i can but i am fetching the data from database Commented Oct 17, 2016 at 9:11

2 Answers 2

1

Change value="comname" in <option ng-repeat="o in comnamelistfun" value="comname"> to either ng-value="comname" or value="{{comname}}"

ng-change not triggering as value doesn't change. You have provided static value "comname".

Sign up to request clarification or add additional context in comments.

Comments

0

Where is the function call with dynamic variables? Your function has hardcoded values.

Also, before even the function call, try a test function to check if the value of dropdown is being captured or even before that if the function is being called. If the function is being called, and the value is reflecting, you can proceed with a database call.

<select ng-change="`gbrandname`(ucomname)" ng-init="ucomname='comname'" ng-model="ucomname">
                  <option ng-repeat="o in comnamelistfun" value="{{comname}}">{{o.comname}}</option>
              </select>

And then the function call:

var gbrandname = function(ucomname){alert(ucomname.comname)}

You can refer to this plnkr that I just created for you:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.