- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:07 AM
I have a widget that has an option, called "message". In one place, I have embedded this widget in another widget. I have created an option called "message" on the parent widget.
How do i link the parent widget's option to the embedded widget?
The solution is this:
function(spUtil) { /* widget controller */
var c = this;
spUtil.get("custom-search-page", {message: c.options.message}).then(function(response) {
c.data.parentMessage = response.options.incident_message;
c.data.parentMessageFlag = 'true';
});
}
I'm not positive i understand exactly what is happening, but it's behaving the way i want it to.
The widget im using is embedded sometimes, and not at other times. The widget is a button with a string of text above it. I set the value of that string with instance options. I wanted to be able to set that text even when it's embedded in this widget.
from what i understand, the SPutil gets the message i ask for from the widget i specify, and returns a promise. When the promise comes back, i set a data paramenter to equal the response field, and set a flag to true.
in my server script i check to see if the flag is true. if it is, I display the parent message. otherwise i use the one local to the widget.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:12 PM
You can use the following in your server script:
data.widget = $sp.getWidget("widget-id", options);
The second parameter is the object being passed in to the widget, so this should pass all available "options" on the first widget in to the embedded widget. I haven't tested this, but 99% certain it'll work.
And then all you have to do is display the widget in your HTML:
<sp-widget widget="data.widget"></sp-widget>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:12 AM
Hi Andrew,
I'm no AngularJS expert, but have you tried using a $rootScope property?
You might also be able to use $on and $broadcast to communicate between the two widgets. I did something like that here:
Live Coding Happy Hour Recap 2017-03-03: Inter widget communications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:26 AM
There's a way to use spUtil to do this, but I don't know what it is. That's what i'm looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:30 AM
Perhaps nathanfirth knows the spUtil method...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:33 AM
You know, I was going to tag him, but I do so often...
