Angular custom directive on specific route/controller

Par Moulin de Boly, il y a 11 ans


Bonjour, I'd like to manipulate DOM (launch directive) only when a specific page (route+controller) is triggered. In my app.js, it seems I can only lanch directive when app.js is called (always). How could I do it ? Merci, S.

2 réponses

Grafikart, il y a 11 ans

You could also create a onRouteChange to detect the route inside the directive

kal-el, il y a 11 ans

I would lazy load the directive using for example the ocLazyLoad plugin https://github.com/ocombe/ocLazyLoad.

$stateProvider.state('app.controller', { url: '/', resolve: { loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) { return $ocLazyLoad.load({ name: 'app.directive.myDirective', files: ['scripts/myDirective.js'] }); }] } });