javascript - Multiple custom filters in AngularJS -


i want put 2 customs filters on data. each filter working independently, when put 2 on same data, have error message (typeerror: input.replace not function), if comment this, have error message (error: [$sce:itype] attempted trust non-string value in content requiring string: context: html)

the 2 customs filters gobold take no argument, , limithellip takes maximum length of string argument.

thanks lot, here code :

angular.module('appfilters', []).  	filter('gobold', function($sce) {  		return  function (input) {  			input = input.replace(' filter ',' <strong>word filtered</strong> ');  			return $sce.trustashtml( input );  		}  	}).  	filter('limithellip', function($sce) {  		return  function (input, limit) {  			console.log(limit);  			if( input.length > 100 ) {  				input = input.substring(0,100);  				var index = input.lastindexof(" ");  				input = input.substring(0,index) + "&hellip;";  			}  			return $sce.trustashtml( input );  		}  	});
<ion-content class="has-subheader">    <ion-item class="element item item-divider" data-ng-repeat="item in blocinfos" >      <a href="#/list/{{ item.url }}">        <img data-ng-src="img/{{ item.imageurl }}" alt="">        <h2 class="title">{{ item.title }}</h2>      </a>      <p data-ng-bind-html="item.text | limithellip: 100 | gobold" class="wrap"></p>    </ion-item>  </ion-content>

this because first filter return $sce.trusashtml() object , not string can't call replace() method.

so, have change string

plunkr

filters

angular.module('appfilters', []). filter('gobold', function($sce) {     return  function (input) {        input = input.tostring(); //this line added          input = input.replace(' filter ',' <strong>word filtered</strong> ');         return $sce.trustashtml( input );     } }). filter('limithellip', function($sce) {     return  function (input, limit) {         input = input.tostring();      //maybe have add here         console.log(limit);         if( input.length > limit ) {             input = input.substring(0,limit);             var index = input.lastindexof(" ");             input = input.substring(0,index) + "&hellip;";         }         return $sce.trustashtml( input );     } }) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -