【问题标题】:using ng2-pdf-viewer with angular-cli使用 ng2-pdf-viewer 和 angular-cli
【发布时间】:2016-10-18 19:43:25
【问题描述】:

我正在尝试将 ng2-pdf-viewer 添加到我的 angular2 项目中,但我在使用 Angular-CLI 设置它时遇到问题,指南说我应该将映射添加到 systemjs 但 angular-cli 没有'现在不使用 systemjs。 我尝试在 angular-cli.json 中添加 lib 的路径,但它给了我同样的错误。

Uncaught Error: Unexpected value 'PdfViewerComponent' declared by the module 'AppModule'
at http://localhost:3000/vendor.bundle.js:12183:31
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/vendor.bundle.js:12170:49)
at RuntimeCompiler.compileComponents (http://localhost:3000/vendor.bundle.js:18476:47)
at RuntimeCompiler._compileModuleAndComponents (http://localhost:3000/vendor.bundle.js:18414:37)
at RuntimeCompiler.compileModuleAsync (http://localhost:3000/vendor.bundle.js:18405:21)
at PlatformRef.bootstrapModuleWithZone (http://localhost:3000/vendor.bundle.js:26818:25)
at PlatformRef.bootstrapModule (http://localhost:3000/vendor.bundle.js:26800:21)
at HTMLDocument.main (http://localhost:3000/main.bundle.js:89232:10)
at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.bundle.js:15379:38)
at Zone.runTask (http://localhost:3000/polyfills.bundle.js:15279:48)
at HTMLDocument.ZoneTask.invoke (http://localhost:3000/polyfills.bundle.js:15447:34)

这是我从组件中得到的错误,该组件使用 pdfjs-dist 并且它不包含任何 ts 文件,并且由于指南说我不能使用 systemjs,因此我需要一些帮助。

angular-cli.json:

 {
  "project": {
    "version": "1.0.0-beta.17",
    "name": "ng_pdf_app"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": "assets",
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
      "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/tether/dist/js/tether.js",
        "../node_modules/bootstrap/dist/js/bootstrap.js"
      ],
      "environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "addons": [],
  "packages": [ {"ng2-pdf-viewer":{ "main": "dist/pdf-viewer.component.min.js", "defaultExtension": "js" }},
    {"pdfjs-dist": { "defaultExtension": "js" }}],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false
  }
}

ng2-pdf-viewer

【问题讨论】:

    标签: angular webpack systemjs angular-cli


    【解决方案1】:

    查看 How to integrate third party libraries 上的 Angular-CLI 文档

    你只需要在angular-cli.json文件的scripts对象中包含相应的JS文件。

    希望这会有所帮助!

    【讨论】:

    • 你使用的是什么版本的cli?
    • 最新的 .17 我相信
    • 能否更新您的问题以包含 cli json 的内容
    猜你喜欢
    • 2022-07-26
    • 2018-03-26
    • 1970-01-01
    • 2019-06-03
    • 2021-12-27
    • 2020-10-21
    • 2020-01-18
    • 2018-03-06
    • 2019-12-19
    相关资源
    最近更新 更多