JHipster 4.如何访问/ content文件夹中的文件?

时间:2018-02-23 10:54:43

标签: angular jhipster

我正在尝试从NavbarComponent播放声音:

audio = new Audio('../../../content/images/Ding-dong.mp3');

我也无法获得图像:

  ngOnInit() {
    let myImage = new Image(100, 200);
myImage.src = '../../../content/images/image.png';
document.body.appendChild(myImage);
...
}

我总是在控制台中出错:

GET http://localhost:9000/content/images/image.png 404 (Not Found)

GET http://localhost:9000/content/images/Ding-dong.mp3 404 (Not Found)

从navbar.scss到达那里没问题,比如logo:

.logo-img {
            height: 45px;
            width: 70px;
            display: inline-block;
            vertical-align: middle;
            background: url("../../../content/images/image.png") no-repeat center center;
            background-size: contain;
        }

如何从.ts文件访问这些文件?

JHipster 4. Angular 5。

1 个答案:

答案 0 :(得分:0)

向CopyWebpackPlugin添加新文件夹不起作用。 我发现.ts文件中的路径必须是:

audio = new Audio('/content/Ding-dong.mp3');

audio = new Audio('../../../content/images/Ding-dong.mp3');

适用于Angular 5版本。

文件/内容参考/ target / www / content /和文件必须手动放在那里。

但是对于AngularJS必须是:

audio = new Audio('../../../content/images/Ding-dong.mp3');