The simplest thing that comes to mind is to use a directive controller in
your label directive and to place the input inside the label.
<label my-label>
<input my-input ng-model="whatevs">
</label>
.directive('myLabel', function() {
return {
controller: function(el, attr) {
...
}
}
});
.directive('myInput', function() {
return {
require: '^myLabel'
link: function(scope, el, attr, myLabelCtrl) {
...
}
}
});
On Wed, Jan 29, 2014 at 11:09 AM, Nikita Tovstoles <
[email protected]> wrote:
> Several sources suggest that using services as the optimal way of sharing
> data between several directives and or controllers. what if a use case
> calls for data to be shared only with specific instances of, say
> directives. In Spring (Java) for example, one would employ a bean with <
> singleton scope. is there a way to do the same in AJS?
>
> for example, say we have a form with N properties. each property is served
> by two directives - myLabel and myInput - and these directives need to
> share state - so we can create a FormPropertyService for that. if that
> service is a global singleton, we'd have to introduce some identifier to
> make sure state for distinct myLabel-myInput pairs is segregated (ie we'll
> end up with a hash with up to N entries in our service). But a more elegant
> way - not requiring an ID scheme - would be to create an instance of
> FormPropertyService per myLabel and myInput pair. How can I do that?
>
> thank you,
> nikita
>
> --
> 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.
>
--
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.