Evaluating scope variables inside ng-repeat with handcrafted html

var directive_app = angular.module('dx.directives', []);
var service_app = angular.module('dx.services', []);
var filter_app = angular.module('dx.filters', []);
var app = angular.module('dx', ['ngResource', 'dx.directives', 'dx.services', 'dx.filters'], function ($compileProvider) {
    $compileProvider.directive('compile', function ($compile) {
        return function (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 data-ng-repeat="iesire in iesiri">
     <td data-compile="template"></td>
</tr>

Further reading: http://docs.angularjs.org/api/ng.$compile

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>