简体   繁体   中英

How can I play a sound on all devices when an element is added to a scope in AngularJS

I want to notify all users of a web app that a new element has been added to a $scope by playing a beep. So when a new element turns up in an ng-repeat the app goes beep. I can do that easily enough on the screen where the element is being added (as shown below) but can't find out how to play a beep for everyone.

$scope.beep = function(){
    beep.play();
};

$scope.addMeal = function(meal) {
    if(meal.food != null && meal.calories != null){
            $scope.todaymeals.$add(meal);               
            if(angular.isDefined($scope.meal)){
                delete $scope.meal;
                beep.play();
            }
        }
    }

You can just easily call the onchildadded method:

ref.on('child_added', function(childSnapshot, prevChildKey) {
  beep.play(); //In Your case
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM