0

In this plunk I have a directive with a table. I'm trying to add dynamically to the table one row with two cells. Still, the table is showing only one cell. What's wrong with this code?

Javascript

angular.module('app', []);


angular.module('app')
.directive('directive1', function() {


    var directive = {};

    directive.restrict = 'E';

    directive.scope = true;

    directive.template = '<table class="c" border="1"></table>';

    directive.link = function(scope, element, attrs) {

                var t = angular.element(".c");
                var r1 = t.append("<tr></tr>");
                var col1 = r1.append("<td></td>");
                col1.text("1111");
                var col2 = r1.append("<td></td>");
                col2.text("2222");

    };

    return directive;

});
2
  • Actually it isn't creating any cell, you can check it inspecting the generated HTML. Commented Aug 2, 2016 at 2:39
  • I know, but how to fix this? Commented Aug 2, 2016 at 2:43

2 Answers 2

1

This could work as well:

var t = angular.element(".c");
var r1 = t.append(angular.element(document.createElement('tr')));
var col1 =angular.element(document.createElement('td')).html("1111");
var col2 =angular.element(document.createElement('td')).html("2222");
r1.append(col1);
r1.append(col2);
Sign up to request clarification or add additional context in comments.

Comments

0

This worked:

            var t = angular.element(".c");
            var r1 = $("<tr></tr>")
            t.append(r1);
            var col1 = $("<td></td>");
            r1.append(col1);
            col1.text("1111");
            var col2 = $("<td></td>");
            r1.append(col2);
            col2.text("2222");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.