user584018 user584018 - 3 months ago 13
AngularJS Question

ng-bind is not working with function call

I would like to bind current date and time with a span,

<span id="lastUpdated" ng-bind="'loadMessage'"></span>


I returning the value of "loadMessage" from a function, but it's not working,

$scope.loadMessage = updateInfo();

function updateInfo() {
var today = new Date();
return "Last updated " + today.toLocaleString() + ".";
}

Answer

I'm assuming that you wanted to get date value at initial load only. You don't need to have '(single qoute) around your ng-bind expression so that it will take from $scope

<span id="lastUpdated" ng-bind="loadMessage"></span>

Demo Here