Jeremaine Osia
Jeremaine Osia

Reputation: 15

AngularJS bind select directive

I have dropdown directive here LINK

Need some assistance on how can I bind for my edit and save form.

FOR VIEWING/EDIT: How can I assign my supplier.statusID in my keyword directive?

<tr ng-repeat="supplier in suppliers">
     <td>{{supplier.Id}}</td>                
     <td>{{supplier.Name}}</td>                
     <td>
        <keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" opt-description="Description"></keywords>
        <br />
     </td>
</tr>

FOR ADD NEW RECORD: how can I save the ID of my keyword directive to my supplier.statusID

<div>Name: <input type="text" />
   <br />
   Status: <keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" opt-description="Description"></keywords><br><button>Save</button>
</div>

Upvotes: 0

Views: 109

Answers (1)

enriquecastl
enriquecastl

Reputation: 840

You just need to create a new property called supplierId in your directive's scope and assign the supplier's ID to that property where you declare the directive

app.directive('keywords', function(){
    return {
        restrict: 'E',
        scope: {
            array: '=',
            supplierId : '='
        },
        template:   '<label>{{label}}</label>' +
                    '<select ng-model="supplierId" ng-options="a[optValue] as a[optDescription] for a in array">'...

In the markup

<td><keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" 
      supplier-id="supplier.Id" opt-description="Description"></keywords>
                    <br />
                </td>

I forked your fiddle and make it work

http://jsfiddle.net/XmbHY/

I hope this helps.

Upvotes: 1

Related Questions