0

Following the code snippet of the control that I am creating. This control is used in various places and the variables differ.

I am trying to write a directive to clean up code, but getting a parse error while inserting values near {{}}.

New to angular and not able to pin point what is it that I am missing. Please help.

track-edit is another directive.

Original control code:

<div id="text-wrapper">
                    <div track-edit="true" id="Type1Desc_{{t1Card.id}}" class="textbody" ng-blur="SaveDesc('Type1Desc_'+t1Card.id,t1Card.Description,'Type1')">
                        <div>
                            <p><div spellcheck="true"  ng-bind-html="t1Card.OrigDescription|diff:t1Card.Description"></div></p>
                        </div>
                    </div>
                </div>

Directive code

app.directive('customEditor', function () {
    return {
        restrict: "E",
        scope: {
            fId: "@",
            idAppend: "@",
            className: "@",
            origVal: "@",
            currVal: "@"
        },
        replace: true,
        transclude: false
        template: ' <div id="text-wrapper"><div track-edit="true" id="{{idAppend}}_{{fId}}" ' +
        'class="{{className}}" ><div><p>' +
        '<div spellcheck="true"  ng-bind-html="{{origVal}}|diff:{{currVal}}"></div></p></div></div></div>',
        link: function (scope, element, attrs) {

        }
    }
});

Html after directive:

 <custom-editor fid="{{t1Card.id}}" idappend="Type1Desc" classname="textbody" ng-blur="SaveLineItemDesc('Type1Desc_'+t1Card.id,t1Card.Description,'Type1')" origVal="{{t1Card.OrigDescription}}" currVal="{{t1Card.Description}}">
 </custom-editor>
user2412146
  • 103
  • 1
  • 1
  • 13

1 Answers1

1

I think your mistake is in this part:

fId: "@",
idAppend: "@",
className: "@",
origVal: "@",
currVal: "@"

It should be:

fid: "@",
idappend: "@",
classname: "@",
origVal: "@",
currVal: "@"

And in the directive:

<custom-editor fid="{{t1Card.id}}" idappend="Type1Desc" classname="textbody" ng-blur="SaveLineItemDesc('Type1Desc_'+t1Card.id,t1Card.Description,'Type1')" origVal="{{t1Card.OrigDescription}}" currVal="{{t1Card.Description}}">
 </custom-editor>

You have idappend but you are referring as idAppend, which is wrong. You should refer to it as idappend. Same is applicable to fid and classname which should refer as it is with no camelcase format

EDIT CODE-

If you trusting origVal and currVal value then replace this statement :

ng-bind-html="{{origVal}}|diff:{{currVal}}"

with this one

ng-bind-html-unsafe="{{origVal}}|diff:{{currVal}}"

Or you can use $sce like this one

$sce.parseAsHtml(your_data_value)

For more you can refer this one also. With ng-bind-html-unsafe removed, how do I inject HTML?

Community
  • 1
  • 1
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53