3

I am making DOM object through javascript and i want it to render it through angularjs but it display like [object HTMLDivElement]

but in browser console its output of dom object in console

but it renders like output in browser

.directive('attachmentify', [

function() {
    return {
        restrict: 'A',
        scope: {
            item: "@filename"
        },
        template: "<div ng-bind-html='content'></div>",
        compile: function(iElement, iAttrs) {
            return function($scope, element, attr) {
                var file = $scope.item;

                // console.log
                // $scope.file =file;
            }
        },
        controller: function($scope) {
            var img = ['jpg', 'jpeg', 'png'];
            var c = 0;
            img.forEach(function(element, index) {
                if ($scope.item.endsWith(element)) c++;
            });
            if (c) {
                var div = document.createElement('div');
                div.setAttribute('name', 'samundra')
                div.innerHTML = "ram"
            } else {
                var div = document.createElement('div');
                div.setAttribute('name', 'ramundra')
                div.innerHTML = "sam"
            }

            $scope.content = div; 
            console.log(div);
        }
    }
}

])

1 Answer 1

2

In your controller instead of assign DOM element instance, You can set $scope.content to html

$scope.content="<div name='ramundra'>ram></div>";
Sign up to request clarification or add additional context in comments.

1 Comment

how to do the same with just a div? how can I bind the object to just a div's inner HTML.

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.