Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i render DOM object from angularjs?

Tags:

dom

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);
        }
    }
}

])

like image 815
Samundra Khatri Avatar asked Feb 17 '26 20:02

Samundra Khatri


1 Answers

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

$scope.content="<div name='ramundra'>ram></div>";
like image 131
Sridhar Chidurala Avatar answered Feb 20 '26 13:02

Sridhar Chidurala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!