Intercept all events that update data of some kind with angularjs -
before can use angularjs have solve following problem
maintaining application state across single page view flips , multi-page flips
i have started view state service , trying integrate application. if call stuff manually, works great. problem want have viewstate object update automatically developer doesn't have anything, include few things , works.
im trying follow angulars source code, functional programs hard debug being pain. there document (other 1 http://docs.angularjs.org/api/ng.$rootscope.scope , pretty useless), explains event system within angular? want able pull list of events registered in system.
here's design im trying pull off.
any time field typed in, button clicked, column sorted, want event fired triggers viewstate service. view state service records event in sorta delta v type layout.
when directive initialized, want event fire again triggers view state service, service looks @ internal delta storage , if directive exists, plays deltas return directive state in before.
when person navigates outside of angular (in case jumping angular legacy struts app) view state service automatically stores delta store redis database.
if user buttons angular app, angular initializing hits redis database , pulls down deltas exist.
i have working in manual layout, need automated.
at moment in time, care less how use event system, right need know how watch work. need able click button , see internal events fired make angular does. how pull off? how angular developers debug event system when writing thing?
how this? use angular's $watch function to, ... watch changes on scope's properties , save them accordingly.
var app = angular.module('app',[]) .directive('adirective',[ 'redisservice', function(redis){ return { restrict: 'a', // or otherwise templateurl: "adirectivetemplate.html", controller : ['$scope', function($scope){ // initialization var savedstate = redis.hasdata('somekey'); if(savedstate){ $scope.model = savedstate; }else{ $scope.model = { prop1: 1, prop2: 2 } } }], link: function(scope, elem, attrs){ // set watcher when directive linked. // observes changes properties assigned scope & fires callback. scope.$watch(function(){ redis.savedelta(scope.model); }); } } }]); // ...
Comments
Post a Comment