当前位置:网站首页>Parsing ng template with let total in NZ Pagination
Parsing ng template with let total in NZ Pagination
2022-06-28 06:03:00 【Firefly Tali】
introduction
In the use of Ant design In the process , Discover paging components nz-pagination By setting nzShowTotal To show how much data there is in total let-total This way of writing , What's strange about me is that let-total An object that is not assigned a value , Where does its value come from ?
<nz-pagination [nzPageIndex]="1" [nzTotal]="85" [nzPageSize]="20" [nzShowTotal]="totalTemplate"></nz-pagination>
<ng-template #totalTemplate let-total> common {
{ total }} Data </ng-template>
analysis
ng-template It belongs to the more advanced angular usage , It defines a template that does not render by default , It means that if we only define and do not use , Then it will not be displayed on the page like other elements , such as :
<!-- The page will only show hello instead of hello world -->
<p>hello</p>
<ng-template>
<p>world</p>
</ng-template>
that ng-template When will it be used ,
- As TemplateRef Class to use
For details, see ant design Created by service in Modal or drawer in use template Example , There is no talk here .
ant design modal Example - Use as a template variable
The question we raised at the beginning belongs to this kind of , Usually just contact ng-template when , The most used arengIf elseIn the structural directive , This is easier to understand , What's the problem at the beginning ?
<p *ngIf="isTrue else falseTpl">
Really?
</p>
<ng-template #falseTpl>
<p> fake </p>
</ng-template>
That's actually using ngTemplateOutlet and ngTemplateOutletContext Dynamic templates for implementation . Explain the first question , Simply speaking , Namely nz-pagination In component , There is a similar line of code
<!-- nz-pagination -->
<ng-container [ngTemplateOutlet]="totalTpl" [ngTemplateOutletContext]="{$implicit: pageInfo.total}"></ng-container>
among totalTpl adopt Input Variables are passed in , Like this
/** nz-pagination **/
@Input() nzShowTotal: TemplateRef<{
$implicit: number;}>;
pageInfo = {
total: 100}
[ngTemplateOutletContext] Represents the context of the template , It's an object , The key of the object will be available for the local template let Declared binding , It uses $implicit Set the key value in the context object to the default value , That is to say, it corresponds to the question at the beginning let-total.
summary
There are some doubts about this ant design The document does not clearly explain the reason , After all, I don't know what the default value of its dynamic template is without looking at the source code . The main reason is that I am not familiar with the use of dynamic templates .
Reference material :
边栏推荐
- Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
- Yygh-7-user management
- Lenovo hybrid cloud Lenovo xcloud, new enterprise IT service portal
- Maskrcnn,fast rcnn, faster rcnn优秀视频
- 基于Kotlin+JetPack实现的MVVM框架的示例
- API learning of OpenGL (2007) gltexcoordpointer
- No one can only use foreach to traverse arrays, right?
- AutoCAD C# 多段線小銳角檢測
- MySQL common functions
- The length of pytorch dataloader the difference between epoch and iteration
猜你喜欢

Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes

Capacity scheduling absolute value configuration queue usage and pit avoidance

YYGH-BUG-03

Oracle fundamentals summary

death_satan/hyperf-validate

Development trend of mobile advertising: Leveraging stock and fine marketing

socke.io长连接实现推送、版本控制、实时活跃用户量统计

Valueerror: iterative over raw text documents expected, string object received

Difficulty calculation of Ethereum classic

High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
随机推荐
重载,重写的区别,抽象类,接口的区别
Official answers to the "network security" competition questions of the 2022 national vocational college skills competition
Mosaic data enhanced mosaic
Apple MDM Bypass 免越狱绕过MDM配置锁 免费
Introduction to uicollectionviewdiffabledatasource and nsdiffabledatasourcesnapshot
Example of MVVM framework based on kotlin+jetpack
Yygh-7-user management
MR-WordCount
PKG package node project (express)
高质量国产立体声编解码器CJC8988,Pin to Pin替代WM8988
Differences between basic types and packaging classes
YYGH-8-预约挂号
Differences between overloads, rewrites, abstract classes and interfaces
Valueerror: iterative over raw text documents expected, string object received
Maskrcnn, fast RCNN, fast RCNN excellent video
YYGH-BUG-03
[MySQL] all query tables contain 20million data -- how to optimize SQL
CSI以及本地盘的相关实现记录
使用pytorch和tensorflow计算分类模型的混淆矩阵
19 fonctions de perte d'apprentissage profond