0

尝试使用角矩库。(不确定我是否可以在此处添加指向它的链接)。尝试使用它,如 github repo 中所示。向索引文件、moment、angularMoment 添加库,然后...

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

但是如果我尝试将它注入 myApp,整个控制器就会消失,就像它不存在一样。我想它可能无法解决 angularMoment 并将整个控制器留在后面。尝试将其注入控制器,但返回它找不到 angularMomentProvider。

我使用此控制器的视图:

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

我究竟做错了什么?我应该怎么做才能让它工作?谢谢

4

1 回答 1

0

您必须为控制器提供名称。

angular
    .module('myApp', ['angularMoment'])
    .controller('MyController', function(angularMoment) {
    });
于 2015-06-05T13:27:36.443 回答