我有点困惑如何获取key并value同时使用angular2对象的*ngFor用于遍历的对象.我知道在角度1.x中有一个类似的语法
ng-repeat="(key, value) in demo"
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在angular2中做同样的事情.我尝试过类似的东西,没有成功:
<ul>
<li *ngFor='#key of demo'>{{key}}</li>
</ul>
demo = {
'key1': [{'key11':'value11'}, {'key12':'value12'}],
'key2': [{'key21':'value21'}, {'key22':'value22'}],
}
Run Code Online (Sandbox Code Playgroud)
以下是我的尝试:http ://plnkr.co/edit/mIj619FncOpfdwrR0KeG?p=preview
我怎样才能获得key1并key2动态使用*ngFor?经过广泛搜索后,我发现了使用管道的想法,但我不知道如何去做.是否有任何内置管道在angular2中做同样的事情?
我想在Angular 2中使用*ngFor迭代[object object].
问题是对象不是对象数组而是包含更多对象的对象对象.
{
"data": {
"id": 834,
"first_name": "GS",
"last_name": "Shahid",
"phone": "03215110224",
"role": null,
"email": "test@example.com",
"picture": **{ <-- I want to get thumb: url but not able to fetch that**
"url": null,
"thumb": {
"url": null
}
},
"address": "Nishtar Colony",
"city_id": 2,
"provider": "email",
"uid": "test@example.com"
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我们可以使用管道迭代对象,但我们如何能够从对象进一步迭代意味着data-> picture-> thum:url.
我正在使用Angular2和Typscript.我有一个枚举:
export enum Role {
ServiceAdmin, CompanyAdmin, Foreman, AgentForeman,
CrewMember, AgentCrewMember, Customer
}
Run Code Online (Sandbox Code Playgroud)
我想使用*ngFor迭代枚举.做这个的最好方式是什么?我必须创建一个管道吗?或者有更简单的方法吗?
我在Ngfor中迭代一个json对象时遇到了麻烦,有我的模板:
模板:
<h1>Hey</h1>
<div>{{ people| json}}</div>
<h1>***************************</h1>
<ul>
<li *ngFor="#person of people">
{{
person.label
}}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
人是我正在尝试迭代的json对象,我有(人| json)的结果而没有得到列表,这里是截图:

并完成,这是json文件的一部分:
{
"actionList": {
"count": 35,
"list": [
{
"Action": {
"label": "A1",
"HTTPMethod": "POST",
"actionType": "indexation",
"status": "active",
"description": "Ajout d'une transcription dans le lac de données",
"resourcePattern": "transcriptions/",
"parameters": [
{
"Parameter": {
"label": "",
"description": "Flux JSON à indexer",
"identifier": "2",
"parameterType": "body",
"dataType": "json",
"requestType": "Action",
"processParameter": {
"label": "",
"description": "Flux JSON à indexer",
"identifier": "4", …Run Code Online (Sandbox Code Playgroud)