Calling function without using ng-click inside ng-repeat- AngularJS


I have following code:

<div ng-repeat="dateDetails in visitsDates | orderBy : | filter : contactid | limitTo : 1">
        <td>Joint Work</td>
        <td><a href="" ng-click="gap(">Click Me</a></td>

in above code, I have put ng-click, after which the function is called. But the function has to be called by default so as to populate one of the columns, which is not happening. the function 'gap' sets $ to the difference between today's date and the date passed to it. How should I fix the problem?

Problem courtesy of: Ru11


If you have to do it with markup you can use ng-init

Also, from the same link, can't you set up initial value using your controller?

Solution courtesy of: Darshan Joshi


I achieved this function call inside ng-repeat by using ng-init

<td class="lectureClass" ng-repeat="s in sessions" ng-init='presenters=getPresenters('>
      <div class="presenterClass" ng-repeat="p in presenters">

The code on the controller side should look like below

$scope.getPresenters = function(id) {
    return SessionPresenters.get({id: id});

While the API factory is as follows:

angular.module('tryme3App').factory('SessionPresenters', function ($resource, DateUtils) {

        return $resource('api/session.Presenters/:id', {}, {
            'query': { method: 'GET', isArray: true},
            'get': {
                method: 'GET', isArray: true
            'update': { method:'PUT' }
Discussion courtesy of: Sacky San

This recipe can be found in it's original form on Stack Over Flow.