[Angular] Learn How To Use ng-template Inputs
2017-07-02 20:14
519 查看
For example, we have a modal component, it can config that using ng-template as a configurable template.
Now what we want to do is to pass in inputs to ng-templates so that template can change dynamiclly according to the inputs.
For example:
To do that, we need to add an @Input to au-modal component:
See the commit: Github
<ng-template #auModalBody></ng-template> <au-modal [body]="auModalBody" ></au-modal>
Now what we want to do is to pass in inputs to ng-templates so that template can change dynamiclly according to the inputs.
For example:
<ng-template #auModalBody let-title="title" <!-- define a title prop --> let-tabActivated=loginTabActivated <!-- define a tabActivated prop --> > <!-- we can use 'title' & 'tabActivated' props here --> <h2>{{title}}</h2> <tab [selected]="tabActivated" #login /> <tab [selected]="!tabActivated" #signUp /> </ng-template> <au-modal [body]="auModalBody" [context]="{ title: 'Login or Sign up', tabActivated: loginTabActivated <!-- based on those variables we passed in--> }"></au-modal>
To do that, we need to add an @Input to au-modal component:
@Input() context: any; <ng-container *ngIf="body; else projectionBody"> <ng-container *ngTemplateOutlet="body; context:context" ></ng-container> </ng-container>
See the commit: Github
相关文章推荐
- Follow me to learn how to use mvc template
- How to use ngMessages in AngularJS
- Learn how to Use UIPageViewController in iOS
- How to use the Springer LNCS LaTeX template
- Learn How to Use Neo4J with Node.js
- Just learn how to use the JNI
- WPF Tutorial - How To Use A DataTemplateSelector
- Angular JS: How/when to use ng-click to call a route?
- learn PCL 02 How to use pcl in your own project.
- [Angular] Use :host-context and the ::ng-deep selector to apply context-based styling
- How to use the CONVERSION_EXIT_PARVW_INPUT and CONVERSION_EXIT_PARVW_OUTPUT
- How to call a service function in AngularJS ng-click
- 一个NHibernate应用的实际例子(A good open source project to learn how to use NHibernate)
- [Angular] Using ngTemplateOutlet to create dynamic template
- Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?
- [RxJS] Learn How To Use RxJS 5.5 Beta 2
- How to use $http and $resource in Angular JS
- Learn How To Use Oracle Audit
- Learn How TO Use SSH To Get Through the GFW
- [Angular 2] Passing Template Input Values to Reducers