Since you're using Webpack to bundle these files, you just need to use require
. Change your TypeScript code to this:
public heroImageUrl = require("./image/employee_management.jpg");
... and you're done. Your existing Webpack configuration is already set up to bundle .jpg
files using file-loader
, so the require
call will return the URL of the bundled image.
Note: The OP didn't mention, but they are using the ASP.NET Core + Angular 2 template here, which has Webpack all set up already. Therefore this ends up being a a Webpack question, not an Angular question, so the question title is misleading.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…