Load radio button value when initializing page in js file

Viewed 21

I have an html form with radio button with angular js.

By default when initializing the page it loads the first selected radio button (ng-checked="$first). Here everything is right as I wanted.

I need to make this selected value (first value selected on the radio button) (in this case cpf)) to be loaded at the top of my page in my js file to follow my logic

Today the value of the radio button in my .js file is only assigned when my ng-click event is fired

<table class="table" ng-if="Profile.a.b.c">
        <thead>
            <tr>
                <th><strong>Select</strong></th>
                <th><strong>Name</strong></th>
                <th><strong>surname</strong></th>
                <th><strong>Cpf</strong></th>
            </tr>
        </thead>
        <tbody>

            <tr ng-repeat="(index, a) in Profile.a.b.c">
                <td style="font-size: 10px">
                    <input type="radio" [(ng-model)]="Profile.rdbuttonagentCpf.cpf" value="{{responsible.cpf}}"
                        ng-click='getResponsible(responsible.cpf)' name="rdcpf" ng-checked="$first" />
                </td>

                <td style="font-size: 10px">
                    {{responsible.name}}
                </td>
                <td style="font-size: 10px">
                    {{responsible.surname}}
                </td>
                <td class="cpf" style="font-size: 10px">
                    {{responsible.cpf}}
                </td>
            </tr>

        </tbody>

JS

 $scope.getResponsible = function (cpf) {
    variable = cpf;

}

I can get the cpf value in my .js file only when it is clicked on the radio button (in the html file), with the ng-click method.

How do I load this value at the top of the page without using the ng-click function

0 Answers
Related