Answer the question
In order to leave comments, you need to log in
Angular + Laravel how to get id from browser string?
I am writing a small Laravel + Angular application.
Application pages are handled by Angular, Laravel provides "API"
There is a controller that displays a record from the database by id
<?php
class ShowOneWorkpeopleController extends BaseController {
public function showOneWorkpeople($id) {
$id = (int)$id;
$workpeople = Workpeoples::showOneWorkpeople($id)->toJson();
return $workpeople;
}
}
Route::get('api/ShowWorkpeople/{id}', '[email protected]');
crmApp.controller('CrmWorkPeopleShowController', ['$scope', function($scope,$http){
$scope.watispage = 'Сотрудник';
$http.get('api/ShowWorkpeople/???').then(
function(result){
$scope.workpeople = result.data;
}
)
}]);
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', {
controller: 'CrmWorkPeopleShowController',
templateUrl: './templates/workpeopleShow.html'
})
}]);
Answer the question
In order to leave comments, you need to log in
are you using ngRoute?
crmApp.controller('CrmWorkPeopleShowController', ['$scope', '$http', '$routeParams', function($scope, $http, $routeParams){
$scope.watispage = 'Сотрудник';
$http.get('api/ShowWorkpeople/' + $routeParams.id).then(
function(result){
$scope.workpeople = result.data;
}
)
}]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question