calling widget without mentioned in script in portal

sainath3
Mega Guru

Hi Team,

 

I am unable to find where the widget is calling from another widget.

 

widget 1:

 

HTML:

<div>
<!-- your widget template -->
<div class="banner">
<div class="title">
${Hello} {{::data.username}}
</div>
<ul>

<div ng-repeat="obj in data.ct track by $index">
<li title="{{obj.title}}" ng-if='obj.condition=="true"'><a href="#flag={{obj.label}}" ng-class="{'highlight':c.selected == obj.passing }" ng-click="selectnew(obj.passing)">{{ obj.label}}</a></li>

</div>
</ul>
<div class="search">
<widget id="search"></widget>
</div>
</div>
</div>

 

Client script:

function($rootScope,$scope,$timeout,$window) {

  /* widget controller */

  var c = this;
   
      $scope.selectnew = function(selection){
            //alert("hello");
  c.selected = selection;
  $rootScope.$broadcast('showHideWidget1', selection);

  };
}
Server Script:
 
(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
data.username=gs.getUser().getFirstName().toString();
    data.title1="new data";
    data.cbm=false;
    if(gs.hasRole('admin')){
        data.cbm=true;
    }
   
    data.ct = [

        {
            "label": "new data request",
            "url": "new_data&flag=data Request",
            "icon": "chevron-right",
            "passing": "new",
            "title":data.title1,
            "cssClass": "",
            "condition":(data.cbm)?"true":"false"
        }];
})();
---
widget 2:
HTML:
<div ng-if="showWidget == 'new'">
<h1>hello</h1>
</div>
 
Client Script:
function($scope, $rootScope, $location, spUtil, $timeout, spAriaFocusManager, $window) {
   

     $scope.showWidget = "";
   
    //$scope.$on('data_table.click', callDataClick);
   
    $rootScope.$on('showHideWidget1', function(event,data) {

  $timeout(function(){

            $scope.showWidget = data;

  });

  });
};
 
Note: I didn't find any Event name with "showHideWidget1"
Question: can anyone tell me how  widget 2 is calling from widget 1 ?

 

1 ACCEPTED SOLUTION

Using $rootScope.$on

View solution in original post

3 REPLIES 3

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @sainath3 ,

<widget id="search"></widget>

 

This line in the HTML is calling another widget.

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍!

 

Thanks,

Alka

 

Thanks for the reply Alka.

My question is from my code how is widget2 calling from widget 1?

Using $rootScope.$on