0

I have one function in a JS file which should ideally be used by multiple html pages. I don't want to duplicate this function to another file. Currently, my js file starts like this:

(function(){
     var app = angular.module('Project1', []);

and the first html that has been using this JS is obviously called Project1. I want 'Prject2' html to use this JS to, and I tried this:

(function(){
     var app = angular.module('Project1', 'Project2' []);

However, this doesn't work. Any idea of how I can utilize this AngularJS file for multiple html pages without duplicating the desired functions?

2 Answers 2

1

simply add your js reference (and angular refrences) into both of your html pages do note that add them after adding angularjs references

Sign up to request clarification or add additional context in comments.

3 Comments

i do the same for the must common functions i use. all in a js file and load it in the main html.
I did not quite understand this answer. Can you please elaborate?
If you mean to just add the .js reference to both html, this does not solve my problem since I still don't know which project I refer to in the angular.module braces.
0

You can create your first module as you did in your first sample.

Your next sample can then use the 'Project1' by setting up a dependency to that module, like so:

var app = angular.module('Project2', ['Project1']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.