如何在另一个角度应用程序中使用角度自定义元素

时间:2019-12-10 18:16:09

标签: angular angular-elements

我已经成功创建了在角度项目中命名的角度自定义元素,并且我想在另一个角度项目中使用此自定义元素 我尝试使用以下方式:

  • 在另一个有角项目中复制了自定义元素的profile.js文件,并在index.html中的另一个项目的标签中使用了
  

但是由于GET http://localhost:4200/profile.js net :: ERR_ABORTED 404(未找到)而出现错误

Index.html

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title></title>
      <base href="/">

      <meta name="viewport" content="width=device-width, initial-scale=1">

      <script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.1.3/custom-elements-es5-adapter.js"></script>
      <script src="https://unpkg.com/zone.js"></script>
      <script type="text/javascript" src="/profile.js"></script>


      <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
      <app-profile></app-profile>
      <app-root></app-root> 
    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

我的猜测是,您将profile.js文件与Angular项目的源文件放在一起。尝试将其移至dist文件夹(放置编译文件的文件夹,并在运行ng serve时从该文件夹提供编译的应用程序)