Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Agregar prefijo desde la raíz en angular.json

Tengo este código en angular.json:

 "root": "admin/", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "baseHref": "/admin/", "deployUrl": "/admin/", "outputPath": "dist/front/admin", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "aot": true, "assets": [ "src/favicon.ico", { "glob": "**/*", "input": "src/assets/", "ignore": ["**/*.svg"], "output": "/assets/" } ], ...

Pero tengo un problema para mostrar imágenes. Esto no funciona:

 <img src="/assets/images/test.png">

Y esto funciona bien:

 <img src="admin/assets/images/test.png">

¿Cómo puedo configurar el prefijo "admin/" en angular.json para cada activo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar una Directive para establecer el prefijo en los atributos src de todas las etiquetas img .

Los pasos son:

  1. Generar directive a través de cli :
 ng generate directive set-img-src-prefix
  1. Configure la directive recién generada como:
 import {Directive, ElementRef} from '@angular/core'; @Directive({ selector: 'img' // selects all img tags }) export class SetImgSrcPrefixDirective { constructor(public ref:ElementRef) { // change anything you want globally here } }
  1. Y como último paso, debe agregar esta directive en app.module.ts :
 import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {AppComponent} from './app.component'; import {SetImgSrcPrefixDirective} from './set-img-src-prefix.directive'; // import the directive here @NgModule({ declarations: [ AppComponent, SetImgSrcPrefixDirective // add here ], imports: [ BrowserModule ], bootstrap: [AppComponent] }) export class AppModule { }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!