user584018 user584018 - 1 year ago 83
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download