How to use assets bundled with ng-packagr in angular library
Asked Answered
M

0

6

I try to bundle some assets into my published angular library. Within my angular workspace, I located the assets in the src-folder with the following ng-package.json

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/project",
  "lib": {
    "entryFile": "src/public-api.ts"
  },
  "assets": [
    "src/assets"
  ]
}

The assets are copied successfully as it should be, but how can I use the assets (in this case an image) in my template? For example, the related template file looks like this:

<div class="login">
  <img src="assets/image.png">
  <div class="actions">
    <ot-cis-input
      [placeholder]="'Bitte Nutzername eingeben'"
      [title]="'Nutzername'"
      [value]="username"
      (changedValue)="username=$event">
    </ot-cis-input>
    <ot-cis-input
      [title]="'Passwort'"
      [type]="'password'"
      (changedValue)="password=$event"></ot-cis-input>
    <div class="login-button">
      <ot-cis-button
        [isPrimary]="true"
        [isLoading]="loadingState"
        (click)="performLogin()">Einloggen</ot-cis-button>
    </div>
  </div>
</div>

The bundled library structure is this: dist/project/lib/library and the assets are placed in dist/project/src/assets/image.png

Can anyone help me?

Mackinaw answered 25/2, 2020 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.