使用ng-show显示模板,并使用ng-repeat显示内容

时间:2017-06-05 01:19:17

标签: javascript angularjs angularjs-ng-repeat angularjs-ng-show

我正在尝试使用ng-show获得一个模板,然后让内容显示为ng-repeat。我是棱角分明的新手,这是我的第一个项目。这是模板链接到的工厂。

(function () {

    function Message($firebaseArray) {
        var Message = {};
        var ref = firebase.database().ref().child("messages");

        Message.getByRoomId = function (roomId) {
            console.log('Linked.')
            ref.orderByChild('messages').equalTo(roomId);
        }

        return Message;
    }

    angular
        .module('blocChat')
        .factory('Message', ['$firebaseArray', Message]);

})();

这是它链接的模板。

<div class="room-list" ng-repeat="room in roomController.rooms" ng-click="Message.getRoomById()">
    {{ room.$value }}
</div>

<div class="button-open" ng-controller="ModalCtrl as mod">
    <button type="button" ng-click="mod.open()">Create new room</button>
</div>

<div class="chat-content-true" ng-show="message.Room.getRoomById.length > 0">
    <div class="chat-room" ng-repeat="chat in message.Message.getRoomById()">
        {{ chat.$value }}
    </div>
</div>

我正在努力解决的两个问题是,我无法找到将工厂链接到模板的方法。两个我不能得到div&#34;聊天室&#34;出现在当前设置中。我提前感谢任何指示。

这是Room的另一个控制器。

(function () {

    function RoomCtrl (Room) {
        this.rooms = Room.all;
    }

    angular
        .module('blocChat')
        .controller('RoomCtrl', ['Room', RoomCtrl]);

})();

这就是我连接到RoomCtrl的工厂。

(function () {

    function Room ($firebaseArray) {

        var Room = {};
        var ref = firebase.database().ref().child("rooms");
        var rooms = $firebaseArray(ref);

        Room.all = rooms;

        Room.add = function (room) {
            rooms.$add(room);
        }

        return Room;

    }

    angular
        .module('blocChat')
        .factory('Room', ['$firebaseArray', Room]);

})();

0 个答案:

没有答案