小编eli*_*eli的帖子

如何在 Angular 库中包含图像?

我创建了一个简单的 Angular 库,我希望我的库也显示图像。问题是,如果我将图像包含在库的模块文件夹中,然后从模块内部引用它,则会出现 404 错误。据我所知,在 Angular 项目中,图像必须放在 /assets 文件夹中,但我确实需要将此图像包含在我的库中。

我将图像放在模块文件夹中,并从.html我的模块组件的文件中引用它:<img src="myImage.png">,但它不起作用。

angular

9
推荐指数
1
解决办法
9798
查看次数

无法读取未定义的属性“saveAs”

我希望能够在 Angular 组件中创建和下载文件。为此,我使用 FileSaver.js。即使我已将其导入到我的组件中,我还是在控制台中收到此错误:

ERROR TypeError: Cannot read property 'saveAs' of undefined

这是我的组件:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FileSaver } from 'file-saver';


@Component({
moduleId: module.id,
templateUrl: 'home.component.html',
styleUrls: ['home.component.css']
})

export class HomeComponent implements OnInit {


constructor(private http: HttpClient) {

}

nodes: any;
ngOnInit(): void {
  // Make the HTTP request:
  this.http.get('assets/file.json').subscribe(data => {
    // Read the result field from the JSON response.
    this.nodes = data;
    this.saveFile();

  });

}

saveFile=function …
Run Code Online (Sandbox Code Playgroud)

filesaver.js angular

4
推荐指数
1
解决办法
5957
查看次数

标签 统计

angular ×2

filesaver.js ×1