0

I'm trying to write a test directive that just shows some markup on the web page. For some reason, when I try to update the markup using AngularJS's angular.element() function, it only shows a visual representation of the object. Much like viewing a JavaScript object from the browser.

[[object HTMLInputElement], [object HTMLSpanElement], [object HTMLBRElement]]

This is my template page where I am just spitting out the directive, it's too simple.

<div my-sample></div>

My directive looks like this,

eventsApp.directive('mySample', function ($compile) {
    var markup = '<input type="text" ng-model="sampleData" /> {{ sampleData }} <br />';
    return {
        link: function (scope, element, atts, controller) {
            angular.element(element).html($compile(markup)(scope));
        }
    }
});

What am I doing wrong?

2
  • 1
    the code seems correct JSFiddle Commented Aug 28, 2017 at 16:01
  • Hence my confusion. Commented Aug 28, 2017 at 16:45

1 Answer 1

1

$compile returns DOM elements, not HTML. Try just element.empty().append($compile(markup)(scope)) instead of using the .html() function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.