相关疑难解决方法(0)

如何使用*ngFor迭代对象键

我想在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.

ionic2 angular

58
推荐指数
6
解决办法
10万
查看次数

ngForIn可用于角4吗?

我试图使用*ngFor但迭代迭代对象的属性in.当我尝试这样做

@Controller({
  selector: 'sample-controller',
  template: `
    <ul>
      <li *ngFor="let i in obj">
        <b>{{i}}</b>: {{obj[i]}}
      </li>
    </ul>`
})
class SampleController {
  obj = {a: 1, b: 2}
}
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

无法绑定到'ngForIn',因为它不是'li'的已知属性.

我已经包含FormsModule并BrowserModule在imports一节@NgModule此组件.

是否有可能使用ngForIn上li,如果没有有一个惯用的方法吗?

typescript ngfor angular

7
推荐指数
1
解决办法
2483
查看次数

标签 统计

angular ×2

ionic2 ×1

ngfor ×1

typescript ×1