如何将模式模板的 let-c="close" 传递给其他组件的 html Angular 5

2024-01-20

我是 Angular 4 的新手,请帮助我。我有一个具有模式模板的组件。

成分 :-

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

import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'ngbd-modal-basic',
  templateUrl: './modal-basic.html'
})
export class NgbdModalBasic {
  closeResult: string;

  constructor(private modalService: NgbModal) {}

  open(content) {
    this.modalService.open(content).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return  `with: ${reason}`;
    }
  }
}

Html :-

<ng-template #content let-c="close" let-d="dismiss">
    <app-partial-modal-content></app-partial-modal-content>
</ng-template>

我的其他组件 Partial Modal ContentComponent

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

import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-partial-modal-content',
  templateUrl: './partial-modal-content.component.html',
  styleUrls: ['./partial-modal-content.component.css']
})
export class PartialCloneModalComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

和partial-modal-content.component.html 是

<div class="modal-header">
  <h4 class="modal-title">Modal title</h4>
  <button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<div class="modal-body">
  <p>One fine body&hellip;</p>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
</div>

但是当我关闭这个模式时,它显示控制台错误,指出 d 和 c 不是函数。 我想将模板的 let-c="close" let-d="dismiss" 传递给其他组件。我怎样才能实现这个目标?


您可以在 PartialModalContentComponent 类中声明 @Input() 。

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

import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-partial-modal-content',
  templateUrl: './partial-modal-content.component.html',
  styleUrls: ['./partial-modal-content.component.css']
})
export class PartialCloneModalComponent implements OnInit {
@Input() cValue;
@Input() dValue;


 constructor() { }

  ngOnInit() {
  }

}

然后当你将它插入到你的html中时:

<ng-template #content let-c="close" let-d="dismiss">
    <app-partial-modal-content [cValue] = "this.c"></app-partial-modal-content>
</ng-template>

现在,您可以使用 tsfile 中的 cValue 和 Partial Modal ContentComponent 中的 html 文件执行操作。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将模式模板的 let-c="close" 传递给其他组件的 html Angular 5 的相关文章

随机推荐

  • 将字符串格式的 url 的 DataFrame 正确转换为 JSON

    我有一个包含 2 列的数据框 其中一列由 URL 组成 示例代码 df pd DataFrame columns name image df df append name sample name image https images pex
  • 元组列表到数据帧的转换[重复]

    这个问题在这里已经有答案了 我有一个类似于以下内容的元组列表 date1 ticker1 value1 date1 ticker1 value2 date1 ticker1 value3 我想将其转换为 DataFrameindex dat
  • 如何在PHP中获取新推送项目的数字键?

    arr new item 是否可以通过编程方式获取新推送的项目 请注意 这不是必需的count arr 1 arr 1 2 arr new item 在上面的例子中 就是2 end 完成工作 返回价值 如果对你有帮助 您可以使用key 之后
  • RuntimeBinderException - C# .NET 4 动态关键字 - 帮助我理解为什么方法不匹配

    我为 HttpModule 构建了一个通用配置系统 允许可插入的 HTTP 标头检查器 作为参考 这里是代码的基本布局 这应该足以让我了解我正在做的事情 public interface IHttpHeaderInspectingAuthe
  • 如何为我的 Java 应用程序指定一个唯一的进程名称?

    我注意到 当我启动 Netbeans 时 它在任务管理器中显示为netbeans exe因为我自己的所有 Java 应用程序都显示为java exe or javaw exe 我怎样才能改变它 以便我的进程名称显示为myapp exe 进程
  • 在 R 中创建空间数据

    我有一个 100 x 200 米区域内物种及其大致位置的数据集 数据框的位置部分不是我认为可用的格式 在这个 100 x 200 米的矩形中 有 200 个 10 x 10 米的正方形 分别命名为 A 到 CV 每个 10 x 10 的正方
  • 如何动态添加导航栏到 jQuery Mobile 应用程序

    如何动态地将导航栏添加到我的 jquery 移动应用程序中 我希望能够从 javascript 将导航栏元素添加到 dom 然后解析它们 我发现我可以根据需要将元素添加到 DOM 然后在元素上调用 navbar 它将执行导航栏解析 例如我可
  • Ormlite Android 批量插入

    谁能解释一下为什么我的插入在 Ormlite 中花费了这么长时间 在桌面上的一个 SQLite 事务中执行 1 700 次插入只需不到一秒 然而 当使用 Ormlite for Android 时 大约需要 70 秒 并且我可以在调试消息中
  • .NET几何库[关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在 NET 中启动一个新项目 该项目需要一些几何算法 例如 检查点是否在多边形内部 贝塞尔曲线 线交
  • 在 C# 类库中使用 MATLAB MWArray.dll

    我正在尝试使用 dll 在 MATLAB 中使用 Matlab net Complier 构建 C 类库 但是每次初始化 MWArray dll 中的对象时程序都会引发异常 例如 MWNumericArray m new MWNumeric
  • json.dump 在看似有效的对象上抛出“TypeError:{...} 不是 JSON 可序列化”?

    背景 我正在编写一个 python 程序来管理我的音乐文件 它抓取目录并将文件及其元数据 通过诱变剂 以 JSON 编码 作为简单的 数据库 放入文件中 我的目录搜索很好 但是当我尝试保存数据库或编码为 JSON 时 它会抛出 TypeEr
  • 维护 web.config 文件

    我很想知道其他人如何维护已部署应用程序的 web config 文件 假设没有自动部署机制 这超出了这个问题的范围 因此 在开发过程中 一些开发人员可能会利用 web config 转换 构建 发布他们的项目 调试 发布 测试 实时配置 然
  • 如何撤消clearPackagePreferredActivities("com.android.launcher");

    我想做的是复制 ToddlerLock 应用程序的功能 我已经设法清除默认启动器 PackageManager localPackageManager getPackageManager localPackageManager clearP
  • 使用 Apollo/graphQL/React 访问和刷新令牌

    经过长时间的搜索 当访问令牌过期时 我为我的应用程序制定了这个解决方案 与其他服务的区别在于 我必须使用外部服务 在使用我的谷歌帐户登录时为我提供访问和刷新令牌 然后 当访问令牌过期时 我需要检索刷新令牌 将其发送到为我提供新访问和刷新令牌
  • C - 求结构的尺寸

    我被问到这个问题作为面试问题 无法回答 编写一个 C 程序来查找结构的大小 而不使用sizeof操作员 struct XYZ int x float y char z int main struct XYZ arr 2 int sz cha
  • ServiceStack.Text 是否提供 JSON 的漂亮打印?

    TL DR ServiceStack Text 中是否有内置方法来生成打印精美的 JSON 我在用ServiceStack Text https github com ServiceStack ServiceStack Text用于进行 J
  • 如何在 Angular2 的 Pipe 中将数组作为 arg 传递

    我创建了一个管道 其目的是根据标签列表过滤列表 Pipe name tagfilter export class TagFilterPipe implements PipeTransform transform items Event ar
  • 更改操作栏溢出的样式

    我在我当前的 android 应用程序中使用 Theme Holo 上面是我当前主题的溢出 UI 我想将溢出菜单的背景颜色自定义为 RGB 245 243 239 将字体颜色自定义为 RGB 64 64 64 以下是我正在使用的 style
  • 在 ActionBar 上放置一个进度条

    我试图在操作栏上放置一个不确定的进度栏 例如 我使用 actionView 来放置进度条 例如 Google 应用程序
  • 如何将模式模板的 let-c="close" 传递给其他组件的 html Angular 5

    我是 Angular 4 的新手 请帮助我 我有一个具有模式模板的组件 成分 import Component from angular core import NgbModal ModalDismissReasons from ng bo