We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<ng-container> 是一个不会干扰样式或布局的分组元素,Angular 不会将其放入DOM中。
<ng-container>
如ngFor
ngFor
<ng-container *ngFor="let book of books> <div> {{ book }} </div> </ng-container>
ngTemplateOutlet是可以把用ng-template包裹的dom元素引入进来,并且可以传递参数过去。
ng-template
<ng-template #cat > <div>一直狸花猫</div> </ng-template> <ng-container *ngTemplateOutlet="cat"> </ng-container>
那么如何传递参数呢? 使用context~
context
ts定义参数变量
age = '2岁了'; height: "10cm";
html传递参数
<ng-container *ngTemplateOutlet="cat; context: { $implicit: age, height: height }"> </ng-container> <ng-template #cat let-data let-height='height'> <div>一直狸花猫</div> {{ data }} {{ height }} </ng-template>
context接收一个对象,如context: { $implicit: age}, $implicit传递的是默认值,在ng-template中使用let-data接收,变量data就是传递过来的值,这是一个固定写法。
context: { $implicit: age}
$implicit
let-data
还可以传递更多的参数,形如context: { height: height},它其实是这种形式{ key: 参数}, ng-template中取值形式为let-变量=context定义的key,这个变量即为传递过来的参数。
context: { height: height}
{ key: 参数}
let-变量=context定义的key
The text was updated successfully, but these errors were encountered:
No branches or pull requests
ng-container vs ngTemplateOutlet
<ng-container>
是一个不会干扰样式或布局的分组元素,Angular 不会将其放入DOM中。结合结构性指令使用
如
ngFor
结合ngTemplateOutlet
ngTemplateOutlet是可以把用
ng-template
包裹的dom元素引入进来,并且可以传递参数过去。那么如何传递参数呢? 使用
context
~ts定义参数变量
html传递参数
context
接收一个对象,如context: { $implicit: age}
,$implicit
传递的是默认值,在ng-template
中使用let-data
接收,变量data就是传递过来的值,这是一个固定写法。还可以传递更多的参数,形如
context: { height: height}
,它其实是这种形式{ key: 参数}
,ng-template
中取值形式为let-变量=context定义的key
,这个变量即为传递过来的参数。The text was updated successfully, but these errors were encountered: