Assuming that this 2 was defined as a route variable
.state('produtoView', {
url: '/produto/:id' ...
You can redeem this id
variable by injecting $stateParams
into your controller and taking the value of the route variable by its name $stateParams.id
.
Take a look at the ui-router documentation, just below it speaks of a new way of searching for the variable in the new versions of the ui-router, so the $stateParams
is deprecated.
I did not put it in the new way because I did not know it either.
Use the $location
service.
For example, for a given URL http://example.com/#/some/path?foo=bar&baz=xoxo
:
var abUl = $location.absUrl(); // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
var url = $location.url(); // => "/some/path?foo=bar&baz=xoxo"
var prot = $location.protocol(); // => "http"
var host = $location.host(); // => "example.com"
var path = $location.path(); // => "/some/path"
var srch = $location.search(); // => {foo: 'bar', baz: 'xoxo'}
In your specific case, $ location.path () will return /app/produto/2
.