Eric, You are correct, thanks for pointing this out. My code was working properly, I had a logic error. What I forgot was that I wasn't navigating to a new page, my "navigation" occurred by changing a scope variable, and the page would then dynamically reconfigured. This works fine except I guess if some of the logic for the page resides in the link function of a directive. In any case, I fixed the problem by having the directive watch for value changes of the attribute, and to then reconfigure itself appropriately.
Would it not make sense to at least have an option for directives to allow themselves to relink upon attribute changes? Regards, David On Thursday, December 4, 2014 9:12:14 AM UTC-5, Eric Eslinger wrote: > > If the directive is only put into the DOM once, the link function is only > called once. Unless the fragment you provided is inside an ng-repeat or > something, it is correct that the link function only gets called the one > time. Maybe if you could make a plunk <http://plnkr.co/> that > encapsulates your expected and observed behaviors? > > Eric > > On Wed Dec 03 2014 at 8:23:20 PM siegeld <[email protected] <javascript:>> > wrote: > >> Sorry, here is the use of the directive: >> >> <area:scene-button-bar integration-id="currentArea.integrationId" >> max-scenes="5"></area:scene-button-bar> >> >> David >> >> On Wednesday, December 3, 2014 5:38:41 PM UTC-5, Frédéric Fanchamps wrote: >>> >>> Heu... in the code/html you have shared, you only create the directive >>> areaSceneButtonBar but you don't show the usage. >>> Missing something in your post? >>> >>> On Wednesday, December 3, 2014 9:59:00 PM UTC+1, siegeld wrote: >>>> >>>> I've created a directive that for some reason the link function only >>>> gets called once per app lifecycle, and that the scope in the directive >>>> appears shared when I route to different pages. Please see the directive >>>> code below: >>>> >>>> lutronDirectives.directive('areaSceneButtonBar', >>>> ['LutronServerService', function(LutronServerService) { >>>> var linker = function(scope, element, attributes) { >>>> scope.scenes = []; >>>> scope.model = 0; >>>> for (var i = 0; i < parseInt(scope.maxScenes); i++) { >>>> scope.scenes.push({name: "Scene " + i, number: >>>> i.toString()}); >>>> } >>>> var area = LutronServerService.getLutronArea(scope. >>>> integrationId); >>>> if (area != null) >>>> scope.scenes = LutronServerService.getLutronArea(scope. >>>> integrationId).scenes; >>>> else >>>> scope.scenes = []; >>>> scope.click = function(scene) { >>>> LutronServerService.setAreaScene(scope.integrationId, >>>> scene); >>>> scope.model = scene; >>>> } >>>> scope.$on('AreaEvent', function(event, obj) { >>>> if (obj.integrationId == scope.integrationId && >>>> obj.actionNumber == "6") { >>>> scope.deviceLevel = parseInt(obj.parameter) >>>> scope.model = obj.parameter; >>>> scope.$apply(); >>>> } >>>> }); >>>> LutronServerService.queryAreaScene(scope.integrationId); >>>> } >>>> return { >>>> restrict: 'E', >>>> scope: { >>>> integrationId: '=', >>>> maxScenes: '=', >>>> }, >>>> templateUrl: 'partials/areaSceneButtonBar.html', >>>> link: linker >>>> } >>>> }]); >>>> >>>> Please also see the templateUrl here: >>>> >>>> <div class="btn-group"> >>>> <label ng-repeat="scene in scenes" class="btn btn-primary" >>>> ng-model="model" btn-radio="scene.number" >>>> ng-click="click(scene.number)"> >>>> {{scene.name}} >>>> </label> >>>> </div> >>>> >>>> You will notice that the template create a number of bootstrap radio >>>> buttons. >>>> >>>> So - what am I doing wrong? Why doesn't the link function get run each >>>> time I create a new directive? >>>> >>>> Very puzzled... >>>> >>>> Thanks, >>>> >>>> David >>>> >>> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at http://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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.
