1

I have following code:

<div ng-repeat="dateDetails in visitsDates | orderBy : dateDetails.date | filter : contactid | limitTo : 1">
    <tr>
        <td>Joint Work</td>
        <td>{{dateDetails.joint_work}}</td>
    </tr>
    <tr>
        <td>Gap</td>
        <td><a href="" ng-click="gap(dateDetails.date)">Click Me</a></td>
    </tr>
</div>

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 $scope.gap to the difference between today's date and the date passed to it. How should I fix the problem?

1
  • I suggest to pre-manipulate visitsDates, use Array#map Commented Jun 12, 2014 at 6:39

2 Answers 2

4

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Darshan, it worked using ng-init.. thank you so much :)
-2

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

<td class="lectureClass" ng-repeat="s in sessions" ng-init='presenters=getPresenters(s.id)'>
      {{s.name}}
      <div class="presenterClass" ng-repeat="p in presenters">
          {{p.name}}
      </div>
</td> 

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' }
        });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.