如何在angular2中进行孙子和父母之间的双向绑定?

时间:2016-07-14 06:57:27

标签: data-binding angular angular2-template angular2-components angular2-inputs

我需要在父母和孙子之间做两种绑定方式。因此,我尝试在孩子和其他两个孩子之间进行双向约束。

有些人认为那样

GrandChild< ==>儿童< ==>父

但它没有像我期望的那样起作用。

这是我的孙子:

<svg [class.small-size]="!isFullScreen" [class.full-screen]="isFullScreen">
  <ng-content></ng-content>
</svg>
...

export class FullScreenableSvgComponent {

  @Input() isFullScreen: Boolean;
  @Output() isFullScreenChange: EventEmitter<Boolean>;

  constructor() {
    this.isFullScreen = this.isFullScreen || false;
    this.isFullScreenChange = new EventEmitter<Boolean>();
  }
  ...
}

这是我的孩子:

<fullscreenable-svg (window:resize)="onResize()" [(isFullScreen)]="isFullScreen">
    ...
</fullscreenable-svg>

export class VisualizationComponent implements OnChanges, OnInit {

  @Input() isFullScreen: Boolean;
  @Output() isFullScreenChange: EventEmitter<Boolean>;

  constructor(private elementRef: ElementRef) {

    this.isFullScreenChange = new EventEmitter<Boolean>();
  }
  ...
}

这是我的父母:

<visualization [(isFullScreen)]="isFullScreen" [nodes]="[]" [links]="[]">         
</visualization>
<div [hidden]="isFullScreen" style="position:absolute;">
    i am working
</div>

0 个答案:

没有答案