- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 03:48 PM
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>
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 02:44 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 08:45 PM
Hi David,
have you tried putting ng-if and the condition will be triggered by the broadcast function of the other widget?
Regards
Prasun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 01:11 PM
Hi Prasun, thanks for the response. The event is triggering ok as is, it's just that the widget is not being updated. Kinda like the inner function doesn't have scope access to c.container
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2018 02:44 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2018 11:55 AM
Much thanks ChrisB, that did the trick!!