Reputation: 4050
I have a function in angular:
$scope.getSessionsForSpeaker = function (id) {
$scope.id = id;
$scope.getAll = SessionService.getAll();
$scope.sessionsFound = [];
$scope.getAll.$promise.then(function(data) {
for (var i = 0; i < data.length; i++) {
if ([data[i].speakers[0]] == $scope.id) {
console.log([data[i].subject]);
$scope.sessionsFound += [[data[i].subject] + ", "];
}
}
});
};
and from html i run it by clicking a link:
<a ng-click="getSessionsForSpeaker(speaker.id)"></a>
Is there a way to run this function without clicking? Thank you in advance!!
Upvotes: 1
Views: 7872
Reputation: 4050
I found a solution that worked for me:
<p ng-bind-html="sessionsFound"></p>
Thanks to everyone for contribution!
Upvotes: 0
Reputation: 4290
You can run it from your controller if you know the ID:
$scope.getSessionsForSpeaker(id);
You can use ng-init
to run it when that element loads:
<a ng-init="getSessionsForSpeaker(speaker.id)"></a>
You can also use ng-mouseover
if you want to run it when the mouse is over that element
<a ng-mouseover="getSessionsForSpeaker(speaker.id)"></a>
All depends when you want to run it.
Upvotes: 1