Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
角度类型脚本中的Html[对象]_Html_Angular_Typescript_Pipe - Fatal编程技术网

角度类型脚本中的Html[对象]

角度类型脚本中的Html[对象],html,angular,typescript,pipe,Html,Angular,Typescript,Pipe,我有一个todo作为输入: 待办事项: import { TodoTag } from "./todo-tag-custom"; export class Todo { ... tags: TodoTag[]; } todo.html <tr *ngFor="let todo of todosFiltered()"> <td>{{todo.tags | json}}</td> 当我遍历todo列表时,如何更

我有一个todo作为输入:

待办事项:

import { TodoTag } from "./todo-tag-custom";

export class Todo {
  ...
  tags: TodoTag[];
}
todo.html

<tr *ngFor="let todo of todosFiltered()">
<td>{{todo.tags | json}}</td>
当我遍历todo列表时,如何更改{{}}以只给我todo.tags中的字符串

作为参考,todosFiltered()返回以下内容:

todosFiltered(): Todo[] {
    if (this.filter === 'all') {
      return this.todos;
    } else if (this.filter === 'active') {
      return this.todos.filter(todo => !todo.done);
    } else if (this.filter === 'done') {
      return this.todos.filter(todo => todo.done);
    }
}

由于
tags
是一个数组,因此需要一些东西来遍历它

<tr *ngFor="let todo of todosFiltered()">
    <td>
        <span *ngFor="let tag of todo.tags">{{ tag.tags }}</span>
    </td>
</tr>

我不确定这是否有效。您提供的范围返回了以下元素:根据您提供的代码,这应该可以工作。数据
todosFiltered()
返回的外观如何?你可以
console.log(todosFiltered())
在你的代码中的某个地方给我看看它是什么样子吗?它看起来像这样:todosFiltered():TodoCustom[]{if(this.filter=='all'){返回this.todos;}else if(this.filter=='active'){返回this.todos.filter(todo=>!todo.done);}else if(this.filter=='done')){返回this.todos.filter(todo=>todo.done);}我应该把console.log(todosFiltered())放在哪里?(我是个新手,以前从未使用过它…(参见上面编辑的代码)我的困惑来自
导出类todo{…tags:TodoTag[];}
和“标记的类型是:string”。您说
tags
是字符串,但您提供的代码将其作为Todo类中的数组。因此,如果
todosFiltered
返回多个
Todo
s,则
tags
是一个数组。因此,您必须使用
*ngFor
进一步迭代标记,然后获取“tags”属性来获取字符串。因此,todosFiltered方法返回一个Todo数组,它从代码中看起来像:
[{tags:[{“id”:1,“tags”:“Hello World”,“todoID”:1}]}]
,所以您看到了2个数组是如何存在的吗?然后您需要2个
*ngFor
s
<tr *ngFor="let todo of todosFiltered()">
    <td>
        <span *ngFor="let tag of todo.tags">{{ tag.tags }}</span>
    </td>
</tr>
{ "id": 1, "tags": "Hello World", "todoID": 1 }