Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show return value of a function with Angularjs

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

I have a HTML like this.

<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 is properly shown, but b is blank. What am I doing wrong?

like image 267
ironsand Avatar asked Jun 13 '14 23:06

ironsand


1 Answers

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

Try

<p>b: {{ b() }}</p>
like image 52
PM 77-1 Avatar answered Nov 14 '22 02:11

PM 77-1