Skip to content

Commit 7c3a2b2

Browse files
committed
fix(directive): tables without the directive are ignored
Closes #18
1 parent e7e5e6b commit 7c3a2b2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/directive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ function wtResponsiveTable() {
6565
function wtResponsiveDynamic() {
6666
return {
6767
restrict: 'E',
68-
require: '^^wtResponsiveTable',
68+
require: '?^^wtResponsiveTable',
6969
link: function (scope, element, attrs, tableCtrl) {
70+
if (!tableCtrl) return;
71+
7072
setTimeout(function () {
7173
Array.prototype.forEach.call(element[0].parentElement.querySelectorAll("td"), function (td) {
7274
var th = tableCtrl.getHeader(td);

tests/directive.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,37 @@ describe('directive', function () {
360360
});
361361

362362
describe('responsive-dynamic', function () {
363+
364+
it('TDs are handled only on tables with wt-responsive-table', function (done) {
365+
var markup = [
366+
'<table>',
367+
' <thead>',
368+
' <tr>',
369+
' <th>column</th>',
370+
' <th>simple</th>',
371+
' </tr>',
372+
' </thead>',
373+
' <tbody>',
374+
' <tr>',
375+
' <td>jerry</td>',
376+
' <td>tom</td>',
377+
' </tr>',
378+
' </tbody>',
379+
'</table>'
380+
].join('');
381+
var element = angular.element(markup);
382+
var scope = $rootScope.$new();
383+
$compile(element)(scope);
384+
scope.$digest();
385+
386+
var els = element.find('tbody tr:first td');
387+
setTimeout(function () {
388+
expect(els.attr('data-title')).toBeUndefined();
389+
done();
390+
}, 0);
391+
});
392+
393+
363394
it('supports ng-if applied on all TDs', function (done) {
364395
var markup = [
365396
'<table wt-responsive-table>',

0 commit comments

Comments
 (0)