I am working with Angular/CoffeeScript/Rails and I am trying to place the copyright with the current year in the footer.
With JavaScript, I used to do something like this:
<script type="text/javascript">
<!--
var theDate = new Date();
$('.mDate').html('© ' + theDate.getFullYear());
-->
</script>
<span class="mDate"></span>
Here is what I have tried in CoffeeScript - within the mainController.coffee:
# mCopyRight
# ------------------------------------------------------------
$scope.mCopyRight = ->
$scope.theDate = new Date();
$scope.mFullYear = '© ' + theDate.getFullYear();
Within the application.html.erb
<span class="mDate">{{mFullYear}}</span>
But nothing is showing up.
It is like new Date is not working and/or .getFullYear(); either
The only thing that I can think of, would be to make a regular js file and require it in the application.js file:
//= require user-defined/mDate
With a file named mDate.js being in the vendor/assets/javascripts/user-defined/ directory.
Thanks in advance
You have assigned theDate to be a property of $scope. Either read it from there:
$scope.mCopyRight = ->
$scope.theDate = new Date
$scope.mFullYear = '© ' + $scope.theDate.getFullYear()
Or if that value is only needed by this function, don't use $scope:
$scope.mCopyRight = ->
theDate = new Date
$scope.mFullYear = '© ' + theDate.getFullYear()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With