Put $ scope data as input value to save it in database

1

I have a problem trying to pull a $ scope data and insert it as value in input.

This value is determined from a select that is part of my form code. The select that determines is "Resource" and I put condition that if it is "Municipal" I pull a data from a $ scope function and put it as value in the input and then that value is saved in a database, but I do not achieve make it appear from the $ scope is reflected in the input.

Could you please help me?

FORM

<form ng-submit="registrar()" >    
    <div class="form-group col-sm-1">
        <label for="ID">ID</label>
        <input type="text" class="form-control" ng-model="IDObra" >
    </div>
    <div class="form-group col-sm-2">
        <label for="Recurso">Recurso</label>
        <select ng-model="recurso" class="form-control" name="recurso">
            <option ng-value="Municipal" >Municipal</option>
            <option id="dos" ng-value="Estatal">Estatal</option>
            <option id="dos"ng-value="Federal">Federal</option>
        </select>
    </div>  
    <div class="form-group col-sm-2" >
        <label for="numObra">No. Obra </label>               
        <input type="text" class="form-control" ng-if="recurso == 'Municipal'" ng-model="numObra" ng-init="value='{{numero}}'"> 
    </div>

angular driver

var empleadoControllers = angular.module('empleadoControllers', []);

empleadoControllers.controller('EmpleadoListadoCtrl', ['$scope','$http', function ($scope, $http) {
    numero();
    empleados();
    profesiones();


    function numero(){
        $http.get('http://localhost:8888/base2/api/?a=numero').then(function(r){
            $scope.numero = r.data;            
        });
    }   
    function empleados(){
        $http.get('http://localhost:8888/base2/api/?a=listar').then(function(r){
            $scope.model = r.data;
        });
    }   
}
    
asked by Carlos Mendoza 20.02.2017 в 17:54
source

1 answer

1

You must read more about angular, when you declare an input with ng-model="example" the value of the example will be shown in the input, it is the equivalent to perform the following with html

<input name="ejemplo" id="ejemplo" value="{{ejemplo}}">

for practical purposes to make it work you should do something like

 $scope.numObra = numero;
    
answered by 21.02.2017 / 22:27
source