Answer the question
In order to leave comments, you need to log in
Angular + Laravel Get Request Validation?
There is a small application in Angular + Laravel.
There is an Angular application config
crmApp.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
controller: 'CrmIndexController',
templateUrl: 'templates/crmIndex.html'
})
.when('/workpeople', {
controller: 'CrmWorkPeopleIndexController',
templateUrl: 'templates/workpeopleIndex.tpl.html'
})
.when('/workpeople/show/id/:workerId', {
controller: 'CrmWorkPeopleShowController',
templateUrl: './templates/workpeople-show.tpl.html'
})
.when('/workpeople/edit', {
controller: 'CrmWorkPeopleEditController',
templateUrl: './templates/workpeopleEdit.html'
})
.when('/workpeople/delete', {
controller: 'CrmWorkPeopleDeleteController',
templateUrl: './templates/workpeopleDelete.html'
})
.when('/map', {
controller: 'CrmMapController',
templateUrl: './templates/mapIndex.html'
}).otherwise({
redirectTo: '/'
});
}]);
crmApp.controller('CrmWorkPeopleShowController', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) {
$scope.watispage = 'Сотрудник';
$scope.workerId = "api/workpeople/id/" + $routeParams.workerId;
$http.get($scope.workerId).then(
function (result) {
$scope.workpeople = result.data;
}
)
}]);
Answer the question
In order to leave comments, you need to log in
Try adding a resolve to the route:
resolve: {
validation: function ($q, $routeParams) {
var deferred = $q.defer(),
id = parseInt($routeParams.id, 10);
if (!isNaN(id)) {
deferred.resolve();
} else {
deferred.reject('VALIDATION FAILED');
$location.path('/login');
}
return deferred.promise;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question