That's not how directives work. Directive controllers are used for
directive-to-directive communication. You could require a parent directive
to be present (i.e. see tabs example from http://angularjs.org) or you can
require a directive on the same element (ie. ngModel).
Since your directive isn't using isolate scope you enjoy direct access to
your controller's scope. There is a drawback though: your directive is
tightly coupled to the TimelineController and isn't reusable as an atomic
unit.
On Monday, March 24, 2014 4:37:15 PM UTC-4, Marc B wrote:
>
> Hello,
>
> I work on a Directive and wonder if I can access a controller using the
> require property. Currently I have no luck with this setup, I wondre what
> I'm doing wrong...
>
> <div
> class="timeline"
> ng-controller="TimelineController"
> tl-edit
> tl-years min="500" max="2010" step="50">
>
> In the controller 'TimelineController' I want to have access to the values
> from attributes min ("500") max ("2010") and step ("50")
> I try doing that via a Directive since that has direct access to
> attributes using the attrs param in link(). (Q: If there's an easier way
> please let me know!)
>
> I want the Directive tl-edit to have access to TimelineController in order
> to inject values of attrs. I do is this
>
> app.directive('tlYears',function(){
> function link(scope,element,attrs,TimelineController){
> TimelineController.init({
> timelineWidth: element.attr('width'),
> startYear: attrs.min,
> endYear: attrs.end,
> step: attrs.step
> })
> }
> return{
> restrict: 'A',
> link: link,
> require: 'ngController'
> }
>
> require: 'ngController'
> refers to Directive ng-controllre, give me some kind of generic object. If
> I call TimelineController.init() I gte an error "
>
> TimelineController.init is not a function" while TimelineController. contains
> function init()...
>
> What to do here?
>
> Thanks,
>
> Marc
>
>
>
--
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.