[英]Use a variable from one component in another (between .ts files) on Angular
So basically I have a todo list being added dynamically and I want to exclude the items, however the list itself is outside the task component:所以基本上我有一个动态添加的待办事项列表,我想排除这些项目,但是列表本身在任务组件之外:
In the task.component.html, the list is being iterated to be displayed:在task.component.html中,正在迭代显示列表:
<ul class="list-group" *ngFor="let taskElement of taskElements; let i=index" [taskElement]="taskElement">
<div class="d-flex justify-content-center">
<li class="list-group-item">
<span>
{{element.description}}
</span>
<button class="btn btn-danger" style="float: right;" type="button">Remove
Task</button>
</li>
However the list is defined on the file app.component.ts:但是,该列表是在文件 app.component.ts 中定义的:
public containsTask = false;
taskElements: { description: string, isDone: boolean }[] = [];
onTaskCreated(taskData: { taskDescription: string }) {
this.taskElements.push({
description: taskData.taskDescription,
isDone: false
});
this.containsTask = true;
}
How can I use the array taskElements (declared in app.component.ts) in the task.component.ts?如何在 task.component.ts 中使用数组 taskElements(在 app.component.ts 中声明)?
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.