11

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?

1 Answer 1

16

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

Try

<p>b: {{ b() }}</p>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.