0

Take the following example directive:

.directive("myDirective", function() {
    return {
        restrict: "A",
        templateUrl: "/my/absolute/path.tmplt.html",
        controller: ...Do Controller Stuff...
    }
});

This runs through the Closure Compiler without error. However, when loading the app I am greeted with a 404 as it tries to load the full /my/absolute/path.tmplt.html path. Removing the leading '/' resolves the problem. This is also a problem for ng-include(src="'/my/url'"), ng-controller="myCtrl") located in the HTML files and I suspect anywhere you could reference a url.

So why do absolute paths fail while relative ones work just fine?

1 Answer 1

2

You have an invalid path specified. If you current page is asdf.com/boo/yourpage try going to asdf.com/my/absolute/path.tmplt.html You should see a 404.

This is not really related to angular Or google closure and is related to your folder structure + your server configuration.

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

1 Comment

The templateUrl does not require a full web path. This is evident from the documentation, nor would it make since that all template requests be made from the site url. Furthermore, this approach works with or without the leading '/' until it is run through google closure. The following show the use of ng-include and directives that reference the template html by file directory structure, not web structure. docs.angularjs.org/guide/directive docs.angularjs.org/api/ng.directive:ngInclude

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.