2

Please find the plunker code

app.js

var app = angular.module('plunker', []);
    app.controller('MainCtrl', function($scope) {
      $scope.name = 'World';
       $scope.levels = [{LevelId:0,LevelName: "Level 1"}, {LevelId:1,LevelName: "Level 2" }];
        $scope.updateLevel = function() {
            console.log("Fired on change");
            $scope.result="Data Changed";
        }
    });

index.html

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <link rel="stylesheet" href="style.css" />
  <script data-require="[email protected]" src="https://code.angularjs.org/1.4.2/angular.js" data-semver="1.4.2"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="MainCtrl">
  <label for="textbox3">Select Level</label>
  <select id="LevelSelect" class="form-control" ng-Change="updateLevel()" ng-model="selectedLevel" ng-options="lvl as level.LevelName for level in levels"></select>
  <p>{{result}}</p>
</body>

</html>

I referred to the various SO questions like on not calling the declared method and onchange not working. Advice.

1 Answer 1

3

The way you use ng-options is incorrect there for the rendered options values is getting undefined:undefined for all the options check below image, and when you change the selected item its not trigger ng-change event because all the values are same.

enter image description here

so change it to,

ng-options="level as level.LevelName for level in levels"

please refer this angular DOC

UPDATED PLUNKER

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

2 Comments

Excellent response. Thanks a lot Toress. It did made a difference after lot of struggle. :)
yea glad to help you :) and please go though the angular doc which i add, and use ng-change simple c, that will not cause any prob but its the standard. :) cheerz

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.