Here is the defulat tab header template:

<ng-template #defaultTabHeader let-tabs="tabsX">
<ul class="tab-panel-buttons" *ngIf="tabs">
<li
[ngClass]="{selected: tab.selected}"
(click)="selectTab(tab)"
*ngFor="let tab of tabs;">{{tab.title}}
</li>
</ul>
</ng-template> <ng-content
*ngTemplateOutlet="defaultTabHeader; context: tabsContext"></ng-content> <ng-content></ng-content>

we have set up that we can switch the default template when we pass in another template.

Now, what we want is able to pass in a custom template to replace the default header.

  <ng-template #headerButtons>
<button>Login</button>
<button>Sign up</button>
</ng-template>

This is the new template, we want to replace the default header.

Now we pass this to the component:

  <ng-template #headerButtons>
<button>Login</button>
<button>Sign up</button>
</ng-template> <au-tab-panel [headerTemplate]="headerButtons">

Create a 'headerTemplate' Input on the component, and pass in the template ref.

export class AuTabPanelComponent implements OnInit, AfterContentInit {

  @Input()
headerTemplate: TemplateRef<any>;

Now we need to check whether the custom template passed in or not, if passed in then we use custom template, otherwise the default template.

<ng-template #defaultTabHeader let-tabs="tabsX">
<ul class="tab-panel-buttons" *ngIf="tabs">
<li
[ngClass]="{selected: tab.selected}"
(click)="selectTab(tab)"
*ngFor="let tab of tabs;">{{tab.title}}
</li>
</ul>
</ng-template> <ng-content
*ngTemplateOutlet="headerTemplate ? headerTemplate :defaultTabHeader; context: tabsContext"></ng-content>

Now we need to export the 'au-tab-panel' component's method to the custom template, to do that we can use template ref:

  <ng-template #headerButtons>
<button (click)="tabPanel.selectTab(loginTab)">Login</button>
<button (click)="tabPanel.selectTab(signUpTab)">Sign up</button>
</ng-template> <au-tab-panel #tabPanel [headerTemplate]="headerButtons"> <au-tab title="login" #loginTab>
<form>
<div class="form-field">
<label>Email:</label><input>
</div>
<div class="form-field">
<label>Password:</label><input>
</div>
</form>
</au-tab> <au-tab title="Sign up" #signUpTab>
<form>
<div class="form-field">
<label>Email:</label><input>
</div>
<div class="form-field">
<label>Password:</label><input>
</div>
<div class="form-field">
<label>Confirm Password:</label><input>
</div>
</form>
</au-tab>

[Angular] Change component default template (ng-content, ng-template, ngTemplateOutlet, TemplateRef)的更多相关文章

  1. [Angular] Test component template

    Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...

  2. [Angular 2] Share Template Content In Another Template With Content Projection <ng-content>

    Angular 1 provided a mechanism to place content from your template inside of another template called ...

  3. [Angular 2] Component relative paths

    Oingial aritial --> Link Take away: import { Component, OnInit } from '@angular/core'; @Component ...

  4. Change the default MySQL data directory with SELinux enabled

    转载:https://rmohan.com/?p=4605 Change the default MySQL data directory with SELinux enabled This is a ...

  5. angular 引入 component 报错

    每天抽出一些时间学习 Angular2 ,并准备把手头上的项目移植为 Angular2 , 不过今天又遇到了一些小问题. 准备写一个导航类适于管理后台常见的右边导航,如博客园的这种: ! 使用 g g ...

  6. How to change from default to alternative Python version on Debian Linux

    https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux You ...

  7. [vue-router] Failed to resolve async component default: Error: Loading chunk 0 failed.

    在整合laravel5.4 和vue2.1的时候遇到一个奇怪的问题 Uncaught SyntaxError: Unexpected token < Error: Loading chunk 0 ...

  8. Vue-cli3.x在开发环境中(router采用 history模式)出现Failed to resolve async component default: Error: Loading chunk {/d} failed.或者Uncaught SyntaxError: Unexpected token <错误

    使用Vue-cli3.x开发环境中(router采用 history模式)出现Failed to resolve async component default: Error: Loading chu ...

  9. MATLAB/SIMULINK生成代码错误之change the default character encoding setting

    SIMULINK点击生成C代码报错 错误提示: Error encountered while executing PostCodeGenCommand for model 'RTW_sc3': Cl ...

随机推荐

  1. CSS盒子模型图

    下面这张图,是W3C标准的CSS盒子模型: 由上图可以清楚的看出各个部分的CSS属性.

  2. oracle取随机结果测试

    http://www.2cto.com/database/201307/227524.html

  3. Trafodion:Transactional SQL on HBase

    Trafodion: Transactional SQL on HBase HBase上实时分布式事务处理 介绍 HBase的SQL能力一直不足.Phoenix缺乏Join能力,eBay提出的kyli ...

  4. JavaScript作用域闭包(你不知道的JavaScript)

    JavaScript闭包.是JS开发project师必须深入了解的知识. 3月份自己曾撰写博客<JavaScript闭包>.博客中仅仅是简单阐述了闭包的工作过程和列举了几个演示样例,并没有 ...

  5. 43.c++指针类型转换

    数据类型转换(static_cast) //数据类型转换 printf("%d\n", static_cast<int>(10.2)); 指针类型转换(reinterp ...

  6. BIND View 加速南北方网络互访

            BIND View 加速南北方网络互访          南北方网络互访的问题一直以来就是广大运维人员的心病,两大网络运营商之间的连接带宽比较有限,跟不上互联网业务发展的速度.如何才能 ...

  7. 桌面版chrome调试APP的webview的步骤:

    1. 在chrome地址栏输入:chrome://inspect/ 2.手机插入电脑USB口,打开开发者选项,OK,可以了. 友情链接:http://www.cnblogs.com/slmk/p/75 ...

  8. easyui树查找

    前端查询 /* 树查询*/ function searchMaterial(){ var parentNode=$('#selectMaterialTree').tree('getRoots'); / ...

  9. 配置spotlight连接linux服务器

    本文转自(https://blog.csdn.net/qq_31391261/article/details/79429098) 一.配置spotlight连接linux服务器 1.以管理员身份运行软 ...

  10. CISP/CISA 每日一题 15

    CISA 每日一题(答) 作业记帐: 监控和记录信息系统资源的使用,这些信息可被信息系统审计师用来执行: 1.将资源使用和相关用户挂钩以便实行计费: 2.通过改变系统软件的默认设置来最优化硬件性能 作 ...