我正在将我的 Angular 11 应用程序重构为库。我的常规应用程序已本地化@angular/localize
为开发依赖项,因此我$localize
在部分代码中使用了该指令。我需要将此指令与此指令一起移动到库中,但我不知道如何执行此操作。
在我的库package.json
文件中,我添加了对等依赖@angular/localize
项以匹配我的应用程序中的 devDependency:
{
"name": "example",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^11.0.0",
"@angular/core": "^11.0.0",
"@angular/localize": "~11.0.0"
},
"dependencies": {
"tslib": "^2.0.0"
}
}
$localize
但是编译器报告说当我尝试做时它找不到ng build <library name>
。
× Compiling TypeScript sources through NGC
ERROR: projects/example/src/lib/example.service.ts:52:23 - error TS2304: Cannot find name '$localize'.
52 description = $localize `example localized text`;
~~~~~~~~~
如何$localize
在我的库中使用该指令?
>ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 11.0.1
Node: 12.18.3
OS: win32 x64
Angular: 11.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1100.1
@angular-devkit/build-angular 0.1100.1
@angular-devkit/core 11.0.1
@angular-devkit/schematics 11.0.1
@angular/cli 11.0.1
@schematics/angular 11.0.1
@schematics/update 0.1100.1
ng-packagr 11.0.3
rxjs 6.6.3
typescript 4.0.5