angularjs - Dynamic variable name directive attribute -
i have my-edit directive has value attribute expecting scope variable bind to.
<my-edit value="myvar"></my-edit>
is there way this:
<my-edit value="{{varname}}"></my-edit>
where varname = "myvar"
i want nest directive in "my-listbox" directive has "text-field" attribute
<my-listbox ng-model="mylist" text-field="itemprop"></my-listbox>
so trying use template like:
<div> <ul> <li ng-repeat="item in items"> <my-edit value="item.{{textfield}}"></my-edit> </li> </ul> </div>
but doesn't work
i guess using text binding not solution.
is dynamic generated template "my-listbox" way go here?
i tried in compile function didn't work because of nested nerepeat directive. should done using $compile in link function?
thanks
this pretty cool angular, evaluated string pass directive. means can value="item[textfield]"
, work.
for instance if had controller data this:
$scope.data = { test: 'test_val', other: 'other_val' }; $scope.val = 'test';
you pass directive:
<directive value="data[val]"></directive>
that set this:
scope: { value: '=' },
and isolate scope have scope.value = 'test_val' , update 'other_val' changing original controller val 'other'
i made fiddle set play with.
hope helps!
Comments
Post a Comment