簡體   English   中英

EventEmitter - 無法綁定,因為它不是已知屬性 - Angular 8

[英]EventEmitter - Can't bind since it isn't a known property - Angular 8

我正在嘗試使用 eventemitter,但我無法使用它。 我對 angular 很陌生,我不明白發生了什么! 對於我在其他帖子中看到的內容,我做的一切都是正確的! 我試圖通過一個組件向另一個組件發送一個數組。 干預頁面將是此數組的負責人和所有者,因此每當此數組發生更改時,我都想將數據導出到同步頁面。 有人能告訴我我做錯了什么嗎?

我收到此錯誤:

*Uncaught Error: Template parse errors:
Parser Error: Bindings cannot contain assignments at column 9 in [message=$event] in ng:///SyncPageModule/SyncPage.html@40:37 ("

  <ion-card>
      <app-intervention [eventTest]="[ERROR ->]message=$event"></app-intervention>
    <ion-item-divider>
        Acciones Pendientes ({{message}})
"): ng:///SyncPageModule/SyncPage.html@40:37
Can't bind to 'eventTest' since it isn't a known property of 'app-intervention'.*

這是我的代碼:

InterventionPage.ts

import { EventEmitter } from 'events';

@Component({
  selector: 'app-intervention',
  templateUrl: './intervention.page.html',
  styleUrls: ['./intervention.page.scss'],
})
export class InterventionPage implements OnInit {

  constructor(private router: Router,
    public alertController: AlertController) { }

  service: any;
  initialDate: string;
  endDate: string;
  initialTime: string;
  endTime: string;
  startingTime: string;
  teste_array: any = [];
  interventions: any = ["test", "teste", "testee"];
  @Output() public eventTest = new EventEmitter();

  sendsData() {
    this.interventions.push("testThroughClick");
    this.eventTest.emit(this.interventions.length);

    console.log("interventions length: ")
    console.log(this.interventions.length);
  }

同步頁面.ts

import { InterventionPage } from '../intervention/intervention.page';


@Component({
  selector: 'app-sync',
  templateUrl: './sync.page.html',
  styleUrls: ['./sync.page.scss'],
})
export class SyncPage implements OnInit {

  services: any = [];
  teste: string;
  teste_array: any = [];
  nr: any;
  public message = "";


  constructor(private interventionsPage: InterventionPage) {
     }

}

同步頁面.HTML

<ion-card>
      <app-intervention [eventTest]="message=$event"></app-intervention>
    <ion-item-divider>
        Acciones Pendientes ({{message}})
    </ion-item-divider>
</ion-card>

改變

import { EventEmitter } from 'events';

import { EventEmitter } from '@angular/core';

和,

<app-intervention (eventTest)="message=$event"></app-intervention>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM