[英]Using this in Angular template with reference
In ourcomponent HTML we have a modal with a reference name. 在我们的组件HTML中,我们有一个带有参考名称的模式。 Inside this modal we have buttons to close the modal.
在此模式内部,我们有一些按钮可以关闭模式。
Here is the code: 这是代码:
<div bsModal #confirmModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirm modal" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title pull-left">Confirm</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="confirmModal.hide()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<span>Are you sure ?</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" (click)="confirmModal.hide()">Cancel</button>
<button type="button" class="btn btn-danger" (click)="confirmModal.hide()">Refresh Data</button>
</div>
</div>
</div>
</div>
To close it, we currently call for example (click)="confirmModal.hide()"
. 要关闭它,我们当前调用例如
(click)="confirmModal.hide()"
。 Using the reference name. 使用参考名称。
Since we are inside the div with reference #confirmModal
, is it possible to maybe have a way to call the hide function using (click)="this.hide()"
由于我们在引用
#confirmModal
的div 内部 , 是否有可能使用(click)="this.hide()"
来调用hide函数的方法
Of course I tried this syntax and it doesn't work as expected as this
refers to component as I understand. 当然,我尝试了这种语法,但按我的理解,
this
指的是组件,因此无法正常工作。
As a bonus: do you have any idea where I can find information on Angular doc about this reference syntax #reference
to name a part of my html? 另外一个好处是:您是否知道我可以在Angular doc上找到有关此参考语法
#reference
以命名html的一部分? I use it without exactly knowing all its possibilities. 我在不完全了解其所有可能性的情况下使用它。
The #abc is called a template reference variable
. #abc称为
template reference variable
。 You can find out more about it here: https://angular.io/guide/template-syntax#ref-vars 您可以在这里找到有关它的更多信息: https : //angular.io/guide/template-syntax#ref-vars
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.