0

I´m working in Angular and I have fields to fill like

I fill my select list as:

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

I want to know how can I pass selected Value into url in my funcion:

     function actualizar(vehiculo) {
                $scope.vehiculo.Origen = $scope.usuario.Origen;
                $scope.vehiculo.Version = $scope.Version;

                apiService.post("../../api/AddCatalogoRegistro/" + selected.ID,
                    function(res) {
                  // my code

How can I pass that selected value as a selected.ID, chrome console throw me

ReferenceError: selected is not defined

View:

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

  <option></option>
</select>
3
  • 2
    It should be $scope.selected Commented Apr 18, 2017 at 20:11
  • I try it but I get , [object%20Object] @PankajParkar Commented Apr 18, 2017 at 20:19
  • Can you please provide a working code example on jsFiddle or plnkr? Commented Apr 18, 2017 at 20:25

1 Answer 1

2

Use $scope.selected as ng-model value

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

It should solve your problem. And the best practise is to name the controller and use ng-model = "ctrlName.selected"

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.