0

I have this lines ofcode in my HTML,

<div ng-app='myApp' ng-controller='myCtrl'>
    <h5 style="margin: 0;">As of {{ date-today }}</h5>
</div>

In my JS,

angular.module('myApp', [])
.controller('myCtrl', ['$scope', '$compile', '$http', function($scope, $compile, $http){
    var today = new Date();
    $scope.date_today = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    initTables($scope, $compile);
}

It is not working. It displays {{ }}.

3

2 Answers 2

2

change "date-today" to "date_today" like in the $scope.

Sign up to request clarification or add additional context in comments.

Comments

0

angular.module('myApp', [])
.controller('myCtrl', function($scope, $compile, $http){
    var today = new Date();
    $scope.date_today = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    //initTables($scope, $compile);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="myCtrl">
    {{date_today}}
  </div>
</div>

Seems to work fine to me make sure you have date_today in both places in JS it's going to see the - as a minus and not parse it you should have had a syntax error I believe (with $scope.date-today, $scope['date-today'] may have worked but still not ideal IMO).

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.