I think this may be an inheritance problem again. Check out the Inheritance article here: https://github.com/angular/angular.js/wiki/Understanding-Scopes. Hopefully this will be of some help. I THINK this may come down to putting the things you want to watch inside of an object (instead of $scope.position, do $scope.someClevelModelName.position) and watch THAT property instead of the position property of the outer scope.
Really hope this helps. -Bill On Fri, Apr 4, 2014 at 8:47 AM, Rob Munro < [email protected]> wrote: > I have an audio player and am using this range slider - which works quite > well. > https://github.com/danielcrisp/angular-rangeslider/blob/master/angular.rangeSlider.js > > <li ng-controller="PlayerCtrl" style="display:inline-block;"> > ... <span range-slider min="0" max="100" ng-controller="PositionCtrl" > model-max="position" pin-handle="min" filter="positionSilderText"> > ...</li> > > So I make a new Controller PositionCtrl inside the PlayerCtrl like so: > > angular.module('myApp.controllers', []).controller('PlayerCtrl', > ['$scope','$timeout',function($scope,$timeout) { > $scope.audioTag=document.getElementById('audioPlayer');// an <audio/> > tag > $scope.position = 0; > $scope.PositionCtrl = function ($scope) { > $scope.$watch('position', function() { > if ($scope.audioTag.duration) { > $scope.audioTag.currentTime = > $scope.audioTag.duration * $scope.position / 100.0; > } > }); > }; > ... > $scope.ui=function() {//called by a $timeout > ... > var newpos = $scope.audioTag.duration; > $scope.position = setpos; > // $scope.$$childHead.position = setpos;// <<-- dont want to do > this > .... > } > }); > > So initially the ui() function updates my slider pos using $scope.position > and all good. > > My problem is that once i drag the slider the position variable gets > created in the child(PositionCtrl) scope and so the watch no longer finds > the variable in the parent(PlayerCtrl) scope. Hence the slider no longer > updates from the ui() method. > > If i uncomment the line to assign the $$childHead.position then the > watcher works . But its no good as i might add more children later and > AFAIK you can't access child scope from the parent anyways (not sure why). > > What is the correct way to share the position with both scopes? > > I asked this > here<http://stackoverflow.com/questions/22845421/how-to-share-a-scope-variable-with-a-child-scope/22846478?noredirect=1>- > but didn't get any answers - that worked. > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
