Angular 6从父组件传递数据给子组件的Bootstrap Modal
创始人
2024-10-16 06:30:39
0

在Angular 6中,可以通过使用@Input装饰器将数据从父组件传递给子组件。以下是一个示例代码:

父组件(parent.component.ts):

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

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css']
})
export class ParentComponent {
  showModal = false;
  dataToPass = 'Hello from parent component';

  openModal() {
    this.showModal = true;
  }

  closeModal() {
    this.showModal = false;
  }
}


子组件(child.component.ts):

import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-child',
  templateUrl: './child.component.html',
  styleUrls: ['./child.component.css']
})
export class ChildComponent {
  @Input() showModal: boolean;
  @Input() data: string;
  @Output() closeModal = new EventEmitter();

  onCloseModal() {
    this.closeModal.emit();
  }
}

在这个示例中,父组件有一个按钮,当点击按钮时,打开子组件中的Bootstrap modal。父组件通过@Input装饰器将showModal和data属性传递给子组件。子组件中,使用@Input装饰器接收这些属性并在模板中使用。子组件中还有一个@Output装饰器,用于在关闭modal时向父组件发送事件。父组件通过监听这个事件来关闭modal。

希望这个例子可以帮助你解决问题。

相关内容

热门资讯

攻略讲解!pokemmo手机版... 攻略讲解!pokemmo手机版脚本,hhpoker透视脚本视频,解密教程(有挂软件)是一款可以让一直...
分享实测!wepoker有什么... 分享实测!wepoker有什么规律,hardrock作弊,可靠教程(有挂软件)是由北京得wepoke...
交流学习经验!wepoker底... 交流学习经验!wepoker底牌透视,wepoker网页版透视方法,存在挂教程(有挂教程)关于wep...
发现玩家!德普之星辅助器,we... 1、发现玩家!德普之星辅助器,wepoker手机插件,曝光教程(有挂技巧);详细教程。2、德普之星辅...
一起来讨论!德州局透视脚本免费... 一起来讨论!德州局透视脚本免费版下载手机版,wepoker私人局俱乐部,AA德州教程(有挂技巧);致...
技术分享!we poker辅助... 技术分享!we poker辅助器v3.3,aapoker ai插件,详细教程(有挂攻略);亲真的是有...
实测必看!wepoker智能辅... 实测必看!wepoker智能辅助插件,wepoker轻量版透视系统,我来教教你(有挂神器);原来确实...
玩家必看!wepoker私人局... 玩家必看!wepoker私人局外卦,wepoker怎么设置透视,可靠技巧(有挂攻略)是一款可以让一直...
实测发现!wepoker免费透... 实测发现!wepoker免费透视,pokemomo辅助软件,攻略教程(有挂软件)1、点击下载安装,微...
让我来分享经验!wepoker... 让我来分享经验!wepoker智能辅助插件,wepoker辅助透视,曝光教程(有挂方法);《WPK辅...