1

I am using ionic framework for developing my hybrid mobile application and I have to access a content editing page where I need to pass in some values. For this, I have added the parameters in the url in routes.js routing file

.state('editText', {
    url: '/editText/:id/:text/:size',
    templateUrl: 'editText.php',
    controller: 'editTextCtrl'
  })

Now I want to access :id , :text and :size in the content of the page. Can I simply do it by using {id} , {text}, {size} in the content of page or do I need to do something else to make it happen. Please note that at this point I am looking for the fastest and simplest solution to achieve this without caring for security.

Daniel
  • 269
  • 6
  • 16
  • Possible duplicate of [How to extract query parameters with ui-router for AngularJS?](http://stackoverflow.com/questions/19053991/how-to-extract-query-parameters-with-ui-router-for-angularjs) – Lex Mar 23 '16 at 02:44

2 Answers2

1

You can request the URL state parameters using $stateParams. Make sure you inject this into your controller.

Let's say you state url is /editText/:id/:text, then you can request the values from the url in your controller (editTextCtrl) using $stateParams.id and $stateParams.text.

Jur Clerkx
  • 698
  • 4
  • 14
0

change your state as follows,

 .state('editText', {
        url: '/editText',
        templateUrl: 'editText.php',
        controller: 'editTextCtrl',
        params: {
            id:'',
            text:'',
            size:''
        }
      })

You can call the state from controller as follows to pass the parameters,

$state.go('editText',{id:45,text:'some text',size:45});

Then you can get these parameters in the controller as follows,

.controller('editTextCtrl',['$stateParams',function($stateParams){
    console.log($stateParmas.id);
    console.log($stateParmas.text);
    console.log($stateParmas.size);
}]);
Venu prasad H S
  • 231
  • 1
  • 8