Pass data from widget to an embedded widget

Tommy Jensen
Giga Guru

I have a widget that display a set of items in an ng-repeat. Within those blocks I want to embed another widget and pass a unique sysid to this child widget. I have tried with the options parameter on the widget directive. And it works sort of. The problem is that all the child widgets get the same sysid passed even though I know what I try to pass is unique. All the child widgets displays the last sysid.

Anybody know how to do this?

1 ACCEPTED SOLUTION

sndangibbard
Mega Guru

It sounds like you might have an issue with your loop, can you post your HTML template an example of the data you are looping through?


View solution in original post

5 REPLIES 5

ChrisBurks
Mega Sage

There are a few ways to do this. Have you tried any of the ways here:


https://serviceportal.io/docs/documentation/widget_embedded.md  


sndangibbard
Mega Guru

It sounds like you might have an issue with your loop, can you post your HTML template an example of the data you are looping through?


The issue was the way I imbedded the widget. I did it with variable subsitution to add the options within the html. When I initialized it from the server script instead then it worked.


Moon1
Giga Contributor

Hi, Tommy,

 

Could you share your resolution to achieve the issue?

I can't figure out how to pass a dynamic data in a loop on the parent widget to the embedded widget.

1. Here is my parent Widget HTML

<div class="panel panel-primary">
<div class="panel-heading">Suggested for you</div>
<div class="panel-body">
<div class="col-sm-6" ng-repeat="item in data.items ">

<h2 class="h4 m-t-none m-b-xs text-overflow-ellipsis" title="{{::item.name}}">{{::item.name}}</h2>
<widget id="user-favorite" options='{ "category": "SR", "sysid": "SYSID"}'></widget>

<div class="text-muted item-short-desc">{{::item.short_description}}</div>

<button type="button" class="btn btn-default"> <a href="?id=sc_cat_item&sys_id={{item.sys_id}}" class="pull-left" tabindex="-1">${Request}</a></button>
</div>
</div>
</div>

 

where I would like to pass 'sysid' property on the options as {{item.sys_id}},rather than a fixed 'SYSID'. It bumped out when I use 

<widget id="user-favorite" options='{ "category": "SR", "sysid": {{item.sys_id}}}'></widget>

I tried few different syntax to escape to pass JSON object through 'options'.

 

Appreciate your help in advance.

 

Moon 1