{"id":11521,"date":"2014-01-29T17:10:35","date_gmt":"2014-01-29T11:40:35","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11521"},"modified":"2017-08-03T16:03:08","modified_gmt":"2017-08-03T10:33:08","slug":"writting-your-own-filters-in-angular-js","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/","title":{"rendered":"Writting Your Own Filters In Angular JS"},"content":{"rendered":"<p>While <a title=\"Angular Development\" href=\"http:\/\/www.tothenew.com\/front-end-angularjs-development\">using AngularJS<\/a>, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, <strong>filters<\/strong> comes to rescue.<\/p>\n<p>We can define our custom filters and return filtered data in whichever way we want to display it.<\/p>\n<p>Lets learn it through an example:<\/p>\n<p>[js]<br \/>\nangular.module(&#8216;myDemoApp&#8217;, []).filter(&#8216;truncate&#8217;,function () {<br \/>\n                    return function (input, length) {<br \/>\n                        input = input + &quot;&quot;;<br \/>\n                        if (input.length &gt; length) {<br \/>\n                            var desc = input.substring(0, length);<br \/>\n                            return desc + &quot;&#8230;&quot;;<br \/>\n                        } else {<br \/>\n                            return input;<br \/>\n                        }<br \/>\n                    };<br \/>\n                })<br \/>\n[\/js]<\/p>\n<p>Here, we have defined a filter named <strong>&#8220;truncate&#8221;<\/strong> which return a string concatenated with (&#8230;) if length of the string is more than parameter provided to the filter, otherwise return the same string as it is. So, we have a function with two arguments, first one is the string itself and second one is the length upto which we want to truncate the string.<\/p>\n<p>Now we can simply use the filter in our html code.<\/p>\n<p>[html]&lt;\/pre&gt;<br \/>\n&lt;div&gt;{{ place | truncate:8}}&lt;\/div&gt;<br \/>\n&lt;pre&gt;<br \/>\n[\/html]<\/p>\n<p>For example if place is &#8220;Netherlands&#8221;, it will print <code>Netherla...<\/code><\/p>\n<p>Similarly we can write our own filters according to our need.<\/p>\n<p>Hope this will help \ud83d\ude42<\/p>\n<p><a href=\"http:\/\/www.tothenew.com\/blog\/building-intuitive-frontend-interfaces-with-angularjs\/\">Building Intuitive Frontend Interfaces with AngularJS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4,"footnotes":""},"categories":[1439,3429],"tags":[3955,955,4697],"class_list":["post-11521","post","type-post","status-publish","format-standard","hentry","category-angular","category-front-end-development","tag-angular-development","tag-angularjs","tag-angularjs-development-company"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Sakshi Tyagi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Writting Your Own Filters In Angular JS | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Writting Your Own Filters In Angular JS | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#article\",\"name\":\"Writting Your Own Filters In Angular JS | TO THE NEW Blog\",\"headline\":\"Writting Your Own Filters In Angular JS\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2014-01-29T17:10:35+05:30\",\"dateModified\":\"2017-08-03T16:03:08+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#webpage\"},\"articleSection\":\"AngularJS, Front End Development, angular development, AngularJS, AngularJS Development Company\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/angular\\\/#listItem\",\"name\":\"AngularJS\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/angular\\\/#listItem\",\"position\":2,\"name\":\"AngularJS\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/angular\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#listItem\",\"name\":\"Writting Your Own Filters In Angular JS\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#listItem\",\"position\":3,\"name\":\"Writting Your Own Filters In Angular JS\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/angular\\\/#listItem\",\"name\":\"AngularJS\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/\",\"name\":\"Sakshi Tyagi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Sakshi Tyagi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/\",\"name\":\"Writting Your Own Filters In Angular JS | TO THE NEW Blog\",\"description\":\"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/writting-your-own-filters-in-angular-js\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/sakshi\\\/#author\"},\"datePublished\":\"2014-01-29T17:10:35+05:30\",\"dateModified\":\"2017-08-03T16:03:08+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Writting Your Own Filters In Angular JS | TO THE NEW Blog","description":"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn","canonical_url":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#article","name":"Writting Your Own Filters In Angular JS | TO THE NEW Blog","headline":"Writting Your Own Filters In Angular JS","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2014-01-29T17:10:35+05:30","dateModified":"2017-08-03T16:03:08+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#webpage"},"articleSection":"AngularJS, Front End Development, angular development, AngularJS, AngularJS Development Company"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/angular\/#listItem","name":"AngularJS"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/angular\/#listItem","position":2,"name":"AngularJS","item":"https:\/\/www.tothenew.com\/blog\/category\/angular\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#listItem","name":"Writting Your Own Filters In Angular JS"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#listItem","position":3,"name":"Writting Your Own Filters In Angular JS","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/angular\/#listItem","name":"AngularJS"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/","name":"Sakshi Tyagi","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a42c6deb088e18815dfcfed629c77b032d17bf973881421880b9c5e4ba713739?s=96&d=mm&r=g","width":96,"height":96,"caption":"Sakshi Tyagi"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/","name":"Writting Your Own Filters In Angular JS | TO THE NEW Blog","description":"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/sakshi\/#author"},"datePublished":"2014-01-29T17:10:35+05:30","dateModified":"2017-08-03T16:03:08+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Writting Your Own Filters In Angular JS | TO THE NEW Blog","og:description":"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn","og:url":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Writting Your Own Filters In Angular JS | TO THE NEW Blog","twitter:description":"While using AngularJS, we come across situation in which we want to display some data in certain format or some specific condition to be applied on the data. In this case, filters comes to rescue. We can define our custom filters and return filtered data in whichever way we want to display it. Lets learn","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"11521","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:06:02","updated":"2024-02-29 10:49:22","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/angular\/\" title=\"AngularJS\">AngularJS<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWritting Your Own Filters In Angular JS\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"AngularJS","link":"https:\/\/www.tothenew.com\/blog\/category\/angular\/"},{"label":"Writting Your Own Filters In Angular JS","link":"https:\/\/www.tothenew.com\/blog\/writting-your-own-filters-in-angular-js\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11521"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11521\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}