Thank you! On Thursday, December 26, 2013 7:33:34 AM UTC+2, bwiklund wrote: > > The issue is that you're overwriting your 'private' i variable, instead of > updating it. > > http://jsfiddle.net/xye4A/7/ > > instead of this: > > i = {name: 'y'} > > do this: > > i.name = "y" > > Always be careful when you're doing clever stuff in closures. > > On Wednesday, December 25, 2013 12:03:36 PM UTC-8, Ronen Tidhar wrote: >> >> Hi, >> I am trying to figure out how to solve this issue. >> I tried referencing the service. >> I tried using $scope.$watch. >> nothing is working for me. >> 10x in advanced for your help. >> TD >> >> I put the sample code here: http://jsfiddle.net/xye4A/5/ >> >> <div ng-app="ExampleApplication"> >> <div ng-controller="InstanceController"> >> <div ng-click="click()">click</div> >> <div>|{{i.name}}|</div> >> </div> >> </div> >> >> var ExampleApplication = angular.module('ExampleApplication', []); >> >> ExampleApplication.service('instancedService', [instancedService]); >> >> function instancedService(){ >> var i = {name: "x"}; >> var service = { i: i, click: click}; >> return service; >> >> function click() { >> i = {name: "y"}; >> alert(i.name); >> } >> } >> >> ExampleApplication.controller('InstanceController', function($scope, >> instancedService){ >> var vm = $scope; >> vm.i = instancedService.i; >> >> vm.click = function () { >> instancedService.click(); >> alert(instancedService.i.name); >> }; >> >> $scope.$watch( >> function(){ return instancedService.i }, >> function(newVal) { $scope.i = newVal; }); >> }); >> >
-- 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/groups/opt_out.
