javascript - Clear previous data before request -


i've got html-template loads data controller's array , keeps them in table. have directive, makes transclusion table rows. data array being filled on api-requests. after new requests i've got request results merged in table. 1 set of rows being added each request instead of clearing previous results.

i've debugged on controller code check state of array , it's being cleared before each request. that's sure. new results added previous. think reason might in template of transclusion directive.

the template looks like:

<div class="row">     <div class="col-md-12">         <div id="results" ng-show="results.length > 0">             <table class="table result-table">                 <thead>                     <tr>                         <th>1</th>                         <th>2</th>                         <th>3</th>                         <th>4</th>                     </tr>                 </thead>                 <tbody>                     <tr ng-repeat="result in results" my-result></tr>                 </tbody>             </table>         </div>     </div> </div> 

here code of transclusion directive:

angular.module('app').directive('myresult', ['$compile', function ($compile) {     return {         transclude: true,         templateurl: '/scripts/app/templates/resulttemplate.html',         compile: function (telement, tattr, transclude) {             var contents = telement.contents().remove();             var compiledcontents;             return function (scope, ielement, iattr) {                 if (!compiledcontents) {                     compiledcontents = $compile(contents, transclude);                 }                 compiledcontents(scope, function (clone, scope) {                     ielement.replacewith(clone);                 });             };         }     } }]); 

and template used transclusion:

<tr class="big-bord">     <td colspan="4"><h3>{{result.fullname}}</h3></td> </tr> <tr ng-repeat="item in result.items">     <td>{{item.value1}}</td>     <td>{{item.value2}}</td>     <td>{{item.value3}}</td>     <td>{{item.value4}}</td> </tr> 

how can clear results before each api requests?

i solved problem. turned out multiple <tbody> tags allowed within 1 table. moved ng-repeat <tbody> tag:

<tbody ng-repeat="result in results">     <tr class="big-bord">         <td colspan="4"><h3>{{result.fullname}}</h3></td>     </tr>     <tr ng-repeat="item in result.items">         <td>{{item.value1}}</td>         <td>{{item.value2}}</td>         <td>{{item.value3}}</td>         <td>{{item.value4}}</td>     </tr> </tbody> 

so, don't need directives @ all.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -