WebContent中的angularjs templateUrl

时间:2017-07-04 11:13:51

标签: angularjs java-ee angularjs-directive

我将我的角度应用程序部署到java动态Web项目,目录映射:

->WebContent
---->javaScript
------>directives
index.html

在我的指令文件夹中我有form指令:

var app = angular.module('myApp');
    app.directive('formDirective', formDirective);

function formDirective() {

    var directive = {
        restrict: 'EA',
        templateUrl: 'formDirective.html', //the request
        scope: {
        },
        controller: FormControllerDir,
        controllerAs: 'vm',
        bindToController: true
    };
    return directive;
}
function FormControllerDir() {
    console.log('FormController');
}

formDirective.html放在同一个目录下,但是对root下的文件进行角度搜索:

GET http://localhost:8080/P2P/formDirective.html 404 (Not Found)

P2P是我的项目名称,如何将其更改为:

http://localhost:8080/P2P/JavaScript/directives/formDirective.html

1 个答案:

答案 0 :(得分:0)

因此,只需添加完整路径表单上下文 -

即可

templateUrl: 'JavaScript/directives/formDirective/formDirective.html'