说明指令templateUrl相对于根 [英] Stating directive templateUrl relative to root

查看:140
本文介绍了说明指令templateUrl相对于根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前陈述templateUrl相对于当前窗口的位置。

I am currently stating templateUrl relative to the current window location.

cvApp.directive('personalDetails', function () {

    return {
        restrict: 'A',
        templateUrl: '../../Scripts/app/templates/personalDetails.html'
    };

});

我怎样才能让相对于应用程序的根templateUrl?我期待这样的事情:

How can I make templateUrl relative to root of the application? I am looking for something like this:

templateUrl: '~/Scripts/app/templates/personalDetails.html'

AngularJS能否做到这一点?

Can AngularJS accomplish this?

推荐答案

看起来像它的支持。从线程采取AngularJS谷歌集团

Looks like it's supported. Taken from a thread on AngularJS Google Group:

以/preFIX URL是相对于域,没有/
  preFIX这将是相对于主(index.html的)网页或碱网址
  (如果您在HTML5模式下使用位置)。

the url with "/" prefix is relative to the domain, without the "/" prefix it will be relative to the main ("index.html") page or base url (if you use location in the html5 mode).

这工作得很好:

templateUrl: '/Scripts/app/templates/personalDetails.html'

这篇关于说明指令templateUrl相对于根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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