Search code examples
javascriptangularjsangularjs-directiveng-bind

How to bind return function to markup angular


<li ng-click="toggleTables('all')" class="active">
    <span>All Tags (getTotal('allTerms'))
        <span ng-bind="getTotal('allTerms')"></span>
    </span>
</li>

I'm trying to get the returned value from the function getTotal to show up in the markup, however the value is not showing up, the function is below:

function getTotal(key) {
    console.log('getTotal',key);
    return totals[key].totals; // 33
}

Solution

  • Are you using a controller?, if that is the case why don't you use a variable instead like this

    $scope.total = 0;
    function getTotal(key) {
        $scope.total = totals[key].totals; 
    }
    
    <span ng-bind="total"></span>