0

I'm working on two very similar projects (almost the same).

But the front end of the code is totally weak. I'm refactoring it and was thinking to use the most of the same code ( and specialize if there is a single rule for it ) for both applications and when generating the build on Grunt it generates the desired application...

I wonder if there is a more correct way to do this...

I would like to reuse as much JS and HTML as possible...

3
  • Why not having 2 controllers pointing at 2 different restful backends. And then having those 2 controllers using the same dependencies? Commented Jun 29, 2015 at 12:57
  • If you want to use the same frontend code, splitting your code would help doing injections. You can easily have 2 main html pages using the same controller with different dependencies or if you have 1 backend, using 2 pages using exactly the same controller if you only want to change the way the 2 apps look. Commented Jun 29, 2015 at 13:15
  • Why not rely on javascript inheritance and override whatever constitutes your delta ? Commented Jun 29, 2015 at 13:46

1 Answer 1

1

Angular JS is a framework, that perfectly divided the code into modules and make each module separate and reusable. Divide your code in modules. Each module having set of Controller, Service, Factory (REST API model), Directive (If any DOM Manipulation), Partials and CSS. Now you can use each Module separately. As in your case you have to use two different backends, make a rootScope property to determine which backend to use. According to the backend to be used configure your Base backend URL, Factories and Service and rest of directives, controllers, HTML and CSS remains the same.

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

2 Comments

But in this case o will change only a "flag" on rootScope to set witch application i will see? I was thinking if its not better set this on build? Or both its ok to do?
I didn't understand your question

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.