JeroenJK JeroenJK - 6 months ago 30
AngularJS Question

Angular stateParams to controller, $urlRouterProvider

I'm building an app with Ionic and AngularJS.

Now I have a page with a list of items. Each item has an ID, and so a click results in something like this:




where 1 and 2 are ID's.

Now I have the default state like this, for the homepage with this list:

.state('app.home', {
url: "/home/",
views: {
'menuContent': {
templateUrl: "app/home.html"
controller: 'HomeCtrl'


What I want is to pass the paramater to the controller. What I found is the following solution, but this isn't working. The reason is that it doesn't know which controller to use (in above example,
is specified.).

.state('app.item', {
url: "/item/:id",
views: {
'menuContent': {
templateUrl: "app/item.html"
controller: function($scope, $stateParams) {
$ = $;


As you can see
now has a function, but where do I specify the actual controller to use?
Also, is this the right way or is there a better/easier way?

    [       '$scope','$stateParams'
    function($scope , $stateParams ) {    
        $ = $;

In $ , id will be name of parameter you define in url(:id).