0
当我尝试将数据从父项传递给子组件时,出现错误。无法将角度4中的父数据传递给子组件
这是我把它放在父组件中的标签。
<pop-up [showPopUp]="true" [content]="content" [title]="title goes here"></pop-up>
子组件
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'pop-up',
templateUrl: './pop-up.component.html',
styleUrls: ['./pop-up.component.css']
})
export class PopUpComponent implements OnInit {
@Input()
showPopUp: boolean;
@Input()
title: string = "";
@Input()
content: string = "";
constructor() {
}
ngOnInit() {
debugger;
}
proceed() {
this.showPopUp = true;
}
closePopUp() {
this.showPopUp = false;
}
}
我想使用的变量showPopUp
,标题和内容中的HTML这样
<h5 class="modal-title" id="exampleModalLabel">{{title}}</h5>
<h5 class="modal-title" id="exampleModalLabel">{{content}}</h5>
我不知道我到底做错了什么。
谢谢,我可以知道它采用这种格式的原因吗 –
我在我的回答中已经添加了一个解释(您可能还没有看到它,因为我在我的初始文章后编辑了我的答案)。 '[]'是特殊的Angular绑定语法。 –