javascript - AngularJS directive only called once? -
javascript - AngularJS directive only called once? -
i'm trying shove mixitup within angular page , in order made directive module it
angular.module('mainctrl', []) .controller('maincontroller', function($scope) { $scope.tagline = 'to moon , back!'; }) .directive('mixitcontainer', function() { homecoming { restrict: 'a', link: function(scope, element, attrs) { $(element).mixitup(scope.$eval(attrs.mixitcontainer)); } }; });
don't worry simplicity of main controller, test.
now, issue directive get's called once! if go page , inquire angular load controller , go home page , inquire angular load mainctrl again, directive isn't loaded!
heres directive:
<div id="container" class="mixit-container" mixit-container="{load: {sort: 'order:asc'}, controls: {togglefilterbuttons: true, togglelogic: 'and'}}">
anyone got ideas?
angularjs doesn't include routing facilities. provided either ngroute (a core optional module), ui-router (ngroute made super-awesome-amazing), or replacement. don't use, , each has different behaviors.
whichever is, going come downwards router, not directive. directive called whenever necessary. doesn't command - 'necessary' means angular compiling portion of dom, template file, , has run directive. phone call directive , inquire "what now?"
the above-named routers have different behaviors, both each other , based on how configure them internally. in of them can arrange things templates do, or not, re-rendered. example, in ui-router can have 'child' states. if have kid state active, parent active... going kid parent not re-render template because done earlier. , create matters more complex, can override hooking $statechangestart
event , forcefulness router redraw view if didn't think needed to.
all means... set attending directive aside. want higher level want. router behaving way expect , happy!
javascript jquery angularjs directive
Comments
Post a Comment