Skip to content Skip to sidebar Skip to footer

How To Add Dynamic Parameters/variables To Templates Rendered With Ng-bind-html Or Custom Directive (inside Ng-repeat)

EDIT: Here is the solution sample based on the first answer. You're still welcome to offer further suggestions and fill some gaps in my knowledge (see comments). plnkr.co/edit/mqGC

Solution 1:

I suggest using ngInclude, in which you can have a funciton that check for the proper template to load based on the passed page structure.

<div ng-repeat="structure in page_structure">
    <div ng-include="getMyTemplate(structure)"></div>    
</div>

$scope.getMyTemplate = function(structure) {
    switch (structure.type) {
        case 'heading':
            return '/Views/Heading.html' // or id of a pre-loaded template
        case 'paragraph':
            return '/Views/Paragraph.html' // or id of a pre-loaded template
    }
}

Post a Comment for "How To Add Dynamic Parameters/variables To Templates Rendered With Ng-bind-html Or Custom Directive (inside Ng-repeat)"