sl3dg3
sl3dg3

Reputation: 5190

Calling a function on scope with Expression won't return anything

Given following simple controller:

(function () {
    angular.module('store').controller('CartCtrl', ['$scope', 
            function ($scope) {

        $scope.cartSumFunction = function () {
            return 678;
        };

        $scope.cartSum = 678;

    }]);

})();

If I try to output cartSumFunction with an expression, it fails (nothing is printed):

<div data-ng-controller="CartCtrl">
    <p>{{ cartSum }}</p> <!-- Works! -->
    <p>{{ cartSumFunction }}</p> <!-- Doesn't work, nothing there! -->
</div>

Why does the expression calling a function with a return value not work?

Upvotes: 0

Views: 42

Answers (1)

Raeef Refai
Raeef Refai

Reputation: 1521

try this:

<div data-ng-controller="CartCtrl">
    <p>{{ cartSum }}</p>
    <p>{{ cartSumFunction() }}</p>
</div>

Upvotes: 1

Related Questions