检测到直接导入 '@angular/localize/init'。请改为将 '@angular/localize/init' 作为垫片使用
我尝试通过实现 MatPaginatorIntl 来自定义分页器的消息:
import { $localize } from '@angular/localize/init';
@Injectable()
export class PaginationInternationalization implements MatPaginatorIntl {
itemsPerPageLabel = $localize`..:`;
但却收到了一个警告:
Direct import of '@angular/localize/init' detected. This may lead to undefined behavior. 和 Include '@angular/localize/init' as a polyfill instead.
我尝试把它添加到 angular.json 的polyfills部分,但无济于事。
解决方案
真正解决警告的方法,是把localize类型添加到我的 tsconfig.app.json 的compilerOptions.types部分:
"types": ["@angular/localize/init"]
就这样,警告消失了。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。