mm1975
mm1975

Reputation: 1655

Issues with ng-bind-html in an INPUT

I want to parse the following strings in an Input:

<>, <, >, = (without comma)

The Input will be binded by this Snippet:

JS

$scope.json = null;
$scope.filter = JSON.parse(data);
$scope.$watch('filter', function (newValue) {
    $scope.json = JSON.stringify(newValue, null, 2);
    $scope.output = computed(newValue.group);
}, true);

If I now use:

<input type="text" ng-bind="output"/>

I get the output: &lt;&gt; (for eg for <>)

If I use

<input type="text" ng-bind-html="output"/>

Nothing happens.

Correct would be the <> in the input

Is there an easy way to do this?

Upvotes: 0

Views: 265

Answers (2)

thomaux
thomaux

Reputation: 19708

Use the ngModel binding to automatically parse these characters.

<input ng-model="text">

Demo

Upvotes: 0

ReeganLourduraj
ReeganLourduraj

Reputation: 873

Use this filter to parse your operators.

filter("decode",function(){
    return function(str){ 

      var el = document.createElement("div");
      el.innerHTML = str;
      str =  el.innerText || el.textContent;
      return str;

    }
})

Html

 <input type="text" ng-bind="model|decode"  />

Upvotes: 1

Related Questions