Angular CLI - How to reference image paths in reusable components

霸气de小男生 提交于 2019-12-05 18:52:54

Found this Angular CLI feature request: https://github.com/angular/angular-cli/issues/3555

The Angular app can be configured to copy files from a relative file path to a folder within the app's distribution directory. This allows us to get access to images from within the node_modules folder without having to manually copy the images into the local assets folder.

After updating to the latest version of Angular CLI (1.2.1) I modified my angular-cli.json file as follows:

{
...
"apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico",
        "version.txt",
        {
          "glob": "**/*",
          "input": "../node_modules/ui-common/src/assets/images",
          "output": "./assets/images"
        }
      ],
...
}

Now all images that are in the UI-Common app are accessible to the Command-Center app.

More details about the configuration here: https://github.com/angular/angular-cli/wiki/stories-asset-configuration

import {APP_BASE_HREF} from '@angular/common';

@NgModule({
  declarations: [ ... ],
  imports: [ ... ], 
  providers: [{provide: APP_BASE_HREF, useValue : '/' }]
]); 

I think you need to do something like this for the module you want to to use the image in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!