0

I've got this line of code

<h3> <script>Date.now</script>{{$flow.files[0].name}} </h3>

Basically All i'm wanting to do is put the date infront of the filename thats generated from the {{}}.

It currently shows nothing, The unix timestamp might be better but i can only get it to show text that i type infront.

I have tried {{Date.now(); $flow.files[0].name}} Which hasn't worked.

2 Answers 2

1

If you want to do it with JavaScript like your first attempt, you should have something like this:

<div ng-app="app">
    <span id="dateHere"></span> - {{fileName}}
    <script>
    document.getElementById("dateHere").innerHTML = Date();
    </script>
</div>

and if you want to have more control on your date format:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<div ng-app='app' ng-controller='Ctrl'>
        <span id="dateHere"></span> - {{fileName}}
        <script>
        document.getElementById("dateHere").innerHTML = Date();
        var date = new Date();
        var currentYear = date.getFullYear();
        var currentMonth = date.getMonth();
        var currentDate = date.getDate();
        var customDate = currentMonth + '-' + currentDate + '-' + currentYear;
        document.getElementById("dateHere").innerHTML = customDate;
        </script>
</div>

<script>
  angular.module('app', []).controller('Ctrl', function($scope){
    $scope.fileName = 'your file name';
  })
</script>

-> on Plunker

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

5 Comments

This didnt do anything except break everything, Quickly remove this
@ddsbro lol well you are supposed to edit it! of course it'll break your code if you just copy and paste it somewhere :)
@ddsbro ignore the ng-app and {{fileName}}, just use the rest of the code to get the time you want and then add the rest of your angular stuff to it
Ha yes i did that , This is what i ended up with, <script> document.getElementById("dateHere").innerHTML = Date(); </script> <h3><span id="datehere"></span>{{$flow.files[0].name}} </h3>
@ddsbro good. I've added an example to my answer. you might want to check that out also
0

Try something like this:

Controller:

$scope.myDate = new Date();

HTML:

{{myDate | date: 'MMM d, y h:mm:ss a' }} {{$flow.files[0].name}}

I used the filter date to format the date.

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.