I have created a directives and while I call that directives, I need to load my JS first. Is there anyway to inject Javascript directly into Directives of angularjs?
Here is the code.
var directive = module.exports = function($rootScope, $location, service, user) { return { restrict: 'E', link: function () { $rootScope.$on( '$routeChangeSuccess', function(event,current) { var path = $location.path(); var pageName = current.$$route.title ? current.$$route.title : path; if(!current.redirectTo) { user.then(function(userInfo) { service.method(pageName, { marketName: userInfo.marketName, accountName: userInfo.name, clientServices: userInfo.isClientServices(), userType: userInfo.type }); }); } }); } }; };
directive.$inject = ['$rootScope', '$location', 'service', 'user'];
Please do needful.