Skip to main content
Relanzada por el usuario Comunidad
Mejorando formato. Indentando código.
Origen Enlace

tengoTengo un array de elementos donde solo quiero traer el primero.  ("sale_price"sale_price), pero en ngForngFor trae todos los "sale_price" <*ngFor="let valor of equipo.equipment_details;">{{valorsale_price.sale_price}}</>

Código Angular:


"equipment_details": [
                {
                    "id": 7,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933975Z",
                    "modified": "2017-11-16T14:49:46.839778Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 6,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933417Z",
                    "modified": "2017-11-16T14:49:46.875055Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 8,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.934477Z",
                    "modified": "2017-11-16T14:49:46.740048Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                }
            ]

<*ngFor="let valor of equipo.equipment_details;">{{valor.sale_price}}</>

Objeto:

"equipment_details": [
    {
        "id": 7,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.933975Z",
        "modified": "2017-11-16T14:49:46.839778Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    },
    {
        "id": 6,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.933417Z",
        "modified": "2017-11-16T14:49:46.875055Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    },
    {
        "id": 8,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.934477Z",
        "modified": "2017-11-16T14:49:46.740048Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    }
]

tengo un array de elementos donde solo quiero traer el primero.("sale_price") pero en ngFor trae todos los "sale_price" <*ngFor="let valor of equipo.equipment_details;">{{valor.sale_price}}</>


"equipment_details": [
                {
                    "id": 7,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933975Z",
                    "modified": "2017-11-16T14:49:46.839778Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 6,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933417Z",
                    "modified": "2017-11-16T14:49:46.875055Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 8,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.934477Z",
                    "modified": "2017-11-16T14:49:46.740048Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                }
            ]

Tengo un array de elementos donde solo quiero traer el primero  (sale_price), pero en ngFor trae todos los sale_price.

Código Angular:

<*ngFor="let valor of equipo.equipment_details;">{{valor.sale_price}}</>

Objeto:

"equipment_details": [
    {
        "id": 7,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.933975Z",
        "modified": "2017-11-16T14:49:46.839778Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    },
    {
        "id": 6,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.933417Z",
        "modified": "2017-11-16T14:49:46.875055Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    },
    {
        "id": 8,
        "sale_price": "0",
        "customer_price": "None",
        "group_plans": [],
        "created": "2017-10-23T21:07:12.934477Z",
        "modified": "2017-11-16T14:49:46.740048Z",
        "memory": null,
        "is_active": false,
        "start": "2017-11-16T21:57:14.299810Z",
        "equipment": 28,
        "promotion": null
    }
]
se eliminaron 16 caracteres en el cuerpo
Origen Enlace
user70775
user70775

al usar ngFor:

al usar ngFor:

Origen Enlace
user70775
user70775

Obtener solo el primer elemento de un array con NgFor

tengo un array de elementos donde solo quiero traer el primero.("sale_price") pero en ngFor trae todos los "sale_price" <*ngFor="let valor of equipo.equipment_details;">{{valor.sale_price}}</>

"equipment_details": [
                {
                    "id": 7,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933975Z",
                    "modified": "2017-11-16T14:49:46.839778Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 6,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.933417Z",
                    "modified": "2017-11-16T14:49:46.875055Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                },
                {
                    "id": 8,
                    "sale_price": "0",
                    "customer_price": "None",
                    "group_plans": [],
                    "created": "2017-10-23T21:07:12.934477Z",
                    "modified": "2017-11-16T14:49:46.740048Z",
                    "memory": null,
                    "is_active": false,
                    "start": "2017-11-16T21:57:14.299810Z",
                    "equipment": 28,
                    "promotion": null
                }
            ]

al usar ngFor: