Service Portal : Need to pass the value from one widget to another widget

raja_5
Tera Expert

Hi Experts,

 

I have a value in main widget which needs to be passed to another widget when I'm clicking on a button 

 

HTML : 

<button type="button" data-toggle="modal" data-target="#mydeletionModal" class="button-custom-2 btn-danger" ng-click="c.getAccountDetails(accNm)"><i class="fa-solid fa-trash"></i> Delete Selection</button>

 

below is the function in main widget 

Client controller : 

$scope.getAccountDetails = function(accNm) {
        $scope.showTab1Info = true;
        c.server.get({
            accountNm: accNm
        
        }).then(function(r) {
            //console.log("account details:" + r.data.accountDetails);
            $scope.accountDetails = r.data.accountDetails;
            alert('print accNm'+accNm);            [ accNm is the value]

        });
    };
1 ACCEPTED SOLUTION

Hi @raja_5 ,

 

it seems like there may be some issues with how you're trying to display the value in the second widget.

Here's how you can modify your code to pass the value from the main widget to the second widget:

 

In the main widget:

// client script
$scope.getAccountDetails = function(accNm) {
  c.server.get({
    accountNm: accNm
  }).then(function(r) {
    $rootScope.$broadcast('getaccount', accNm);
    $scope.accountDetails = r.data.accountDetails;
  });
};

 

In the second widget:

// client script
$scope.showaccount = {};
$scope.$on('getaccount', function(event, accNm) {
  $scope.showaccount.accNm = accNm;
});

 

In the second widget's HTML, you can display the value like this:

<label for="account-name">Account Name</label>
<input type="text" ng-value="showaccount.accNm">

 

Thanks,

Ratnakar

View solution in original post

5 REPLIES 5

@Ratnakar7

 Thank you for you help