Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a function defined in the controller inside of the view?

Tags:

angularjs

I know I can display a scope variable value by doing:

<div> This is my var value: {{myVar}} </div>

Suppose I have this function

$scope.displayVal = function(){
         return myVar+5;
};

Is there a way to call it in a similar way?

like image 371
Phate Avatar asked Dec 20 '22 00:12

Phate


1 Answers

<div>{{displayVal()}}</div>

or

<div ng-bind="displayVal()"></div>

If you use Controller as syntax

<div ng-controller="YourController as vm">
    <div>{{vm.displayVal()}}</div>
</div>
like image 66
Shyju Avatar answered May 20 '23 20:05

Shyju