Reputation: 50
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??
Upvotes: 0
Views: 644
Reputation: 16498
change this
<a href="" ng-click="solicitaDespacho(<% vehiculo.id %>)">Seleccionar</a>
to
<a href="" ng-click="solicitaDespacho(vehiculo.id)">Seleccionar</a>
Upvotes: 3