如何在视图源中隐藏样式标签。例如,请访问已上传的图片。这就是我想要实现的目标。
在ng-build之后,我得到了所有的内部样式显示在视图源代码中。我想对view Source隐藏起来。
发布于 2019-02-14 05:32:54
在单点登录模式下,在app.server.module.js中添加NoRenderServerStylesHost以覆盖默认的ServerStylesHost行为。例如:
import { NgModule } from '@angular/core';
import { ServerModule, ServerTransferStateModule } from '@angular/platform-server';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
import { ɵangular_packages_platform_server_platform_server_c as ServerStylesHost } from '@angular/platform-server';
export class NoRenderServerStylesHost extends ServerStylesHost {
onStylesAdded(additions: Set<string>): void {
// super.onStylesAdded(additions);
// additions.forEach((s) => console.log(s));
// ignore styles added
}
}
@NgModule({
imports: [
// The AppServerModule should import your AppModule followed
// by the ServerModule from @angular/platform-server.
AppModule,
ServerModule,
ModuleMapLoaderModule,
ServerTransferStateModule,
],
// Since the bootstrapped component is not inherited from your
// imported AppModule, it needs to be repeated here.
bootstrap: [AppComponent],
providers: [{
provide: ServerStylesHost,
useClass: NoRenderServerStylesHost
}]
})
export class AppServerModule {
}https://stackoverflow.com/questions/47807163
复制相似问题