0
How to get parameter of the URL with Angularjs. If anyone has any example I thank.
$scope.pegaCNPJ = function () {
var cnpjs = $("#prospectCNPJ").val().replace(/[^\d]+/g, '');
$.post('models/verificaCliente.php', {prospectCNPJ: cnpjs}, function (retorno) {
console.log(retorno);
$scope.dados = retorno;
if (retorno.length > 0) {
$('#processando').show();
$timeout(function () {
$state.go('cadOportunidade', {id: retorno});
}, 3000);
} else {
$http.jsonp("https://www.receitaws.com.br/v1/cnpj/" + cnpjs, {jsonpCallbackParam: 'callback'}).then(function (response) {
$scope.valor = response;
});
}
});
};
angular.module('App').config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.hashPrefix(''); // by default '!'
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'views/dashboardAdmin.php',
controller: 'AppCtrl',
resolve: {
'title': ['$rootScope', function ($rootScope) {
$rootScope.title = 'Home';
}],
}
})
.state('dashboardAdmin', {
url: '/dashboardAdmin',
templateUrl: 'views/dashboardAdmin.php',
controller: 'AppCtrl',
resolve: {
'title': ['$rootScope', function ($rootScope) {
$rootScope.title = 'Dashboard';
}],
}
})
.state('cadProspect', {
url: '/cadProspect',
templateUrl: 'views/cadProspect.php',
controller: 'AppCtrl',
resolve: {
'title': ['$rootScope', function ($rootScope) {
$rootScope.title = 'Cadastro Prospect';
}],
}
})
.state('cadOportunidade', {
url: '/cadOportunidade/:id',
templateUrl: 'views/cadOportunidade.php',
controller: 'AppCtrl',
resolve: {
'title': ['$rootScope', function ($rootScope) {
$rootScope.title = 'Cadastro Oportunidade';
}],
}
})
});
See if it helps: https://answall.com/questions/274553/geteven%C3%A2metro-da-url-via-Angularjs
– Vinícius