Skip to content

Commit be835a3

Browse files
amcdnljosephperrott
authored andcommitted
chore(nit): address PR feedback
1 parent ab7e49f commit be835a3

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/lib/tabs/tab-group.spec.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,23 +322,26 @@ describe('MdTabGroup', () => {
322322
fixture.debugElement.query(By.directive(MdTabGroup)).componentInstance as MdTabGroup;
323323
});
324324

325-
it('should support a tab-group with the simple api', () => {
326-
expect(getSelectedLabel(fixture).textContent).toMatch('Junk food');
327-
expect(getSelectedContent(fixture).textContent).toMatch('Pizza, fries');
325+
it('should support a tab-group with the simple api', async(() => {
326+
fixture.whenStable().then(() => {
327+
fixture.detectChanges();
328+
expect(getSelectedLabel(fixture).textContent).toMatch('Junk food');
329+
expect(getSelectedContent(fixture).textContent).toMatch('Pizza, fries');
328330

329-
tabGroup.selectedIndex = 2;
330-
fixture.detectChanges();
331+
tabGroup.selectedIndex = 2;
332+
fixture.detectChanges();
331333

332-
expect(getSelectedLabel(fixture).textContent).toMatch('Fruit');
333-
expect(getSelectedContent(fixture).textContent).toMatch('Apples, grapes');
334+
expect(getSelectedLabel(fixture).textContent).toMatch('Fruit');
335+
expect(getSelectedContent(fixture).textContent).toMatch('Apples, grapes');
334336

335-
fixture.componentInstance.otherLabel = 'Chips';
336-
fixture.componentInstance.otherContent = 'Salt, vinegar';
337-
fixture.detectChanges();
337+
fixture.componentInstance.otherLabel = 'Chips';
338+
fixture.componentInstance.otherContent = 'Salt, vinegar';
339+
fixture.detectChanges();
338340

339-
expect(getSelectedLabel(fixture).textContent).toMatch('Chips');
340-
expect(getSelectedContent(fixture).textContent).toMatch('Salt, vinegar');
341-
});
341+
expect(getSelectedLabel(fixture).textContent).toMatch('Chips');
342+
expect(getSelectedContent(fixture).textContent).toMatch('Salt, vinegar');
343+
});
344+
}));
342345

343346
it('should support @ViewChild in the tab content', () => {
344347
expect(fixture.componentInstance.legumes).toBeTruthy();

src/lib/tabs/tab-group.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class MdTabGroup extends _MdTabGroupMixinBase implements AfterContentInit
192192
}
193193
}
194194

195-
ngAfterContentInit() {
195+
ngAfterContentInit(): void {
196196
this._subscribeToTabLabels();
197197

198198
// Subscribe to changes in the amount of tabs, in order to be
@@ -203,7 +203,7 @@ export class MdTabGroup extends _MdTabGroupMixinBase implements AfterContentInit
203203
});
204204
}
205205

206-
ngOnDestroy() {
206+
ngOnDestroy(): void {
207207
this._tabsSubscription.unsubscribe();
208208
this._tabLabelSubscription.unsubscribe();
209209
}
@@ -216,7 +216,7 @@ export class MdTabGroup extends _MdTabGroupMixinBase implements AfterContentInit
216216
this._isInitialized = true;
217217
}
218218

219-
_focusChanged(index: number) {
219+
_focusChanged(index: number): void {
220220
this.focusChange.emit(this._createChangeEvent(index));
221221
}
222222

src/lib/tabs/tab.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<!-- Create a template for the content of the <mat-tab> so that we can grab a reference to this
22
TemplateRef and use it in a Portal to render the tab content in the appropriate place in the
33
tab-group. -->
4-
<ng-template #bodyTemplate>
5-
<ng-content></ng-content>
6-
<ng-template *ngIf="templateBody && templateBody.template"
7-
[ngTemplateOutlet]="templateBody.template">
8-
</ng-template>
9-
</ng-template>
4+
<ng-template><ng-content></ng-content></ng-template>

src/lib/tabs/tab.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ export const _MdTabMixinBase = mixinDisabled(MdTabBase);
4545
export class MdTab extends _MdTabMixinBase implements OnInit, CanDisable, OnChanges, OnDestroy {
4646
/** Content for the tab label given by <ng-template md-tab-label>. */
4747
@ContentChild(MdTabLabel) templateLabel: MdTabLabel;
48-
@ContentChild(MdTabContent) templateBody: MdTabContent;
48+
49+
/** User provided template that we are going to use instead of implicitContent template */
50+
@ContentChild(MdTabContent, {read: TemplateRef}) _explicitContent: TemplateRef<any>;
4951

5052
/** Template inside the MdTab view that contains an <ng-content>. */
51-
@ViewChild('bodyTemplate') _content: TemplateRef<any>;
53+
@ViewChild(TemplateRef) _implicitContent: TemplateRef<any>;
5254

5355
/** The plain text label for the tab, used when there is no template label. */
5456
@Input('label') textLabel: string = '';
@@ -84,6 +86,11 @@ export class MdTab extends _MdTabMixinBase implements OnInit, CanDisable, OnChan
8486
super();
8587
}
8688

89+
ngOnInit(): void {
90+
this._contentPortal = new TemplatePortal(
91+
this._explicitContent || this._implicitContent, this._viewContainerRef);
92+
}
93+
8794
ngOnChanges(changes: SimpleChanges): void {
8895
if (changes.hasOwnProperty('textLabel')) {
8996
this._labelChange.next();
@@ -95,11 +102,6 @@ export class MdTab extends _MdTabMixinBase implements OnInit, CanDisable, OnChan
95102
}
96103

97104
ngOnDestroy(): void {
98-
this._disableChange.complete();
99105
this._labelChange.complete();
100106
}
101-
102-
ngOnInit(): void {
103-
this._contentPortal = new TemplatePortal(this._content, this._viewContainerRef);
104-
}
105107
}

0 commit comments

Comments
 (0)