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>

and it Charge it with Angular Controller like this:

  function cargarCatalogo() {
            apiService.get("../../api/Catalogo/GetCatalogoPadre/" + $scope.Catalogo + "/",
                null,
                function(res) {
                    $scope.Catalogos = res.data;
                    $scope.selected = $scope.Catalogos[0];
                    $scope.filtro($scope.selected);
                },
                errorCatalogo);
        }

So I have two different context with same view: Create and Edit. If $scope.catalogoid come null I present a Create View and it come with value is an Edit View.

Problem is into Edit View, I want to present a select of actual value of Id instead first value. How can I do that?

Ledwing
  • 311
  • 2
  • 10
  • What is id. Is it an intsance of $scope.Catalogos? – Vivz Jul 14 '17 at 18:08
  • I´m sorry, as you can see I have `$scope.Catalogos[0]`, it get first option of selected, but instead it when Edit View comes I want that `$scope.Catalogos[0]` it´s the value come from database instead [0] @Vivz – Ledwing Jul 14 '17 at 18:11
  • Where are you capturing this id in your code? – Vivz Jul 14 '17 at 18:12
  • Something similar here: https://stackoverflow.com/questions/40726299/how-to-auto-selected-value-angularjs/40726509#40726509 and here: https://stackoverflow.com/questions/18194255/how-to-have-a-default-option-in-angular-js-select-box – lealceldeiro Jul 14 '17 at 18:13
  • 1
    Possible duplicate of [How to have a default option in Angular.js select box](https://stackoverflow.com/questions/18194255/how-to-have-a-default-option-in-angular-js-select-box) – lealceldeiro Jul 14 '17 at 18:14
  • what is the typeof `$scope.Catalogos` an array object or just array? – Arigi Wiratama Jul 14 '17 at 18:15
  • I have it into antoher parameter `$scope.catalogoPadre` @Vivz – Ledwing Jul 14 '17 at 18:15
  • `$scope.Catalogos = [];` is an array @ArigiWiratama – Ledwing Jul 14 '17 at 18:15
  • You just have to do $scope.selected = $scope.Catalogos[$scope.catalogoPadre]; – Vivz Jul 14 '17 at 18:17

0 Answers0