limit characters Now. to display only 100 characters change the above code to
limit characters:=>
{{mobileDescription | limitTo: 100}}
- for ex: {{ “My String Is Too Long i think” | limitTo: 9 }}
- the output will be >>> “My String“
Simple isn’t it. But what if we want to display all the text of that model, For doing that we need to initialize a limit value in an outer element so that we can later modify it as shown below:
<div ng-init="limit = 100">
{{mobileDescription | limitTo: limit}}
</div>
<div ng-init="limit = 100; moreShown = false">{{mobileDescription | limitTo: limit}}<a ng-show="mobileDescription .length > limit"href ng-click="limit=mobileDescription .length; moreShown = true"> Show More...</a></div>
Finally, our overall code will be:
<div ng-init="limit = 100; moreShown = false">
{{mobileDescription | limitTo: limit}}{{mobileDescription .length > limit ? '...' : ''}}
<a ng-show="mobileDescription .length > limit"
href ng-click="limit=mobileDescription .length; moreShown = true">Show More
</a>
<a ng-show="moreShown" href ng-click="limit=100; moreShown = false">Show Less </a>
</div>
Comments
Post a Comment