I don't think it's a bug, but it certainly is a cry for help.

Hi and thanks in advance for any help.

First, my goals. I want to:

 - Establish a widget system, provided that every widget should display its 
state in the url;
 - This system must ensure that internal changes and external ones, from 
the url, must be properly synchronized;
 - There can be no search params outside the registered widgets;

Think about Google Maps: when the map becomes idle, its latitude, longitude 
and zoom are displayed in the url.

So, I made a factory named "widgets", which holds a private variable of the 
same name. Inside this factory, I declared that the $rootScope should 
$watch for changes on this private variable, evaluating its properties, and 
not its reference.

Then, the $rootScope adds a listener to the event "$locationChangeStart". 
The handler function takes care of comparing the search params values from 
the url to the respective ones from the widgets object, prefering the 
firsts. Then, for each registered widget, it $broadcast's an event with 
name of every widget, passing the value just obtained.

This factory returns an object with two methods: "registerWidget(scope, 
widgetName, widgetValue, callback)" and "setWidget(widgetName, 
widgetValue)".

Any directive intented to behave as a widget must have a controller into 
which is injected the "widgets" factory. Inside this directive controller, 
I register the widget with its $scope, an appropriate name, an initial 
value and a callback function.

When something meaningful is done with the directive, the directive itself 
call the method "widgets.setWidget(name, value)".

By modifying the private variable widgets inside the factory, the url shall 
reflect the state of the widget.

I made a fiddle with an example, an adaptation of my work. The button 
"change params" uses $location.search to add an inadequate param, and, 
somehow, this param ends in the private variable, although it should be 
only exposed to registered widgets.

My plunker. <http://plnkr.co/edit/fnvm4B>

Any help would be greatly appreciated. Thanks

-- 
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.

Reply via email to