javascript - Get value from directive in html table -
i using angular js. want value input inside row in table.
below there input element. when click button (add) need value particular row.
view
<tr ng-click="" ng-repeat='customer in customers | filter:query | orderby: sort.field : sort.order'> <td ng-repeat='field in fields'> {{customer[field]}} </td> <td mult-ecs> <p class="input-group"> <span class="input-group-addon">rs</span> <input class="form-control" name="debit" type="text" ng-model="customer['id'].value"> </p> <button ng-click="addmulecs(customer['id'])" class="btn btn-primary btn-sm" >add</button> <button ng-click="removemulecs(customer[id])" class="btn btn-danger btn-sm" >remove</button> </td> </tr>
controller
.directive('multecs', ['$http', function($http){ return{ restrict: 'a', replace:false, scope:{ }, link: function(scope, elem, attr){ scope.addmulecs = function(id){ } } } }]);
image of table
you can refer controller scope's variable binding directive scope. in case think one way binding
suit situation.
in directive setting:
scope:{ localecsvalue : "@ecsvalue" },
and in template :
<td mult-ecs ecs-value="customer['id'].value">
this bind scope.localecsvalue
customer['id'].value
in controller.
and in link
function can :
scope.addmulecs = function(id){ alert( scope.localecsvalue() ) }
be careful using ng-model
inside directive. directive create isolated scope , cause ng-model not bind correct variable. check more info
Comments
Post a Comment