1
I have the following heading structure at the angle:
.when('/', {
redirectTo: '/pages/signin'
})
.when('/:page', { // we can enable ngAnimate and implement the fix here, but it's a bit laggy
templateUrl: function($routeParams) {
return 'app/views/pages/'+ $routeParams.page +'.html';
},
resolve: function($routeParams) {
return {deps: app.resolveScriptDeps(['js/controller.'+$routeParams.page+'.js'])};
},
controller: 'Dash'
})
It works very well, locates the html files according to what is passed in the URL
In my route.php file, I have this route:
Route::controller('api/usuarios', 'UsuariosController');
In the User I have the following method:
public function getDados(){
return Response::json([
'id' => '1',
'texto' => 'TESTE TESTE ETSTE'
]);
}
In my angular controller, I have this method:
$scope.getDados = function(){
$http.get('api/usuarios/dados').
success(function(data, status, headers, config) {
console.log('DATA', data);
}).
error(function(data) {
});
}
$scope.getDados();
Only when I call this angular method, it gives me a 404 error
Any hint of what might be happening?
What would that be
/dados
in his$http.get('api/usuarios/dados')
, would not beget-dados
?– Ivan Ferrer
If you are calling a json output, it has no purpose to load an html.
– Ivan Ferrer
So, but I don’t want to call an html, I want to get this JSON just
– Daniel Swater
when you send this url manually, what happens? api/users/data
– Ivan Ferrer
I get this error: Not Found The requested URL /Laravel/api/users/get-data was not found on this server.
– Daniel Swater
so the problem is that there is no such route. But what about this one? /Standard/api/users/data
– Ivan Ferrer
take a look here: http://laravel.com/docs/5.1/testing#testing-json-Apis
– Ivan Ferrer
So, give me the same error
– Daniel Swater
Just to top it off, I use Laravel 4
– Daniel Swater
Dude, the exit route to json is in the Aravel.
– Ivan Ferrer
http://laravel.com/docs/4.2/eloquent#Converting-to-arrays-or-json Response:json($someArray) Return $model->toJson(); you don’t have to set anything at the angle unless you are doing Restful output of the js angular api.
– Ivan Ferrer
http://fdietz.github.io/recipes-with-angular-js/consuming-external-services/consuming-restful-apis.html
– Ivan Ferrer
When so, you will have a whole rule of use. https://docs.angularjs.org/api/ngResource/service/$Resource
– Ivan Ferrer
Execute the command
php artisan route:list
at the root of your project and check that the "api/users/data" route is in the list.– Ademir Mazer Jr - Nuno