$apply():-
The $scope.$apply() work takes a capacity as parameter which is executed, and after that $scope.$digest() is called inside. That makes it less demanding for you to ensure that all watches are checked, and in this way all information ties invigorated. Here is a $apply()Example:-
$scope.$apply(function() {
$scope.data.myVar = "Another worth";
});
$filter():-
There are two way use filter in angular js
1:-filter in view or HTML page with expression {{--|--}}.
AngularJS provides filters to transform data by default using in expression with HTML tag:
currency
::Format a number to a currency format.date
::Format a date to a specified format.filter
::Select a subset of items from an array.json
::Format an object to a JSON string.limitTo
::Limits an array/string, into a specified number of elements/characters.lowercase
::Format a string to lower case.number
::Format a number to a string.orderBy
::Orders an array by an expression.uppercase
::Format a string to upper case.
<p>The name is {{ lastName | uppercase }}</p>
You can use filter properties after {{--|--}} with any HTML tag.
2:-filter in Angular controller.
Step 1:-Create Html page using Angular.js file
<div ng-app>
<div ng-controller="Demo">
<input type="text" ng-model="search">
<table>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
Step 2:-Create .Js file
Step 3:-Inject $filter in your controller.
function Demo($scope, $filter)
{
$scope.items = [
{id:1, name:'Bikesh'},
{id:2, name:'srivastava'},
{id:3, name:'Alok'},
{id:4, name:'srivastava'},
{id:5, name:'Hitesh singh'}];
$scope.items2 = $scope.items;
$scope.$watch('search', function(val)
{
$scope.items = $filter('filter')($scope.items2, val);
});
};
You have just read an article that categorized by title AngularJs
by title What is $apply() and $filter in AngularJs?. You can bookmark this page with a URL https://bikeshsrivastava.blogspot.com/2016/01/part-9what-is-apply-and-filter-in.html. Thank You!
Author:
Bikesh Srivastava - Sunday, January 31, 2016
Good Post Thanks for sharing this blog. Keep on sharing...
ReplyDeleteAngular JS Online training
Angular JS training in hyderabad