Anup
Anup

Reputation: 9738

AngularJS - Call function in HTML

I have made a function getAge() in my custom.js. This function needs to be called in my HTML page.

So what i tried is like this :-

<td>{{getAge(user.basicinformation[0].dateofbirth)}}</td>

I can see no results.

How to call function in HTML?

Upvotes: 23

Views: 90670

Answers (2)

Nitish Kumar
Nitish Kumar

Reputation: 4870

So create a filter for getAge.

app.filter("getAge", function(){
   return function(input){
      // Your logic
      return output; 
   }
});

Then call it in HTML:

<td>{{ user.basicinformation[0].dateofbirth | getAge }}</td>

Upvotes: 40

BlinkyTop
BlinkyTop

Reputation: 1144

Attach getAge and user to the $scope of the pages controller.

$scope.user = user;
$scope.getAge = getAge;

Make sure you're doing this in the controller and setting up the controller correctly. It won't work unless you've set up a controller with this DOM view and injected the $scope service into the controller.

Upvotes: 25

Related Questions