[英]Angular Pass Interpolated Data within an *ngFor back to component
I am currently iterating over collection of Documents that belong to a parent (Policy).我目前正在迭代属于父级(策略)的文档集合。 I need to get a specific property from the element to send to my back end for processing.我需要从元素中获取特定属性以发送到我的后端进行处理。
When I use the bound data in my HTML elements things work fine:当我在 HTML 元素中使用绑定数据时,一切正常:
<tbody>
<tr *ngFor="let el of policy.documents">
<td>{{el.year}}</td>
<td>
<a href="{{ el.url }}" target="_blank">{{ el.docType }}</a>
</td>
</tr>
</tbody>
However when I try to pass one of the bound elements to a function (via button click) the data does not make it to my component.ts.但是,当我尝试将其中一个绑定元素传递给 function(通过按钮单击)时,数据不会进入我的 component.ts。
<tbody>
<tr *ngFor="let el of policy.documents">
<td>{{el.year}}</td>
<td>
<a href="{{ el.url }}" target="_blank">{{ el.docType }}</a>
</td>
<td>
<button class="button btn btn-sm btn-primary" style="min-width: 150px;"
(click)="getDocuments(el.url)">View Document</button>
</td>
</tr>
</tbody>
component.ts组件.ts
getDocuments(url){
this.policyService.getAuthorizedHeader(url).subscribe((res) => {
this.authHeader = res.toString();
window.open(this.authUrl, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes')
}, error => {
this.alertify.error("Problem with your search: " + error.errors);
});;
}
Any Ideas?有任何想法吗?
In this case I found the the upstream provider changed the name of the property my model was storing (url to refUrl).在这种情况下,我发现上游提供商更改了我的 model 正在存储的属性的名称(url 到 refUrl)。 Once i updated my models to capture the re-named property it worked as expected.一旦我更新了我的模型以捕获重命名的属性,它就会按预期工作。
Lesson: Check the source of your data if things look right.教训:如果事情看起来正确,请检查您的数据来源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.