带有组件 templateUrl 的离子库不起作用
Ionic library with component templateUrl not working
我已经创建了一个 Ionic 5 解决方案,并在我的多解决方案项目中添加了一个带有组件“着陆”的库,但是当我尝试在 landing.component.ts 中使用 templateUrl 时,我得到
ERROR Error: Uncaught (in promise): Failed to load
landing.component.html
使用带有 html 的模板效果很好。知道为什么吗?
根本不起作用
templateUrl: './landing.component.html',
工作正常
template: `
<p>
core-LANDING workss!
</p>`,
我试过使用“require('./landing.component.html')”,但我的库无法正常构建
The class 'LandingComponent' is listed in the declarations of the
NgModule 'CoreLibModule', but is not a directive, a component, or a
pipe. Either remove it from the NgModule's declarations, or add an
appropriate Angular decorator.
编辑
- 是 Landing.component.html (templateUrl:) 确实存在。如果我的库不存在,它就不会编译。
- 下面的解决方案结构。
发现问题。伙计,为了一些简单的事情,在厕所里呆了 3 天
*不要使用 ng-package.json
来构建您的解决方案(即不要押注 npm run build
使用默认 ng-package.json
工作)。将 ngPackage 标签添加到您的库 package.json
并包含您要导入的资产。使用脚本命令构建它以专门引用库 package.json
文件。与必须加载对等依赖项以解析路径有关
你的图书馆图书馆package.json
{
"$schema": "../../node_modules/ng-packagr/package.schema.json",
"name": "core-lib",
"version": "0.0.1",
"ngPackage": {
"dest": "../../dist/core-lib",
"assets": [
"src/lib/components/**/*.html",
"src/lib/components/**/*.css"
],
"lib": {
"entryFile": "src/public-api.ts"
}
},
"peerDependencies": {
"@angular/common": "^10.2.4",
"@angular/core": "^10.2.4"
},
"dependencies": {
"tslib": "^2.0.0"
}
}
你的基础项目package.json
(将其添加到脚本标签中)
"build:coreLib": "ng-packagr -p projects/core-lib/package.json"
然后建立你的图书馆运行
npm run build:coreLib
多么无证的头痛。
我已经创建了一个 Ionic 5 解决方案,并在我的多解决方案项目中添加了一个带有组件“着陆”的库,但是当我尝试在 landing.component.ts 中使用 templateUrl 时,我得到
ERROR Error: Uncaught (in promise): Failed to load landing.component.html
使用带有 html 的模板效果很好。知道为什么吗?
根本不起作用
templateUrl: './landing.component.html',
工作正常
template: `
<p>
core-LANDING workss!
</p>`,
我试过使用“require('./landing.component.html')”,但我的库无法正常构建
The class 'LandingComponent' is listed in the declarations of the NgModule 'CoreLibModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.
编辑
- 是 Landing.component.html (templateUrl:) 确实存在。如果我的库不存在,它就不会编译。
- 下面的解决方案结构。
发现问题。伙计,为了一些简单的事情,在厕所里呆了 3 天
*不要使用 ng-package.json
来构建您的解决方案(即不要押注 npm run build
使用默认 ng-package.json
工作)。将 ngPackage 标签添加到您的库 package.json
并包含您要导入的资产。使用脚本命令构建它以专门引用库 package.json
文件。与必须加载对等依赖项以解析路径有关
你的图书馆图书馆package.json
{
"$schema": "../../node_modules/ng-packagr/package.schema.json",
"name": "core-lib",
"version": "0.0.1",
"ngPackage": {
"dest": "../../dist/core-lib",
"assets": [
"src/lib/components/**/*.html",
"src/lib/components/**/*.css"
],
"lib": {
"entryFile": "src/public-api.ts"
}
},
"peerDependencies": {
"@angular/common": "^10.2.4",
"@angular/core": "^10.2.4"
},
"dependencies": {
"tslib": "^2.0.0"
}
}
你的基础项目package.json
(将其添加到脚本标签中)
"build:coreLib": "ng-packagr -p projects/core-lib/package.json"
然后建立你的图书馆运行
npm run build:coreLib
多么无证的头痛。