0

I have this code generated by laravel partial view...

<div ng-controller="viajeController">
<ul class="nav nav-pills">
    <li><a href="#/">Volver</a></li>
</ul>

    <div class="col-xs-4">
        <h3>Horario de Salida:</h3> 
        <select class="form-control" name="sel_horario" ng-model="hora" ng-options="hora.hora_inicio for hora in horarios | orderBy: 'id'" id="sel_horario" ></select>
    </div>
    <div class="col-xs-8">          

        <fieldset>
            <legend>Asignar Vehiculo </legend>

            <table class="table table-hover">
                <thead>
                    <th>Seleccione</th>
                    <th>Placa</th>
                    <th>Numero Interno</th>
                    <th>Tipo Vehiculo</th>
                </thead>
                <tbody>
                    <tr ng-repeat="vehiculo in vehiculos">
                        <td>
                            <a href="" ng-click="solicitaDespacho(<% vehiculo.id %>)">Seleccionar</a>
                        </td>
                        <td><% vehiculo.placa %></td>
                        <td><% vehiculo.numero_interno %></td>
                        <td><% vehiculo.tipo_vehiculo %></td>
                    </tr>
                </tbody>

            </table>

        </fieldset>

    </div>
</div>

all under the controller "viajeController" this is the code:

app.controller('viajeController',function ($scope, $location, viajeFactory){

$scope.horarios = viajeFactory.horarios;
viajeFactory.async().then(function(d){
    $scope.vehiculos = d;
});

$scope.solicitaDespacho = function(idVeh){
    var urlPost = '/asignarVehiculo';
    var idHora = $("#sel_horario").val();

    if (idHora != 'undefined' && idHora != '?'){
        urlPost = '/addViajeData/'+idVeh;   
    }else{
        alert('Debe seleccionar un horario de salida.');
    }

    $location.path(urlPost);

};
});

viajeFactory is OK, but when I click on <a href="" ng-click="solicitaDespacho(<% vehiculo.id %>)">Seleccionar</a> put a error in console:

undefined is not a function

Why not found a "solicitaDespacho" function on $scope??

2 Answers 2

3

change this

<a href="" ng-click="solicitaDespacho(<% vehiculo.id %>)">Seleccionar</a>

to

 <a href="" ng-click="solicitaDespacho(vehiculo.id)">Seleccionar</a>
Sign up to request clarification or add additional context in comments.

3 Comments

Also, you did not include enough HTML to verify that you are actually attaching your controller to the DOM properly. Make sure you have an ngController directive somewhere in your HTML above this ngRepeat that actually uses viajeController in the first place!
sorry I dont't say I change {{ for <% because I use laravel with blade, so ng-repeat generate a good html solicitaDespacho(1), solicitaDespacho(2).. etc, but when I click say undefined
works but with ng-click="solicitaDespacho(vehiculo.id)" Thanks
0

You missed the ; after the closing bracket of the function.

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.