Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – 如何将子组件传递给父级兄弟组件?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在list.component.ts上的@L_352_0@mouSEOver / mouSELEave时显示来自bucket-modal.component.ts的弹出窗口.
如何在list.component.ts和bucket-modal.component.ts之间进行通信?我的代码在这里.

list.component.ts

@Component({    
    SELEctor: 'list',templateUrl: 'list.component.html',styleUrls: ['list.component.css'],})

export class ListComponent implements OnInit {
 @input() state: Boolean;
    @Output() toggle = new EventEmitter();
    onHover() {
    this.state = true;
    this.toggle.emit(this.statE);
    console.log("state is ----------" + this.statE);
    }
    onHoverOut() {
    this.state = false;
    this.toggle.emit(this.statE);
    console.log("state is------ " + this.statE);
    }
}

list.component.html

<a (mouSEOver)="onHover()" (mouSELEavE)="onHoverOut()">random Link list</a>

listdetails.component.ts

@Component({

    SELEctor: 'app-list-detail',templateUrl: 'app-list.component.html',styleUrls: ['app-list.component.css'],})


export class ListDetailComponent implements OnInit {


}

listdetails.component.html

<list [elementslist]="listdetails" lisTingtype="3"></list>
<list [elementslist]="listdetails" lisTingtype="3"></list>
<list [elementslist]="listdetails" lisTingtype="3"></list>
<bucket-modal [(showMeaddBucket)]="show2ClickedBucket" [state]="PopUpshow" (togglE)="PopUpshow=$event"></bucket-modal>

斗modal.component.ts

@Component({    
    SELEctor: 'bucket-modal',templateUrl: 'bucket-modal.component.html',styleUrls: ['bucket-modal.component.css'],})



export class BucketModalComponent implements OnInit {

      @input() state: Boolean;
      @Output() toggle = new EventEmitter();
    onHover() {
        this.state = true;
        this.toggle.emit(this.statE);
        console.log("state is " + this.statE);
    }
    onHoverOut() {
        this.state = false;
        this.toggle.emit(this.statE);
        console.log("state is " + this.statE);
    }
}

解决方法

我认为最简单的方法是在BucketModalComponent中创建一个公共方法,它将显示弹出对话框.就像是

export class BucketModalComponent implements OnInit {
  showDialog(): void {
    // Open the popup dialog
  }
}

然后你可以在listdetails.component.html中调用它:

<list ... (togglE)="modal.showDialog()"></list>
<bucket-modal #modal ... ></bucket-modal>

大佬总结

以上是大佬教程为你收集整理的angular – 如何将子组件传递给父级兄弟组件?全部内容,希望文章能够帮你解决angular – 如何将子组件传递给父级兄弟组件?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。