Dj Genexxe
Dj Genexxe

Reputation: 27

angular js expressions not working

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 {{ }}.

Upvotes: 0

Views: 78

Answers (2)

shaunhusain
shaunhusain

Reputation: 19748

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).

Upvotes: 0

user3227295
user3227295

Reputation: 2156

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

Upvotes: 2

Related Questions