prozaek.prozaek prozaek.prozaek - 1 month ago 5
AngularJS Question

how to apply a filter for an attribute?

Please help solve the problem.

I write custom filter for text. in first case i output myText and apply filter, result is OK

html:

<div ng-app="main4">
<md-content ng-controller="main4Ctrl">
<h2 class="md-display-1 ng-binding">Главная страница 3</h2>

<sapn id="firstCase">{{myText | transform}}</sapn> - it worked
<hr>
<span id="secondCase" ng-bind-html="myText"/> - but it not worked
</md-content>
</div>


js:

angular.module('main4', [])
.controller('main4Ctrl', ['$rootScope', '$scope', '$timeout',
function($rootScope, $scope, $timeout) {
$scope.myText = 'qWeRtYuIoP';
}
]).filter('transform',[function(){
return function(text){
return transformTetx = text.toLowerCase();
}
}]);


I need apply this filter for second case

JSFILLDE

Answer

You'll need angular sanitize in order to use ng-bind-html

angular.module('main4', ['ngSanitize'])
.controller('main4Ctrl', ['$rootScope', '$scope', '$timeout',
  function($rootScope, $scope, $timeout) {
    $scope.myText = 'qWeRtYuIoP';
  }
]).filter('transform',[function(){
  return function(text){
    return transformTetx = text.toLowerCase();
  }
}]);

<span id="secondCase" ng-bind-html="myText | transform"></span>

I have updated your FIDDLE

Comments