S
S
Sergey2019-09-30 13:54:55
Angular
Sergey, 2019-09-30 13:54:55

How to add markup with ng-repeat?

Good afternoon.
For a blog, I store the content of the post in an object:

vm.postArr = [{
            title:"newPosr",
            data:'January 1, 2014',
            author:'Mark',
            body:'<p>This blog post.</p>'
        }]

I'm going to store the markup in the body property in order to be able to insert lists, headings and other joys. How to implement placement in the body of the template of the markup, and not of the text string when bypassing the array using ngRepeate. I write in AngularJs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2019-09-30
@Banjamin

Problem solved.
I create a directive:

.directive('compile', function($compile){
            return function(scope, element, attr){
                const body = angular.element(attr.compile)
                const compileFunc = $compile(body);
                compileFunc(scope)
                element.append(body)
            }
        })

In template<p compile = '{{post.body}}' ></p>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question