0

我使用模板变量来访问来自父 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
        }
      },
    },
    ...
4

0 回答 0