- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 10:54 AM
Hi experts,
I'm starting with Widgets and I'm need to pass a value from the spModal to the widget, I'm trying the "widgetInput" parameter, for example:
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 08:20 PM
Hi @dgarnica ,
One possible solution is to use the $scope property named "widget_parameters". If you add a property called "shared" to the object passed to the spModal.open() method, it will be added to the widget_parameters property on the current widget $scope and it will be accessible in both the modal and the calling widget.
Here is a basic example:
Widget that opens the spModal
HTML:
<div>
<h3>
Hello
<span ng-hide="c.MySharedVar.person">_______</span>
<span ng-show="c.MySharedVar.person" class="text-success">{{c.MySharedVar.person}}</span>
!
</h3>
<button class="btn btn-default" ng-click="c.openModal()">
Get Person
</button>
</div>
Client Controller:
api.controller=function($scope, spModal) {
var c = this;
c.MySharedVar = {
"person":"",
};
c.openModal = function() {
spModal.open({
"title":"My First Widget",
"shared": c.MySharedVar,
"widget": "my-first-widget",
"size":"md",
buttons:[
{"label":"Cancel", "cancel":true},
{"label": "Ok", "primary":true}
],
});
}
};
Widget appearing in the modal (my-first-widget)
HTML
<div>
<form>
<div class="form-group">
<label for="FirstInputPerson">Who Am I</label>
<input id="FirstInputPerson" class="form-control" ng-model="c.MySharedVar.person">
</div>
</form>
</div>
Client Controller
api.controller=function($scope) {
var c = this;
c.MySharedVar = $scope.widget_parameters.shared;
};
Rendered Demo:
Pass object from Modal back to Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:45 PM
Hi @ChrisBurks
I achieved the decision based with a ternary condition in the "ng-click" attribute of the button, getting the result from the function called at the first time and setting a close action in case of a specific result.
I'll try other use case with the $scope function that you're sharing as example.
Thanks a lot for the help.