Skip to content Skip to sidebar Skip to footer

Render Text As HTML On AngularJS

I'm trying to display text fields (like a form) inside a table. I got a button, when I click it one new line is added to the table and all the cells are form fields. When I click t

Solution 1:

The text needs to be compiled as html by Angular for it to render properly. Try creating a 'compile' directive. That will call $compile on any text passed into it..

assets.directive('compile', compile);

function compile($compile)
{
    return {
        restrict: 'A',
        replace: true,
        link: linkFunction
    };

    function linkFunction(scope, element, attrs)
    {
        scope.$watch(
            function (scope)
            {
                return scope.$eval(attrs.compile);
            },
            function (value)
            {
                element.html(value);

                $compile(element.contents())(scope);
            }
        );
    }
}

.. and in your template

<tr ng-repeat="atribut in atributs">
    <td compile="nomAtribut"></td>
    <td compile="tipus"></td>
    <td compile="mida"></td>
    <td compile="prioritat"></td>
    <td compile="obligatori"></td>
</tr>

Post a Comment for "Render Text As HTML On AngularJS"