javascript - 全局设置 angular.js url root

标签 javascript angularjs angularjs-routing

我有一个托管在我大学服务器上的 Angular 应用。

因为该应用程序不在根域中(URL 构造如下:university.domain/~<student_id>)所有链接和图像源都已损坏(angular 假定它位于域根中)。

我的问题是:如何覆盖 Angular 基础 URL,以便我仍然可以使用 ng-href、ng-src 等好东西?

最佳答案

引用 AngularJS 文档:

Relative links

Be sure to check all relative links, images, scripts etc. You must either specify the url base in the head of your main html file (<base href="/my-base">) or you must use absolute urls (starting with /) everywhere because relative urls will be resolved to absolute urls using the initial absolute url of the document, which is often different from the root of the application.

这里有更多 on the official documentation

例子

<base href="university.domain/~12345678" />

关于javascript - 全局设置 angular.js url root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20310871/

相关文章:

javascript - 在 ng-repeat 上填充新数组

angularjs - 使用 Angular UI 路由器在 URL 中设置动态参数

javascript - 如何使用 ui.router 和 ASP.NET MVC 在 AngularJS 中处理页面刷新

javascript - 分割字符串,评估各部分并重新连接

javascript - 返回大括号在 javascript 中意味着什么(例如 return { init : init} )

javascript - Phantom js 不支持箭头函数 (=>)

javascript - 从 cookie 存储中获取对象后属性消失

javascript - 如何为 AngularJS 路由添加动态前缀

javascript - Node.js Typescript如何将Request.payload分配给自定义接口(interface)

javascript - 收到 Strope.js 通知(正在撰写)