相对于 root 的声明指令 templateUrl [英] Stating directive templateUrl relative to root

查看:29
本文介绍了相对于 root 的声明指令 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 Google Group 上的一个帖子:

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

带有/"前缀的url是相对于域的,没有/"前缀它将相对于主(index.html")页面或基本 url(如果您在 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'

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

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