我正在尝试将数据从一个角度组件发送到另一个角度组件。 我已经设法通过sessionStorage做到了这一点,但我知道这不是最好的做法,因为它应该只包含与用户身份识别、日志记录等相关的数据。 在我看过的几个教程中,我必须通过EventEmitter通过html传递数据。在所有这些技术Sharing Data between Angular Components - Four Methods中都可以看到 但是,理想情况下,我想要做的是通过ts组件将数据从parent component传递到child component,以便能够直接在那里操作数据,然后决定如何在parent html中处理数
在我的子组件中,单击一个按钮就会触发一个进程并返回一个布尔值。我需要在父组件中捕获这个布尔值,并启用/禁用一个按钮。我以前从未使用过@Output()。我已经创建了一个示例来显示这个问题。在开发工具中,我得到这个错误:
ERROR TypeError: _co.onclickValidateAndSave is not a function
child.component.ts
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
@Component({
selector:
我正在学习角4,遇到了一个我似乎找不到解决办法的问题。这里是背景:我有一个简单的应用程序,显示有关美国总统的信息。后端是由webapi...this提供的rest,运行良好。前端是一个角度应用程序。
我将问题归结为3个组件、1个数据服务和1个模型。以下是模型:
export class President {
constructor(
public id: number,
public presidentName: string,
public presidentNumber: number,
public yearsServed: string,