AngularJS two way binding variables to array items -
to view code follow link
i've created directive handles array of items (it 2 because it's "from" , "to" date pair).
i want make array items accessible separate values later use refer array items
vm.data = ['data a', 'data b']; vm.separatedata = vm.data[0]; vm.otherdata = vm.data[1];
when implement 2 way bind directive, vm.data[0]
, vm.data[1]
references updated vm.separatedata
, vm.otherdata
aren't.
is there way of making work or should restructure rest of app (where needed) accomodate array items?
in fiddle link (same above) try changing text input values , you'll see mean.
vm.data[0] string , primitive datatype in javascript immutable. bind immutable string 'data a' vm.separatedata, not reference data[0].
if want copy reference array vm.separatedata try wrap strings in other javascript objects, e.g.
vm.data = [{"value":"data a"}, {"value":"data b"}]
and can reference
vm.separatedata = vm.data[0];
and access value via
vm.separatedata.value
Comments
Post a Comment