Re: [angular.js] Re: New Post - AngularJS Sticky Notes Pt 2 – Isolated Scope

253 views
Skip to first unread message

Oliver Batchelor

unread,
Jul 12, 2012, 10:20:41 PM7/12/12
to ang...@googlegroups.com
I think the recommended thing to use here is a service where you have
some global state or functionality. Then you simply inject the service
into each directive. One thing I've seen done is storing data in the
rootScope and then the service makes a nicer API around accessing
it/providing events for it.

Another thing I've been doing is passing an object as a parameter, and
that object has a bunch of shared state. I've used this where I don't
want a singleton service (it's not global), it's an inner-directive
which needs to know some state which is local to an outer-directive
but perhaps 3 or 4 levels down.

My example is a document editor, where I want to draw a cursor
(amongst other things), the directive which puts the cursor in the DOM
is a kind of span directive which sits deep in the tree - but the
cursor manipulation is done at the top level. Then I might have
several 'documents' on one pace, so a service is inappropriate.

I'm not sure if this is a bad idea - opinions?

Cheers,
Oliver

On Fri, Jul 13, 2012 at 12:01 PM, Eddie Huang <co...@rocketmail.com> wrote:
> Yeah, but every directive in the entire system needs it. I almost want
> framework support for it instead.
>
>
> On Thursday, July 12, 2012 4:51:25 PM UTC-7, Lukas Ruebbelke wrote:
>>
>> The behavior you described is a good thing. That is why isolated scope
>> exists. To prevent scope from having access to things that you do not
>> explicitly define.
>>
>> The solution is to wire up what you want your isolated scope to know about
>> via attributes, bindings or expressions.
>>
>> An alternate solution would be to turn uiMessages into a service and
>> inject it into the directive.
>>
>>
>> On Thursday, July 12, 2012 4:28:28 PM UTC-7, Eddie Huang wrote:
>>>
>>> 1 thing we hit today with isolated scope, there is no way to populate
>>> "defaults" for them.
>>>
>>> Eg, on rootScope we have uiMessages object, which contains the localized
>>> string for the templates everywhere.
>>>
>>> Then we have a bunch of directives with isolated scope and non of them
>>> have access to uiMessages...
>>>
>>> On Thursday, July 12, 2012 2:32:35 PM UTC-7, Mitcherizer wrote:
>>>>
>>>> Thumbs up! You break it down just great and concepts become much easier
>>>> to manage and understand. Much appreciated, Lukas.
>>>>
>>>> Den torsdagen den 12:e juli 2012 kl. 19:17:31 UTC+2 skrev Lukas
>>>> Ruebbelke:
>>>>>
>>>>> Hey Angulars!
>>>>>
>>>>> I just finished Part 2 of the AngularJS Sticky Notes series on isolated
>>>>> scope.
>>>>>
>>>>> http://onehungrymind.com/angularjs-sticky-notes-pt-2-isolated-scope/
>>>>>
>>>>> Isolated scope was definitely a challenging topic when I started
>>>>> AngularJS but thankfully it has gotten a LOT easier with the new simplified
>>>>> syntax.
>>>>>
>>>>> I hope this helps makes things a little clearer and as always feedback
>>>>> is welcome!
>>>>>
>>>>> Lukas
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/aUdWnFZGcj0J.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

Oliver Batchelor

unread,
Jul 12, 2012, 11:10:12 PM7/12/12
to ang...@googlegroups.com
Very nice!

Just one thing - I am finding the discussion of expressions a little
confusing. It helps to have more concrete names than Foo, the example
in the fiddle makes much better sense.

On Fri, Jul 13, 2012 at 5:17 AM, Lukas Ruebbelke <sim...@gmail.com> wrote:
> Hey Angulars!
>
> I just finished Part 2 of the AngularJS Sticky Notes series on isolated
> scope.
>
> http://onehungrymind.com/angularjs-sticky-notes-pt-2-isolated-scope/
>
> Isolated scope was definitely a challenging topic when I started AngularJS
> but thankfully it has gotten a LOT easier with the new simplified syntax.
>
> I hope this helps makes things a little clearer and as always feedback is
> welcome!
>
> Lukas
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/UCbLNgbYcKEJ.
Reply all
Reply to author
Forward
0 new messages