angular - 重新编译后未定义角度模板变量
问题描述
我使用模板变量来访问来自父 svg 组件的数据。首先它工作得很好,但是在使用默认ng serve重新编译后,模板变量是未定义的。所以我必须重新启动ng serve它工作正常,直到我重建我的应用程序。我不知道是什么变化导致了这个问题,因为它以前没有任何问题。
<g app-parent-component #parentComponent>
<g app-child-component [position]="{x:parentComponent.position,y:0}"> <!-- errors.ts:30 ERROR TypeError: Cannot read property 'position' of undefined -->
</g>
</g>
父组件模板
@Component({
selector: '[app-parent-component]',
template: '
<svg:g class="parent-component">
<ng-content></ng-content>
</svg:g>',
styleUrls: ['./app-parent-component.scss']
})
export class ParentComponent {
...
}
角.json
...
"build":{
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/my-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"preserveSymlinks": true,
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/main.scss",
"src/styles.css"
],
"scripts": []
},
},
...
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "my-app:build",
"sourceMap": {
"scripts": true,
"styles": true,
"vendor": true
}
},
},
...
解决方案
推荐阅读
- python - 复杂的 Pandas 数据框到嵌套字典/JSON
- docker - 为什么我在 docker 容器中使用 nginx 禁止 403
- asp.net - 从网页上的 SQL Server 获取数据超时,但 Crystal Report 在 VS2015 中很好
- google-sheets - 查找一个月是否属于日期范围
- c++ - 返回 WinSock2 SOCKET 的方法无法编译
- javascript - 在 Material-UI React 中将鼠标悬停在复选框上时,如何更改复选框样式和图标?
- kubernetes - Istio:如何配置 NetworkFailPolicy?
- google-cloud-platform - 如何在 application.properties 文件中指定 GCP 凭据位置(用于在 GCP 中使用 Pub/Sub)?
- angular - R3InjectorError 没有 NgbDropdown 的提供程序
- spring - Spring JmsListener 在应用程序运行时启动/停止