4

I come to you because in my web page I want to display the time which come from an Angular script. So I have in my HTML :

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>
<p class="alert alert-info">Time is: {{mytime | date:'shortTime'}}</p>

and my script :

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TimepickerDemoCtrl', function ($scope, $log) {
    $scope.mytime = new Date();

    $scope.hstep = 1;
    $scope.mstep = 15;

    $scope.options = {
        hstep: [1, 2, 3],
        mstep: [1, 5, 10, 15, 25, 30]
    };

    $scope.ismeridian = true;
    $scope.toggleMode = function() {
        $scope.ismeridian = ! $scope.ismeridian;
    };

    $scope.update = function() {
        var d = new Date();
        d.setHours( 14 );
        d.setMinutes( 0 );
        $scope.mytime = d;
    };

    $scope.changed = function () {
        $log.log('Time changed to: ' + $scope.mytime);
    };

    $scope.clear = function() {
        $scope.mytime = null;
    };
});

But only "Time is :" is displayed.

Any idea ? Thanks in advance.

4 Answers 4

2

I think you missed ng-app and ng-controller tah

<body ng-app>
   <p ng-controller="TimepickerDemoCtrl" class="alert alert-info">Time is: {{myTime | date:'shortTime'}}</p>
</body>
Sign up to request clarification or add additional context in comments.

1 Comment

First thanks for your response. I actually put it on a div above, so I did try to put it where you told me to put it, but it didn't work..
1

After checking the code you provided, I went to Plunker to test it. First thing I noticed was that you were not referencing the module in the ng-app.

ng-app="ui.bootstrap.demo"

The second thing was that the console was showing a module dependence error related to ui.bootstrap. I just added that dependency and everything was fine.

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.0.0/ui-bootstrap.js"></script>

Please, check the full working example.

4 Comments

Thanks responding.Is it necessary to put the ng-app in the html 's tag ?
Because I put previously in a div. Like that : <div ng-app="ui.bootstrap.demo" ng-controller="TimepickerDemoCtrl"> <p class="alert alert-info">Time is: {{mytime | date:'shortTime'}}</p> </div>
It's necessary because a controller should be related to some module. Keep in mind you could have many modules on a single page. If you don't specify to which module this controller relates, it would not be able to "load".
Your example works too, but it's more common to put ng-app into the head and the controller somewhere between the body and any of its child elements, like divs and so on. Please, if you think this answer helped you solve the issue, feel free to mark it as the answer =)
0

You have given incorrect name in html , change myTime to mytime

Time is: {{mytime | date:'shortTime'}}

1 Comment

Sorry, it was just a copying mistake, I actually wrote "mytime" in the code, but thanks for responding.. Any ohter idea?
0

You have written it wrong in the HTML file. i.e "myTime". Change it to "mytime"

Time is: {{mytime | date:'shortTime'}}

1 Comment

Sorry, it was just a copying mistake, I actually wrote "mytime" in the code, but thanks for responding.. Any ohter idea?

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.