One way would be to use ngRoute . Through $routeProvider
you can configure your site's routes, and thereby extract the parameters from the URLs and inject them directly into your controller.
That is:
var myApp = angular.module('app', ['ngRoute']); // adicione o ngRoute como modulo do seu modulo
myApp.config(function($routeProvider) {
// indica que quando tiver uma URL do tipo http://localhost/[id], que deve utilizar este template e controlador
$routeProvider.when('/:id', {
templateUrl: '[caminho para a sua pagina HTML]',
controller: 'Controller' // nome do seu controlador
});
})
myApp.controller('Controller', function ($scope, traineeControlService, $routeParams) {
var vm = this;
//getAll();
$scope.numberOfregistrationUser = {};
// var searchObj = $location.url();
console.log($routeParams.id);
}
The $routeParams
object contains all the parameters defined in the URL (note when the URL is configured, the use of :
to indicate that it is a parameter that should be read).