Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49164

Listening to data change on service

$
0
0

@markandrewkato wrote:

How can I listen to a change in my variable inside my service so that i can sync it on all of my controllers.

I tried using:

Controller:

$scope.$watch(Room.all(), function (newVal) {
    console.log('new', newVal);
});

Service:

(function(){
    'use strict';
    angular.module('starter')
        .factory('RoomSrv', RoomSrv);

   RoomSrv.$inject = [];

function RoomSrv() {

    var rooms = {};

    return {
        all: all,
    };

    function all() {
        return rooms;
    }

    }
})();

but this returns undefined. It doesn't get my service's data.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>