MatTaNg
MatTaNg

Reputation: 895

AngularJS cannot find template

Here is my directive

(function() {
    angular.module('commentsDirective', [])

    .directive('mngComments', mngComments)

    function mngComments() {
        return {
            restrict: 'AE',
            scope: {
                moment: '='
            },
            templateUrl: 'comments.html',
            replace: true,
            controller: 'CommentsController',
            controllerAs: 'vm'
        };
    };
})();

Here is my file structure:

enter image description here

And I get this error message:

enter image description here

I'm not understanding this. My html file is in the same directory as my directive so why can't it find it?

Upvotes: 0

Views: 899

Answers (1)

Danny Chernyavsky
Danny Chernyavsky

Reputation: 479

Path to template should be relative to page’s path. So if directory comments is placed at root, you should specify templateUrl as /comments/comments.html.

If you want to use your module in unknown paths, you can use $templateCache to “import” your template to your module first. Then you can specify custom URL used while defining templateCache.

Upvotes: 2

Related Questions