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

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

    functionlinkFunction(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

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

Post a Comment for "Render Text As Html On Angularjs"