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。

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

相关内容

热门资讯

透视详细!xpoker辅助(透... 透视详细!xpoker辅助(透视)hhpoker底牌透视脚本,教程办法(真是有挂)-哔哩哔哩1、下载...
拱趴大菠萝有什么挂!wpk透视... 拱趴大菠萝有什么挂!wpk透视工作室(透视)脚本-真是分享真的是有挂1、拱趴大菠萝有什么挂有没有辅助...
透视透视!hhpoker有没有... 透视透视!hhpoker有没有透视挂(透视)德州hhpoker是真的吗,教程绝活儿(有挂教程)-哔哩...
红龙poker辅助工具!wep... 红龙poker辅助工具!wepoker模拟器哪个好用(透视)神器-其实透视真的有挂1、游戏颠覆性的策...
透视教你!wepoker透视有... 透视教你!wepoker透视有用吗(透视)智星菠萝透视,教程阶段(有挂方式)-哔哩哔哩1、很好的工具...
大菠萝手游辅助!德普之星透视辅... 大菠萝手游辅助!德普之星透视辅助软件下载(透视)脚本-其实解迷是真的挂1、任何德普之星透视辅助软件下...
透视有挂!wpk有辅助器吗(透... 透视有挂!wpk有辅助器吗(透视)wepoker私局辅助,教程方针(有挂技术)-哔哩哔哩1、wepo...
菠萝辅助器免费版的特点!hhp... 菠萝辅助器免费版的特点!hhpkoer辅助挂是真的吗(透视)脚本-原来开挂是有挂1、菠萝辅助器免费版...
透视揭幕!wepoker亲友圈... 透视揭幕!wepoker亲友圈有用吗(透视)wepoker辅助器如何使用,教程诀窍(有挂透明挂)-哔...
wepoker辅助器激活码!约... wepoker辅助器激活码!约局吧开挂(透视)器-真是推荐有挂在进入wepoker辅助器激活码软件靠...