S
S
Sergey Koshkin2016-01-17 05:33:44
Angular
Sergey Koshkin, 2016-01-17 05:33:44

How to use as filter for ng-repeat in AngularJs?

Is there <input type="date">a sign with ng-repeat under it? By default, ng-repeat displays elements with today's date. And it is necessary that after changing the date in the input, the content in ng-reapeat changes (with the date from the input).
update :
Tried to do it this way:
in html

<input type="date" ng-model="bd" />
  <button ng-click='changeDate()'>Ok</button>

in controller
$scope.changeDate = function() {
     var changedDate = $scope.bd;
     $http.get("/api/meals/" + changedDate)
          .success(function(data) {
              self.updateMeals(data);
              console.log($scope.bd);
            })
          .error(function(){
            console.log('Error get Meals')
          });
   };

but the trouble is that the date leaves the input in this format:
"Thu%20Feb%2018%202016%2000:00:00%20GMT+0200%20(EET)"
and you need it in this format:
"2015-1-1"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2016-01-18
Protko @Fesor

don't use filters with ngRepeat. That's all science.
To change today's date (for example, using ngChange or other callbacks of your datepicker directive), we simply call the controller method that will form a new collection. And that's all.
ps no $scope.$watch ! and generally don't use $scope anywhere except in a link directive, which you should also rarely ever need. Y031

M
Maxim Dunayevsky, 2016-01-17
@dunmaksim

ng-repeat operates on a set of data. Describe a method in the controller that filters the main set depending on the value in the input. You can use $scope.$watch for this .

N
nk_pl, 2016-01-18
@nk_pl

<input type="text" ng-model="date">
<table>
  	<tr ng-repeat="post in posts | filter:date">
  		<td>{{post.text}}</td>
  		<td>{{post.date}}</td>
  	</tr>
</table>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question