- for array data sources:
label
for
value
in
array
select
as
label
for
value
in
array
label
group by
group
for
value
in
array
select
as
label
group by
group
for
value
in
array
track by
trackexpr
- for object data sources:
label
for (
key
,
value
) in
object
select
as
label
for (
key
,
value
) in
object
label
group by
group
for (
key
,
value
) in
object
select
as
label
group by
group
for
(
key
,
value
) in
object
Where:
array
/object
: an expression which evaluates to an array / object to iterate over.value
: local variable which will refer to each item in thearray
or each property value ofobject
during iteration.key
: local variable which will refer to a property name inobject
during iteration.label
: The result of this expression will be the label forelement. The
expression
will most likely refer to thevalue
variable (e.g.value.propertyName
).select
: The result of this expression will be bound to the model of the parentelement. If not specified,
select
expression will default tovalue
.group
: The result of this expression will be used to group options using theDOM element.
trackexpr
: Used when working with an array of objects. The result of this expression will be used to identify the objects in the array. Thetrackexpr
will most likely refer to thevalue
variable (e.g.value.propertyName
).
Hunh? What if you simply want a value for each option, you know, like you used to get back in the old days? Here is our options
$scope.unitOptions =[{VALUE:"CRB11",LABEL:"20FT CONTAINER"},{VALUE:"CRB12",LABEL:"40FT CONTAINER"},{VALUE:"CRB3",LABEL:"CARTONS"},{VALUE:"CRB6",LABEL:"ENVELOPES"},{VALUE:"FRT25",LABEL:"ITEMS"},{VALUE:"CRBx2",LABEL:"ITEMS IN THE LOT"},{VALUE:"CRBx1",LABEL:"LITRES"},{VALUE:"CRB5",LABEL:"PALLETS"},{VALUE:"CRB14",LABEL:"PALLETS OR SKIDS"},{VALUE:"CRB4",LABEL:"SKIDS"},{VALUE:"FRFCB16",LABEL:"SPA"}];
So item_units will receive the opt.VALUE rather than a reference to an object. From the above "opt.VALUE as opt.LABEL for opt in unitOptions" matches the form "
select
as
label
for
value
in
array"
from the documentation. I read that as ;opt.VALUE is the id for the displayed opt.LABEL for each of the opt objects in unitOptions
Not complaining, Angular is a great way of organizing the frontend. I can see why they wrote it the way they did, but it doesn't bring us any closer to literate programming.