Link to home
Start Free TrialLog in
Avatar of Shanmugam Rajagopal
Shanmugam Rajagopal

asked on

Select 1st Row radio button by default and fire ng-click event in angular

I am populating a table by adding first column as radio button. Want to select first row radio button as default and fire the radio button event ng-click.

            
<div class="col-5-md col-lg-8">
            <div class="well well-sm">
                <table id="eventsTable" st-safe-src="vm.AllEmployees" st-table="displayCollection" class="table table-striped">
                    <thead>
                        <tr>
                            <th> </th>
							<th st-sort="EMPLOYEE_ID">EMPLOYEE ID</th>
                            <th st-sort="EMPLOYEE_NAME">EMPLOYEE NAME</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr st-select-row="row" ng-repeat="row in displayCollection">
                            <td><input type="radio" value="false" name="eventsRadio" ng-click="vm.onEventSelection(row)" /></td>
                            <td>{{::row.EMPLOYEE_ID}}</td>
                            <td>{{::row.EMPLOYEE_NAME}}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

Open in new window


Thanks for your help in advance.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Any particular reason you are not linking the Radio to your model?

The bit about firing the ng-click - why not just invoke that function from the controller when the page loads?
Avatar of Shanmugam Rajagopal
Shanmugam Rajagopal

ASKER

Julian,

I had ng-modal for radio but I removed because my first goal was to check the first row by default and display its associated row values to a label.

If you could explain me how to fire ng-click from controller that would be great. I am very new to angular and in learning process.

Thanks for your help in advance
Angular requires a bit of a shift in thinking. Because of the two way binding your application changes from one that is about manipulating the DOM to one that is based on state. You link view elements to the model such that when the model changes your view changes automatically.

When you assign your radio button to the model with ng-model you now link the state of the radio button to the model and vice versa.

When you say you want to fire an ng-click - why - what is it that click function does,
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.