How to show function return value using Angularjs

I am trying to use Angularjs . How can I show the result of a function in a view?

I have such HTML.

 <body ng-controller="fooCtrl"> <p>a: {{ a }}</p> <p>b: {{ b }}</p> </body> 

And javascript for it.

 fooApp.controller('fooCtrl', ['$scope', function ($scope) { $scope.a = 3; $scope.b = function(){ return 4; }; }]); 

a displayed correctly, but b empty. What am I doing wrong?

+7
javascript angularjs
source share
1 answer

b is a function object . To get a result, you really need to call it.

Try

 <p>b: {{ b() }}</p> 
+10
source share

All Articles