How to get URL parameter with AngularJS. If anyone has an example I would appreciate it.
$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';
}],
}
})
});