Firebase AngularJS ng-repeat orderby ..怎么样?

时间:2016-03-26 18:12:49

标签: javascript angularjs firebase angularfire

我此时有点迷失,在网上寻找答案,但我还是做错了什么.. 场景: 我有一个firebase obj,我从那里通过ng-repeat重复项目,循环工作完美,但是我无法弄清楚如何通过子项的值来命令这些元素,基本上这就是它现在的样子:

app.js

    .controller('MessageController', function ($scope, $firebase) {

        var ref = new Firebase("https://01062016ag.firebaseio.com/messages/yourmessages/02");
        var fb = $firebase(ref);

        // sync as object
        var syncObject = fb.$asObject();
        var time = Firebase.ServerValue.TIMESTAMP ? Firebase.ServerValue.TIMESTAMP : 1459007018632;

        this.newMessage = { approved:false, time:Firebase.ServerValue.TIMESTAMP };
        this.addMessage = function($event) {
            $event.preventDefault();
            ref.push(this.newMessage);
            this.newMessage = {};
        };
        console.log(syncObject, ref, fb);

        // three way data binding
        syncObject.$bindTo( $scope, 'messages' );
    })

HTML

 <carousel interval="myInterval">

                            <div id="preview">

                                <blockquote ng-class="{ 'preview' : !msgCtrl.newMessage.text }" class="active">
                                    {{ msgCtrl.newMessage.text ? msgCtrl.newMessage.text : 'leave a message' }}
                                </blockquote>
                                <cite ng-class="{ 'preview' : !msgCtrl.newMessage.author }" class="">
                                    {{ msgCtrl.newMessage.author ? msgCtrl.newMessage.author : 'Author' }}
                                </cite>

                            </div>

                            <slide ng-repeat="slide in messages | orderBy: 'time' : reverse " active="slide.active">
                                <blockquote>
                                    {{ slide.text | limitTo: 100 }}{{slide.text.length > 100 ? ' ...' : ''}}
                                </blockquote>
                                <cite>
                                    {{ slide.author }}
                                </cite>
                            </slide>
                        </carousel>

我尝试将过滤器应用于ng-repeat,如某些帖子中所述,例如ng-repeat="slide in messages | orderByPriority | orderBy: 'time' : reverse " or ng-repeat="slide in messages | toArray | orderBy: 'time' : reverse "

但没有运气..我收到了未知提供者注入的错误 我非常确定我的控制器还有问题......

很抱歉,如果它看起来有点不高兴,但我对角度很新:)

感谢您的帮助

0 个答案:

没有答案