无法向表angularjs添加新行

时间:2017-01-07 08:05:58

标签: html css angularjs

如何在angularjs中将新行添加到表中。单击添加按钮无法将新行添加到现有表。这是plunkr - https://plnkr.co/edit/s7XAaG4JbvbTTxiZ0V2z?p=preview

html -

<html>
<head>
<script src="angular.min.js"></script>

<script src="script.js"></script>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="font-awesome.min.css"/>
<link rel="stylesheet" href="bootstrap.min.css" />
</head>
<body data-ng-app="testApp" data-ng-controller="treeTable">
<div  class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-9">
    <div class="tableheight ">
  <table class="treetable-nested childtable">
    <thead>
      <tr>
        <!-- <th >
          <input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" />
        </th> -->
        <th class="cell-members">
         <input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" /> Name
        </th>
        <th class="cell-members">
          Version
        </th>
        <th class="cell-members">
          Size
        </th>
        <th class="cell-members">
        Modified By
        </th>
        <th class="cell-members">
        Labels
        </th>
        <th class="cell-members">
        Description
        </th>
      </tr>
    </thead>
    <tbody class="newRepo" style="font-size:12px" data-ng-class="{opened: item.opened}" data-ng-include="&#39;table_tree.html&#39;" data-ng-repeat="item in list"></tbody>
  </table>
    </div>
  <script id="table_tree.html" type="text/ng-template">
    <tr ng-class="{parent: item.children}" ng-init="parentScope = $parent.$parent; initCheckbox(item, parentScope.item)">

      <td class="cell-name top-border" ng-if="level &amp;&amp; level &gt; 1">
      <span style="padding-left: 30px" >&nbsp;  <input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}} </span>
      </td>
<td class="cell-name top-border" ng-if=" &#40;&#33;level &amp;&amp; level &lt;&#61; 1 &#41; &#124;&#124 &#40;level &amp;&amp; level &lt;&#61; 1&#41;">
        <span style="padding-left:11px" ng-click="item.opened = !item.opened"></span>&nbsp;<input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}}
      </td>

<td class="cell-name top-border" ng-if="&#33;level">
       <span class="indent" ng-click="item.opened = !item.opened">&nbsp;<input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}} </span>
      </td>

      <td class="cell-name">
        {{item.Version}} 
      </td>
      <td class="cell-name">
        {{item.Size}}
      </td>
      <td class="cell-name">
        {{item.ModifiedBy}}
      </td>
    <td class="cell-name">
        {{item.Labels}}
      </td>
<td class="cell-name">
        {{item.Description}}
      </td>
    </tr>
    <tr class="children" ng-if="item.children &amp;&amp; item.children.length &gt; 0">
      <td colspan="6">
        <table class="childtable">
          <tbody style="font-size:12px" ng-class="{opened: item.opened}" ng-include="&#39;table_tree.html&#39;" ng-init="level = level + 1" ng-repeat="item in item.children"></tbody>
        </table>
      </td>
    </tr>
  </script>
</div>
</div>
</div>
</div>
<button ng-click="addRow()" >Add</button>
</body>
</html>

1 个答案:

答案 0 :(得分:3)

中删除return
return $scope.$on('changeParent', ...

或者以下代码不会被执行,这是$scope.addRow的声明。