0

I want to save the selected value and pop up the selected value . But when I add the ng- change directive the select stops functioning. If you remove the ng change the droplist is displayed. Help me out.

This is my html

<div ng-app="HelloApp">
  <div ng-controller="MyCtrl">
    <p>Term</p>
    <select ng-model="bob" ng-change="test()" ng-options="x for x in nos">

    </select>
  </div>
</div>

And this is my js script

**var app = angular.module('HelloApp', []);  
app.controller('MyCtrl', function($scope) {
console.log('ctrl working');
    $scope.test = function () {
     nos=["5", "10", "15"];**
     var kill=$scope.bob;
     alert ("changed!"+ kill); 
    }

});

I am new to angular and internet searches only land to complex arrays not a simple one. Please help

3 Answers 3

1

Change your script to the following :

var app = angular.module('HelloApp', []);  
app.controller('MyCtrl', function($scope) {
console.log('ctrl working');
$scope.nos=["5", "10", "15"];
    $scope.test = function () {

       var kill=$scope.bob;
       alert ("changed!"+ kill); 
    }

});

Things to note :

-The nos must be declared into the controller scope , previously it was not visible to the view. -It should be out of the test function.

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

Comments

1

See this - fiddle

$scope.nos=["5", "10", "15"];
$scope.bob="";
$scope.test = function () {
   alert($scope.bob);

}

1 Comment

hey got it, thnks
0

Just a Bit change , nothing major

app.controller('MyCtrl', function($scope) {
$scope.nos=["5", "10", "15"];
    $scope.test = function (x) {
     alert (x); 
    }
});

HTML

<select ng-model="bob" ng-change="test(bob)" ng-options="x for x in nos">

Thanks

1 Comment

ya, got it, thnks for answering so fast

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.