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。

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

相关内容

热门资讯

三分钟辅助!wepoker私人... 三分钟辅助!wepoker私人局俱乐部辅助,wepoker有辅助器吗,指引教程(有挂方略)1、操作简...
9分钟辅助!wepoker透视... 9分钟辅助!wepoker透视app下载,wepoker私人局俱乐部怎么进,方针教程(有挂工具)一、...
四分钟辅助!德普之星app安卓... 四分钟辅助!德普之星app安卓版破解版,wepokerplus脚本,项目教程(有挂辅助)1、玩家可以...
2分钟辅助!hhpoker透视... 2分钟辅助!hhpoker透视脚本,wepoker有透视吗,教程书教程(有挂头条)1、超多福利:超高...
第七分钟辅助!wepoker透... 第七分钟辅助!wepoker透视app下载,aa poker辅助包,讲义教程(有挂分享)一、wepo...
第八分钟辅助!wepoker怎... 第八分钟辅助!wepoker怎么开辅助,xpoker辅助器,模块教程(的确有挂)1、不需要AI权限,...
一分钟辅助!wepoker有没... 一分钟辅助!wepoker有没有挂,pokemmo脚本辅助器,讲义教程(有挂教学)1、完成pokem...
第一分钟辅助!hhpoker是... 第一分钟辅助!hhpoker是真的还是假的,wepoker辅助器,阶段教程(有挂技巧)1、金币登录送...
8分钟辅助!hhpoker辅助... 8分钟辅助!hhpoker辅助挂,wejoker私人辅助软件,窍要教程(有挂分析)1、玩家可以在we...
第6分钟辅助!xpoker透视... 第6分钟辅助!xpoker透视辅助,wejoker内置辅助,窍门教程(有挂秘诀)该软件可以轻松地帮助...