Sunday 15 March 2015

javascript - AngularJS: Data from service is not updated -



javascript - AngularJS: Data from service is not updated -

i have template, gets info service. info in service updated directive.

after info gets updated, won´t updated in template.

// in template {{service.get()}} // in service .service('service', function($http){ var _val = 5; return{ get:function(){ homecoming val; }, set:function(val){ _val = val; } }; }); // in directive var somedirective = angular.module('app.somedirective',[]); somedirective.directive('somedirective', ['service', function(service) { homecoming function(scope, element, attrs){ $(element).on('scroll', function(event){ service.set(15); }); }; }]);

if phone call service.set(x) in other place (like other controller) works 100% fine.

maybe knows, did wrong. (thanks much)

edit create bit more clear:

when pages load, '5' displayed (correctly). when value should updated, service.set()-function called correctly (from directive), nil changes in template.

if phone call service.set() anywere else, works (value updated in template).

you event happens outside of digest cycle. simplest fix:

$timeout(function() { service.set(15); });

javascript angularjs

No comments:

Post a Comment