You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular组件参数如何定义?darkUnderneath属性绑定报错求解

解决Angular组件属性绑定报错问题

你这里的核心问题是用错了装饰器:@Output是用来让子组件向父组件发射事件的,而你要实现的是父组件向子组件传递属性值,这时候应该用@Input装饰器。

修正后的ModalComponent代码:

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

export class ModalComponent implements OnInit {
  @Input()
  darkUnderneath: boolean = false;
  // ... 其他代码
}

另外还要确认两个关键点:

  • 确保ModalComponent已经在对应的Angular模块(比如AppModule或自定义模块)的declarations数组中声明,否则Angular无法识别该组件的输入属性。
  • 父组件模板里的blah变量要确保已在父组件类中定义,或者直接写[darkUnderneath]="true"传递固定布尔值。

内容的提问来源于stack exchange,提问作者Hydroper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 03:44:53