gpt4 book ai didi

javascript - HTML5 模式中的 $location 需要

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:37 24 4
gpt4 key购买 nike

我添加了一个 Tealium AngularJS来自 Github 的 lib 作为我的 SPA 的 bower 组件。这立即破坏了我的单元测试。我不明白为什么它仍然应该使用已经设置了基本 href 的主 index.html 文件?

当我从命令行运行 gulp test 时,出现此错误:

    PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 11 of 118 SUCCESS (0 secs / 0.721 secs)

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 12 of 118 SUCCESS (0 secs / 0.73
secs)

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 SUCCESS (0 secs / 0.741 secs)

PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR

Error: [$location:noc:/dev/code/new-site-ui] $location in HTML5 mode requires a <c:/dev/code/new-site-ui> tag to be present!

http://errors.angularjs.org/1.4.8/$location/noc:/dev/code/new-site-ui
at c:/dev/code/new-site-ui/bower_components/angular/angular.js:12197

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 ERROR (0 secs / 0.741 secs)

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 ERROR (0.004 secs / 0.741 secs)

[13:03:12] 'test' errored after 3.67 s
[13:03:12] Error: Failed 1 tests.

at c:\dev\code\new-site-ui\gulp\unit-tests.js:41:58
at removeAllListeners (c:\dev\code\new-site-ui\node_modules\karma\lib\server.js:336:7)
at Server.<anonymous> (c:\dev\code\new-site-ui\node_modules\karma\lib\server.js:347:9)
at Server.g (events.js:199:16)
at Server.emit (events.js:129:20)
at net.js:1421:10
at process._tickCallback (node.js:355:11)

Process finished with exit code 1

我已经为此奋斗了 2 天。有人有什么建议吗?

最佳答案

你真的确定你有 <base href="/">在你的 HTML 中 <head>

为了避免需要 <base>元素,您可以将其添加到 Angular 模块配置中:

$locationProvider.html5Mode({
enabled: true,
requireBase: false
});

文档:https://docs.angularjs.org/error/$location/nobase

关于javascript - HTML5 模式中的 $location 需要 <base>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com