在RC6之前我这样做了:
import { Injectable, provide, SecurityContext } from '@angular/core';
import { DomSanitizationService } from '@angular/platform-browser';
@Injectable()
export class NoSanitizationService {
sanitize(ctx: SecurityContext, value: any): string {
return value;
}
}
export const NO_SANITIZATION_PROVIDERS: any[] = [
provide(DomSanitizationService, { useClass: NoSanitizationService }),
];
如何使用新的角度释放2.0.0进行操作?因为我无法使用provide
函数。
答案 0 :(得分:0)
DomSanitizationService 已重命名为 DomSanitizer 。
import { Injectable, provide, SecurityContext } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';
@Injectable()
export class NoSanitizationService {
sanitize(ctx: SecurityContext, value: any): string {
return value;
}
}
export const NO_SANITIZATION_PROVIDERS: any[] = [
{provide:DomSanitizer, useClass:NoSanitizationService }, //<----changed this line as well
];
import {NO_SANITIZATION_PROVIDERS} from 'valid path';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: [NO_SANITIZATION_PROVIDERS], //<----here
})
答案 1 :(得分:0)
请勿导入提供并将其写为:
export const NO_SANITIZATION_PROVIDERS: any[] = [
{ provide: DomSanitizationService, useClass: NoSanitizationService }
];