角JS templateUrl以绝对路径 [英] angular js templateUrl with absolute path

查看:437
本文介绍了角JS templateUrl以绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在该URL指向的视频观看页面

On the video watch page with the url

/手表/ VIDEO_ID

/watch/video_id

,我有一个NG应用程序。该指令如下图所示。

, I had a ng app. The directive is shown as below.

app.directive('myApp', function() {
    return {
      restrict: 'E',
      templateUrl: 'ng-templates/myTemplate.html', 
      link: function(scope, elem, attrs) {
      },
      controller: 'Controller'
    };
  }); 

由于templateUrl是相对路径,它会试图找到在模板

Since the templateUrl is the relative path, it will try to find the template in

/手表/ NG-模板/ myTemplate.html

'/watch/ng-templates/myTemplate.html'

这是一个错误。

我想要把所有的模板中的NG-模板文件夹。但它不会工作,如果NG应用始终查找相对路径。有没有配置使得它寻找/ng-template/myTemplate.html应用程序的方法吗?

I want to put all the templates in the ng-templates folder. But it won't work if the ng app always looks for the relative path. Is there a way to configure the app making it to look for '/ng-template/myTemplate.html'?

推荐答案

你有没有尝试添加斜线到templateUrl,像

Did you try to add leading slash to templateUrl, like

templateUrl: '/ng-templates/myTemplate.html', 

这篇关于角JS templateUrl以绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆