Noobish Noobish - 5 months ago 46
AngularJS Question

Passing data attributes with ui-sref

I want pass some extra data into the controller from

. I am looping a json object and adding data to the sref:
<a data-imgName="{{ }}" data-imgDesc="{{ img.desc }}" ui-sref="main.imgDesc({imgid: '{{ }}'})">

$stateProvider.state('main.imgDesc', {
url: '/image/:imgid',
templateUrl: '...',
controller: 'ImageDescCtrl'

I want
into the controller. I have checked
but its not found in it. Is there any way?


We should use params : {} to declare any kind of parameter, even complex object:

$stateProvider.state('main.imgDesc', {
    url: '/image/:imgid',
    templateUrl: '...',
    controller: 'ImageDescCtrl',
    params: {
       imageData: null,

And we are ready to pass those

ui-sref="main.imgDesc({imgid:, imageData: img })"

and controller can ask for $stateParams where both will be available (if passed as above)