【问题标题】:Angular 2 - scripts that require elementsAngular 2 - 需要元素的脚本
【发布时间】:2016-11-22 09:52:28
【问题描述】:

当我尝试在组件中使用脚本化的 A-Frame 元素而不是 index.html 时出现错误。仅运行 index.html 时,注释部分有效。

  <script src="https://aframe.io/releases/0.3.2/aframe.js"></script>
<!--
  <a-scene>
  </a-scene>
-->

但是,当我将“a-scene”元素发送到我的组件中时,它不起作用。

@Component({
  selector: 'app-test0',
  template: `
    <a-scene>
    </a-scene>
  `,
  styles: []
})

我在控制台中收到此错误。

“1.如果'a-scene'是一个Angular组件,那么验证它是这个模块的一部分。”

“2. 如果“a-scene”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。”

【问题讨论】:

    标签: angular angular-cli aframe


    【解决方案1】:

    我能够让它(有点)工作。我在使用 A-Frame VR 时遇到错误,但这似乎超出了此问题的范围。我能够通过“app.module.ts”文件解决问题。

    import { NgModule } from '@angular/core';
    

    import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
    

    @NgModule({
      declarations: [
        AppComponent,
        Test0Component
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    

    @NgModule({
      declarations: [
        AppComponent,
        Test0Component
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule
      ],
      providers: [],
      bootstrap: [AppComponent],
      schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-16
      • 2019-07-04
      • 2018-03-06
      • 2020-09-28
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多