In the case of generic directives, you often want to use binding and
restrict them to not using application specific services. In the case that
you create 'components' to build your application, these components might
be directives - which DO access application specific services.

Controllers might expose services to the view via placing them on the
scope. I do this all the time.

In the case that you want a generic directive to reveal complex
functionality, you might want to expose the directives controller. This
could be done via a binding (imagine <span
myDirective="directiveController"> - where the variable directiveController
on the scope now gives reference to the directives controller). This could
also be done via an accessor service, where the directive uses a binding to
assign an id to itself, then you use a service to access its controller -
this is how the ionic framework does it.

So, i think your 'rules' are broadly correct, but there are plenty of other
patterns that can be used in more complex situations.



On 21 November 2014 at 23:59, Sander Elias <[email protected]> wrote:

> Hi Asicfr.
>
>> - The view (html) knows only the main controller and his scope
>>
> Not true, the template/html, knows:
>
>    - the scope of the defined ngController
>    - the defined controller itself when the controllerAs is used.
>    - all he $parent scopes.
>    - the controllers from directives when exposed with controllerAs
>
>
>
>> - A directive should not have his own services
>>
> also not true, there is no issue injecting services into directives,
> and/or directives controllers.
>
>
>> *So :*
>> - The view (html) cannot call the services directly.
>>
> It can, but it's not somethign taht's done often.
>
>
>> - The view (html) must use the main controller to access the services.
>>
> It can use any of the above mechanisms
>
>
>> - The view must declare the binding between the directive and the main
>> controller
>>
> Among quite some other options yes,
>
> Given the above I think you might need to reevaluate.Angular does not
> enforce strict rules on how you code.
> It provides guidance, on how to implement long proven paradigms, but you
> are free to program as you want.
>
> Regards
> Sander
>
> --
> 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.
>



-- 
Tony Polinelli

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