skip to Main Content

I am trying to pass a variable from a table to Form-Modal, hence need a little guidance on snippet. Please refer to the HTLML section.
I need to pass {{rec.sys_id}} into a method as a parameter, which is inside this form-modal:

"myController.displayUserRecord(<rec.sys_id>)"

Please let me know about the approach.
Thank you.

<table>
    <tr ng-repeat="rec in myController.userRecord">
     <td><a ng-href="" target="" data-toggle="modal" data-target="#formUserRecord">Click Here</a></td>
     <td>{{rec.sys_id}}</td>
    </tr>
 </table>


 <div  class="modal fade" id="formUserRecord" tabindex="-1" role="dialog">
    <p>Check your Workday Record:</p>
    <button type="button" ng-click="myController.displayUserRecord(<rec.sys_id>)">Click here </button>
</div>

2

Answers


  1. myController.displayUserRecord(rec.sys_id)
    

    please try this

    Login or Signup to reply.
  2. To pass the rec.sys_id value from the table to the displayUserRecord method in the form modal, you can make use of AngularJS data binding. Modify your HTML as follows:

    <table>
        <tr ng-repeat="rec in myController.userRecord">
            <td>
                <a ng-href="" target="" data-toggle="modal" data-target="#formUserRecord" ng-click="myController.setSelectedSysId(rec.sys_id)">Click Here</a>
            </td>
            <td>{{rec.sys_id}}</td>
        </tr>
    </table>
    
    <div class="modal fade" id="formUserRecord" tabindex="-1" role="dialog">
        <p>Check your Workday Record:</p>
        <button type="button" ng-click="myController.displayUserRecord()">Click here </button>
    </div>
    

    In your controller (assuming it’s named myController), you need to define the setSelectedSysId method to set the selected sys_id. You can then use this value in the displayUserRecord method.

    app.controller('MyController', function ($scope) {
        $scope.selectedSysId = null;
    
        $scope.setSelectedSysId = function (sysId) {
            $scope.selectedSysId = sysId;
        };
    
        $scope.displayUserRecord = function () {
            // Access $scope.selectedSysId here in your method
            console.log($scope.selectedSysId);
            // Rest of your logic
        };
    });
    

    This way, when a user clicks on "Click Here" in the table, the setSelectedSysId method will be called, setting the selectedSysId variable. Later, when the user clicks "Click here" in the modal, the displayUserRecord method will be called, and you can access the selected sys_id from the selectedSysId variable in the controller.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search