0

I have a select like this:

<select class="form-control" ng-hide="Catalogos.length==0" ng-change="filtro(selected)" ng-model="selected" ng-options="item.Nombre for item in Catalogos "></select>

From there I get selected value in function like this:

$scope.filtro = function(selected) {
            $scope.selectedID = selected.ID;
        }

There I get Id for selected value, but now I want to send this parameter to another function like:

$scope.insertar = function(selected) {
                $scope.selectedID = selected.ID;
                if ($scope.catalogoid != null) {...

But selected always come undefined

Note: $scope.insertar triggers when I clic submit button

<button type="submit" class="btn blue" ng-click="insertar();">Aceptar</button>

Help is very appreciated! Regards

1
  • 2
    If the <select> and <button> are in the same scope, you can just use ng-click="insertar(selected)" Commented Jul 10, 2017 at 5:49

1 Answer 1

3

You should just use the scope variable in your insertar function, not reassign it. Like this:

$scope.insertar = function() {
    var selectedId = $scope.selectedID; 
    if ($scope.catalogoid != null) {...
Sign up to request clarification or add additional context in comments.

Comments

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.