0

Trying to use angular-moment library. (Not sure if I can add a link to it here). Tried to use it as shown in github repo. Added libraries to the index file, moment, angularMoment and then...

angular.module('chat', ['angularMoment'])
.controller('ChatController', ['$scope', '$location', '$timeout', '$interval', '$filter', 'Authentication', 'Socket', 'Chat',
    function($scope, $location, $timeout, $interval, $filter, Authentication, Socket, Chat) {
    }]);

But if I try to inject it in myApp, the whole controller just disappears, like it was not there. I suppose it might not be able to resolve angularMoment and leaves the whole controller behind. Tried injecting it into controller, but returns that it cant find angularMomentProvider.

The view where im using this controller:

<section ng-controller="ChatController" ng-init="getMessages()">
    <div class="page-header">
        <h1>Chat</h1>
    </div>
    <div class="col-md-4">asd</div>
    <div class="col-md-6" style="background-color: hsla(30, 1%, 52%, 0.02); border-radius: 1%;">
        <small>{{ userWriting }}</small>
        <div scroll-to="isAtTop" style="padding: 10px 10px 0px; ">
            <ul class="list-unstyled">
                <li class="" ng-repeat="message in messages">
                    <small class="pull-right text-muted" style="color: lightgrey;"><span class="glyphicon glyphicon-time"></span> {{ message.created | timeDuration }}</small> 
                    <span style="font-size: 14px; font-weight: 700;">{{ message.user.username }}</span>
                    <p style="font-size: 14px">{{ message.message }}</p>
                </li>
            </ul>
        </div>
        <form name="chatForm" class="form-horizontal" ng-submit="sendMessage()" novalidate>
            <fieldset>
                <div class="input-group" style="margin-bottom: 15px">
                    <input name="message" type="text" data-ng-model="message" id="message_input" class="form-control" placeholder="Message" [required="test"] ng-keypress="keypressEvent()" ng-model-options="{ debounce: 2000 }">
                    <span class="input-group-btn">
                        <button class="btn btn-default">Send</button>
                    </span>
                </div>
                <div data-ng-show="error" class="text-danger">
                    <strong data-ng-bind="error"></strong>
                </div>
            </fieldset>
        </form>
    </div>
    <div class="col-md-2">
        asd
    </div>
</section>

What am I doing wrong? What should I do to make it work? Thanks

DasBoot
  • 469
  • 6
  • 17
  • What does the output on the developer console say? – Mark Veenstra Jun 05 '15 at 13:20
  • What order did you add you script includes in? You need to add moment.js too - this one should be added before angular-moment.js. – Donal Jun 05 '15 at 13:20
  • moment first and angular-moment second. Also console doesnt return any errors, it just acts like there isnt such route to the controller. – DasBoot Jun 05 '15 at 13:25
  • @DasBoot I think we need to see more code. – Donal Jun 05 '15 at 13:26
  • I am not really sure what specific code would you want to look at. Because all I have tried for this angular-moment is injecting it to app which works fine without it. So let me know what would you like to look at. – DasBoot Jun 05 '15 at 13:36

1 Answers1

0

You must provide a name to the controller.

angular
    .module('myApp', ['angularMoment'])
    .controller('MyController', function(angularMoment) {
    });
tommy
  • 1,006
  • 1
  • 11
  • 13
  • I changed code snippet to my specific one, you can see there is a name. I might have missed it in previous example. – DasBoot Jun 05 '15 at 13:37
  • Can you post some additional code? For example a view where you use the controller or moment's module. – tommy Jun 05 '15 at 13:41