简体   繁体   中英

Ionic/Angular update array from Javascript

I'm new to this..

I have a controller

.controller('AudioCtrl', function($scope, Audio, AudioSockets) {

$scope.audioSockets = AudioSockets.list;

$scope.$watch(function() {return AudioSockets.list}, function () {
  $scope.audioSockets = AudioSockets.list;
  console.log(AudioSockets.list);
});

That references a service

.service('AudioSockets', function() {

// public API
this.list = sockets;
});

Where I'm trying to use a Javascript array that get's updated via external code

var sockets = [];

How do I get the value of what's in those sockets into my Controller?

Add third parameter boolean true to make deep watch

$scope.$watch(function(){
  return AudioSockets.list
},
function(oldVal,newVal){
  console.log(newVal);
},true);

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