sputil.get()

David Pichard
Mega Guru

Hi all, I'm trying to dynamically load widgets in service portal based on a broadcast event. I am unable to get the following code to load a widget. The "broadcast" and "on" functions work as expected as I can log the actual string value of the widget to load. I can also log the get() functions response which is an object, I just can't load the new widget into the container. Any ideas?:

//Client script:
$rootScope.$on('updateWidget', function (event, widget) {
  spUtil.get(widget).then(function(response) {
    c.container = response;
  });

});

 

//HTML:
<div>
<sp-widget widget="c.container"></sp-widget>
</div>

1 ACCEPTED SOLUTION

I believe the scope does change if you console.log out the widget info. However, it doesn't apply the newly suggested widget. 
One way around this is to use an array. For example:
Client Script:


$rootScope.$on('updateWidget', function (event, widget) {
  spUtil.get(widget).then(function(response) {
    c.containers = [response];

});

HTML:

<div ng-repeat="container in c.containers">
    <sp-widget widget="container"></sp-widget>
</div>

The ngRepeat directive will now update the view as the array changes, albeit just one item.

 

View solution in original post

6 REPLIES 6

Thanks a lot!

I'm glad I was able to help.