URL with string parameters with angular.js

3

I would like to know the best way to treat url with string parameters in angular.js.

When accessed:

www.app.net/nomeDaPessoa/ServicoDaPessoa

It would respond to a given route that is receiving nomeDaPessoa and ServicoDaPessoa as a parameter.

Another example would be:

www.app.net/nomeDaPessoa

In this case, you will receive the name of the Person!

I use Node.js with Express.js to deliver the files.

    
asked by anonymous 25.02.2015 / 13:31

2 answers

1

In Express.js you can use parameters like this:

app.get('/:nomeDaPessoa?/:ServicoDaPessoa?', function(req, res){

and then get these parameters via req.params . That is:

var nome = req.params.nomeDaPessoa;
var servico = req.params.ServicoDaPessoa;
    
25.02.2015 / 13:37
1

I was able to solve my problem but I do not think it's the best way! Based on the response of Sergio and Rafael I created an algorithm:

When accessed via URL in the node I created the route that receives these parameters and saves the id of them as follows:

router.get('/:nomeDaPessoa?/:ServicoDaPessoa?', function(req, res){
    var nome = req.params.nomeDaPessoa;
    var servico = req.params.ServicoDaPessoa;
    serviceController.getByUrl(nome, servico, function (data){
        req.session.serviceUrl = data.data[0].servico_id;
        req.session.professionalUrl = data.data[0].profissional_id;
        res.sendfile(FRONTEND_PATH + '/views/index.html');
    });
});

In the angled front end I created the route to bring the correct view:

.state('service', {
  url: '/:prof/:service',
  templateUrl: function ($stateParams){
    return '/views/detail.html';
  },
  controller: 'DetailController'
});

And in detailController is valid if it is coming from the click on the interface or via URL, so I go to the node and get the id's that are in the session:

if($rootScope.service && $rootScope.service.id){ //clicou em um servico na interface, nesse caso já tenho o id dos elementos!
    $scope.getDetailService($rootScope.service.id);
} else {
    Service.getSession(function(data){ //Vai ao node e pega o req.session
        $scope.getDetailService(data.servico_id);
    });
}

Well as I said I think it's not the best way but solve my problem! if someone else has a better solution let me know! valew

    
02.03.2015 / 15:00