0

I have an input field, where you can specify min number of reviews. I also have a function that updates data that ng-repeat populates and create the table. But what I need is, when you type some number into input field this function of mine, runs automatically and changes data which means that my table is up-to-date automatically. It is some sort of two-way binding. (I don't want to use filter directly on my ng-repeat, filters in angular run very frequently and decrease performance)

Here is my input field:

<label>Reviews Min: <input type="number" ng-init="revNum=30" class="form-control review-input" min="0" step="10" ng-model="filterValues.revNum" /></label>

Here is my ng-repeat:

 ng-repeat="car in sortedCarList"

And here is the function:

$scope.formattedTable = function(index){
    $scope.initCarList(index);
    $scope.sortedCarList = [];
    var carlistLength = $scope.carList.length;
    for (var i=0;i<carlistLength;i++){   // just checks every row if values passes user requirements like: min number of review and price range
        var rowBool = $scope.tableFilter($scope.carList[i]);
        if (rowBool){
            $scope.sortedCarList.push($scope.carList[i]);
        }
    }
}

How can I achieve this?

1
  • Have you tried using ng-change? Commented Oct 6, 2014 at 12:43

2 Answers 2

1

Use the ng-change directive to run a specific function every time the input changes.

<label>Reviews Min: <input type="number" ng-init="revNum=30" class="form-control review-input" min="0" step="10" ng-model="filterValues.revNum" ng-change="formattedTable()" /></label>
Sign up to request clarification or add additional context in comments.

Comments

1

there a two methodes:

a) Watcher:

$scope.$watch('filterValues.revNum', function() {
    $scope.formattedTable();
});

b) ng-change:

<label>Reviews Min: <input type="number" ng-init="revNum=30" class="form-control review-input" min="0" step="10" ng-model="filterValues.revNum" ng-change="formattedTable()"/></label>

Comments

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.