angularjs - 表格行中的按钮 Angular 5
问题描述
嗨,我对 Angular 比较陌生,所以我需要了解一些编码概念。我有一个使用此代码从数据库模型输出字段数据的表:
{
label: 'Fattura XML',
width: 120,
maxWidth: 160,
minWidth: 120,
field: 'xml_flag',
class: 'text-right w_md',
sort: {
field: 'xml_flag',
},
},
{
label: 'Firmata',
width: 130,
maxWidth: 130,
minWidth: 130,
field: 'file_xml',
class: 'text-right w_md',
sort: {
field: 'file_xml',
},
},
字段的值输出正确,但现在我需要在 xml_flag 中显示一个按钮来下载文件,并在字段 file_xml 中显示一个按钮来上传签名文件。我怎样才能达到这个结果?我整个早上都在尝试......但没有。
解决方案
嗯,一旦您从服务中收到数据,该服务会调用您的后端来检索数据。您的组件应订阅该服务以接收组件中的数据。一旦它在您的组件中,您就可以在您的视图中以相同的属性使用它。
服务包括@Injectable()
getData(): {
return this.http.getSomeData();
}
零件:
Inject the service in the constructor, and have a function invoke the data retrieval
private storedValue;
getDataInComponent(){
this.service.getData().subscribe(value=>{
// value is your response if Success it will be value else error
// Once you have this data you can use it in your component
this.storedValue = value;
}, error =>{ // this is your error }
};
在您的模板中
<button class="storedValue.class">{{ storedValue.label}}</button>
类似的东西
推荐阅读
- python - 自变量在类中更改不返回
- kafka-consumer-api - @KafkaListener 处理 Spring Cloud 添加的标头
- snakemake - 单独总结snakemake步骤:Snakefile中的每个规则一个
- report - 控制源,寻找多个值
- apache - Tomcat LDAP 角色:未找到角色
- bash - 在 gawk 中计算文件中第一个单词的长度
- relational-database - 关系代数在同一个键中选择多个条件
- kubernetes - 如果我有一个公共负载均衡器,直接服务到服务通信如何实现负载均衡?
- c++ - 此类代码中 gcc 和 clang 之间的不同行为
- sql-server - 说明为什么我的 AND 子句在 SQL 中返回空字符串的原因