Chrome扩展程序 - 无基础href集。请为APP_BASE_HREF提供一个值 [英] Chrome Extension - No base href set. Please provide a value for the APP_BASE_HREF

查看:150
本文介绍了Chrome扩展程序 - 无基础href集。请为APP_BASE_HREF提供一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图将一个Angular 2应用程序加载到Chrome的弹出窗口中。



在使用Angular 1.5之前,我已经完成了这个工作,但尝试使用Angular 2并发生错误。


未处理承诺拒绝:无基础href集。请为APP_BASE_HREF标记提供值
或向文档添加基本元素。 ;
区域:;任务:Promise.then;值:错误:无基础href集。
请为APP_BASE_HREF标记提供一个值,或为文档添加一个基本
元素。(...)错误:没有设置基准href。请为APP_BASE_HREF标记提供一个
的值,或向
文档中添加一个基本元素。


我有把< base href =/> 标签放到我的popu.html中。但问题是vendor.js和main.js被Chrome加载(在被popup.html加载之前),所以没有HTML页面可以放置< base href = />>



只是想知道我可以如何解决这个问题。

Popup.html



 <!doctype html> 
< html>
< head>
< base href =/>
< meta charset =utf-8>
< title> FountainJS< / title>
< meta name =descriptioncontent =>
< meta name =viewportcontent =width = device-width>
< link href =../ styles / popup.css =stylesheet>
< / head>

< body>
< div style =width:200px; height:150px;>
< fountain-root> My Awesome Chrome Popup应该加载Angular 2 right< / fountain-root>
< script type =text / javascriptsrc =../ scripts / vendor.js>< / script>

< script type =text / javascriptsrc =../ scripts / main.js>< / script>
< / div>
< / body>
< / html>


解决方案

您可以在代码中设置基本href, p>

 从'@ angular / common'导入{APP_BASE_HREF}; 
$ b $ @NgModule({
providers:[
{provide:APP_BASE_HREF,useValue:'/'}
]
})
class AppModule {}


I am building a Chrome Browser Action Extension.

I am attempting to load an Angular 2 application into the Popup Window in Chrome.

I have done this before using Angular 1.5, but attempting with Angular 2 and getting an error.

Unhandled Promise rejection: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. ; Zone: ; Task: Promise.then ; Value: Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.(…) Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.

I have put the <base href="/"> tag into my popu.html. But the problem is that vendor.js and main.js get loaded underneath by Chrome (and before being loaded by popup.html) and so there is no HTML page in which to put <base href="/">

Just wondering how I can resolve this issue.

Popup.html

<!doctype html>
<html>
<head>
    <base href="/">
    <meta charset="utf-8">
    <title>FountainJS</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <link rel="icon" type="image/png" href="http://fountainjs.io/assets/imgs/fountain.png"/>
    <link href="../styles/popup.css" rel="stylesheet">
</head>

<body>
<div style="width: 200px; height: 150px;">
<fountain-root>My Awesome Chrome Popup should load with Angular 2 right Here</fountain-root>
<script type="text/javascript" src="../scripts/vendor.js"></script>

<script type="text/javascript" src="../scripts/main.js"></script>
</div>
</body>
</html>

解决方案

You could set the base href in code instead

import { APP_BASE_HREF } from '@angular/common';

@NgModule({
  providers: [
    { provide: APP_BASE_HREF, useValue: '/' }
  ]
})
class AppModule {}

这篇关于Chrome扩展程序 - 无基础href集。请为APP_BASE_HREF提供一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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