Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,
First of all i am sorry i know this type of questions should not be ask here.
But after spending my 2 hours i am forced to ask it here.

What I want is to create a custom angular directive which can be put in separate js file and can be used anywhere by just referring it
I don't want to make my directive on each app let's say I have app named as MYAPP
then i can create directive on app level like below
JavaScript
var app = angular.module('MYAPP',[]);
app.directive('mydiretive',function(){
     //my directive code
})


i dont want to do above one.

I want something like below viz directive in a separate js and inject in module initialization.
JavaScript
var app = angular.module('MYAPP',['mydiretive']);

How to achieve it guys please help
Posted
Comments
Sergey Alexandrovich Kryukov 4-Dec-14 15:18pm    
Not clear what is your problem is.

It's possible that your understanding of context model and modularity in JavaScript is more complex than it really is. First, essentially, there are no "separate JS files". The files come in one single context, in the order they appear in HTML. (You can dynamically load a file, but this is a different story). And then, the objects appear in the order the execution goes (which is typical for interpretive languages), in up to down direction; and the object name should be visible through the outsize scope or if passed as function parameters.

Say, Angular "module" (or anything like that) is nothing but a named element of associative container, a.k.a. property, a.k.a. array element indexed by the name "module" (string "module"). Everything in Javascript has the same nature...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900