0

footer.js if defined as the main app.

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

app.directive('siteFooter', function () {
    return {
        restrict: 'E',
        templateUrl: 'site-footer.html',
    };
  });
})();

footer.js if added as a dependency.

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

app.directive('siteFooter', function () {
    return {
        restrict: 'E',
        templateUrl: 'Hexdra/partials/site-footer.html',
    };
  });
})();

I have an app that controls just the footer of my site, I then inject that footer app into the main app that defines my page.

I use the templateUrl to load a template for the footer.

For the first case I'm confused because the footerapp is not in the same directory as the template it's linked to, and it's still able to find it.


For the second case when the template has to be defined as 'Hexdra/partials/site-footer.html', why does it require me to go to the root?

If my files are structured as

 - Hexdra
 - -> app - contains the angular.Js files
 - -> assets 
 - -> partials - contains my site-footer.html file. 
 - html-files

wouldn't I need to use 'partials/site-footer.html'?

2
  • Don't describe your code. Post it. Commented Mar 31, 2016 at 17:23
  • The format has been changed to aid answering. Commented Mar 31, 2016 at 17:35

1 Answer 1

1

First I'm confused because the footerapp is not in the same directory as the template its linked to, and it is still able to find it

That's a javascript feature.

Second, for the second case when the template has to be defines as 'Hexdra/partials/site-footer.html', why does it require me to go to the root?

The template is loaded with respect to the directory for index.html as the root, because the template is references by your script and your script files are loaded from index.html.

As a stand alone app, your script is loaded from the footer template and hence the root is the directory of the footer template.

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

8 Comments

What JavaScript feature is used?
You can reference any script anywhere and the root within the script reference wise remains the folder of the file that included the script.
Where your scripts live, their location, is irrelevant. Once included it is as if the html file contained the script itself
Am I misunderstanding something in your question?
So if the html file that called the footer script was inside the app folder then the root would be stuck to only files located in the app folder without redefining the templateUrl explicitly like i did in the second case?
|

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.