Home » Filter – Limit the length of string using AngularJS

Filter – Limit the length of string using AngularJS

Filter – Limit the length of string using AngularJS

Today, We want to share with you Filter – Limit the length of string using AngularJS.
In this post we will show you Angular Filter – Limit the length of string, hear for AngularJS – How to Limit String Length using Filter? we will give you demo and example for implement.
In this post, we will learn about Filter angular Limit the length of string with an example.

Getting Started for Angularjs limit string length

We have used CDN(libs) for AngularJS so you must need Your internet Data connection for them to work on Limit the length of string using AngularJS.

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

index.html

This is the main HTML view of our Simple Web Application. In here, we have init Base declared all our simple my this Example(Filter – find the Limit the length of string using Angular) dependencies and the HTML Elements that we have created.

Read Also:  Custom Pagination Using WooCommerce REST API

<body ng-app="pakaApp" ng-controller="pakaCtrl">
<h2>AngularJS - How to Limit String Length using Filter?</h2>
{{ randomText | limitChar }}

<hr/>

{{ randomText | limitChar:10 }}

<hr/>

{{ randomText | limitChar:10:"...!!!" }}

</body>

index.js

This contains our simple custom index.js files Add Like as javascript, AngularJS scripts source code.

<script>
var pakaApp = angular.module('pakaApp', []);
pakaApp.controller('pakaCtrl', function($scope) {
    $scope.randomText = "Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners.";
});
pakaApp.filter('limitChar', function () {
    return function (dataContentInfo, length, dtlpka) {
        if (isNaN(length))
            length = 50;
 
        if (dtlpka === undefined)
            dtlpka = "...";
 
        if (dataContentInfo.length <= length || dataContentInfo.length - dtlpka.length <= length) {
            return dataContentInfo;
        }
        else {
            return String(dataContentInfo).substring(0, length-dtlpka.length) + dtlpka;
        }
    };
});
<script>

Full Example : Angularjs filter limit characters

<html>
<head>
<title>AngularJS - How to Limit String Length using Filter?</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-app="pakaApp" ng-controller="pakaCtrl">
<h2>AngularJS - How to Limit String Length using Filter?</h2>
{{ randomText | limitChar }}

<hr/>

{{ randomText | limitChar:10 }}

<hr/>

{{ randomText | limitChar:10:"...!!!" }}

<script>
var pakaApp = angular.module('pakaApp', []);
pakaApp.controller('pakaCtrl', function($scope) {
    $scope.randomText = "Any visitors of this site are free to browse our tutorials, live demos and download scripts";
});
pakaApp.filter('limitChar', function () {
    return function (dataContentInfo, length, dtlpka) {
        if (isNaN(length))
            length = 50;
 
        if (dtlpka === undefined)
            dtlpka = "...";
 
        if (dataContentInfo.length <= length || dataContentInfo.length - dtlpka.length <= length) {
            return dataContentInfo;
        }
        else {
            return String(dataContentInfo).substring(0, length-dtlpka.length) + dtlpka;
        }
    };
});
<script>
</body>
</html>

We hope you get an idea about angularjs limit input characters
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

Read Also:  PHP Laravel Get current User Information
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about simple get a Limit the length of string.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Vuejs autocomplete search with typeahead js

We hope This Post can help you…….Good Luck!.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  how to get last inserted record in laravel?
  2. Read Also:  Remove specific value from php array
  3. Read Also:  Top 40 Laravel Interview Questions
  4. Read Also:  PHP Laravel Store Array in Session Examples
  5. Read Also:  Dropdown List using Angular Example
  6. Read Also:  Vuejs color picker Plugins With Examples
  7. Read Also:  Create React Nested Router component
  8. Read Also:  jquery multidimensional array search by value
  9. Read Also:  Laravel Send Emails Mailgun setup Tutorial
  10. Read Also:  laravel checking if record exists

Leave a Comment

Your email address will not be published. Required fields are marked *