Angular 指令:来自其他文件的模板

Pre*_*cho 3 javascript angularjs angularjs-directive

如何在 angular js 中包含 .html 作为我的模板文件,而不是在模板属性中包含直接的 HTML 代码?`

到目前为止,这是我的代码:

    .directive('navigation', ['$rootScope', '$i18next', function ($rootScope: any, $i18next: any) {
        return {
            bindToController: true,
            template: '../views/navigation-directive.html',
            link: function (scope, element, attrs) {....
Run Code Online (Sandbox Code Playgroud)

但是当运行此代码时,我的浏览器显示的唯一内容是以纯文本形式显示的“../views/navigation-directive.html”。

在此处输入图片说明

我的文件的当前结构是这样的。

指令文件位于 solution/script/navigation.js .html 文件位于 solution/view/navigation-directive.html

Beh*_*adi 5

改变道具

template: '../views/navigation-directive.html',
Run Code Online (Sandbox Code Playgroud)

templateUrl: '../views/navigation-directive.html',
Run Code Online (Sandbox Code Playgroud)