0

I have a header that is used on every page on my website. This header containers menu items, searches, etc. I have a controller called 'HeaderController' that is used in the menu. I also have another controller that is used for the main content of the page. I have the following code that allows me to use two controllers:

 angular.module('customersApp')
   .controller('HeaderController', HeaderController)

I run into a problem when I am trying to use this same file on pages outside of the 'customersApp.' For example I have a 'deliveryApp' and when I try to run the top header on a page within the 'deliveryApp' I get an error saying that the 'customersApp' is not available, which I would expect.

I do not want to make a new header and file for each section of my website due to having to make changes to 5 different pages instead of 1. I am looking for a way to include all of my apps in the above code. Thanks.

6
  • Have you injected customersApp in your deliveryApp as a dependency? Commented Dec 15, 2014 at 19:15
  • No that isn't something I am familiar with. Commented Dec 15, 2014 at 19:21
  • You have created two modules, right? Like such angular.module('deliveryApp', []); For deliveryApp to have access to the header you need to inject customersApp into it like this: angular.module('deliveryApp', ['customersApp']); Commented Dec 15, 2014 at 19:26
  • Okay. I actually have 5 different modules. Would the same concept apply? Commented Dec 15, 2014 at 19:30
  • Yes, it would. Are you using a kickstarter such as Yeoman or ng-boilerplate? Commented Dec 15, 2014 at 19:31

1 Answer 1

1

Create a common module for your header controller:

angular.module("common", [])
  .controller("HeaderController", HeaderController);

Then, add this module as a depdendency into other apps.

angular.module("deliveryApp", ["common"]);

and

angular.module("customersApp", ["common"]);

Make sure that the actual js file for common is also included in index.html of each of the apps.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.