0

I am trying to access the value in node js using req.body which is in ng-model, actually my ng-model is having a angular js filter,I need to get that filter value from the input field in node js using req.body, I paste my ng-model code snippet here, please help me to resolve

    <input type="disable" ng-disabled="true" class="form-control"
           name="count" ng-model="table.fields | mysum">

angular filter

app.filter('mysum', function() {
  return function(items) {
    var sum = 0;
    items.forEach(function(item) {
     if (item.item_count) {
         sum += item.item_count;      
      }     
    })
    return sum;
  }
})
3
  • You can't use ng-model with a filter -- ng-model needs to bind to property. Commented Dec 28, 2015 at 5:16
  • @ExplosionPills can you please tell how can I access the filter in ng-model have any idea Commented Dec 28, 2015 at 5:40
  • I think you should $watch for the model change and update the model value Commented Dec 28, 2015 at 5:50

1 Answer 1

0

This would be your DOM, you can't apply filters to ng-model.

<input type="disable" ng-disabled="true" class="form-control"
           name="count" ng-model="table.fields">

And in your controller code, do something like this. Inject $filter as dependency in your controller.

$scope.table = {};
$scope.table.fields = $filter('mySum')($scope.table.fields);

//watch for updated value... .
$scope.$watch('table.fields', function() {
    //watch for changes and do something... 
});
Sign up to request clarification or add additional context in comments.

2 Comments

how can I send that to node express like req.body to store that value in mysql table
if I want to watch this field means <input type="number" ng-model="table.fields[$index].item_count" class="form-control" name="item_count" ng-pattern="/^[0-9]/" placeholder="Category Item View Count" required> should I igve like this in my watch $scope.$watch('table.fields[$index].item_count', function(){}); is the above one is correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.