首页 > 解决方案 > 表格行中的按钮 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 中显示一个按钮来上传签名文件。我怎样才能达到这个结果?我整个早上都在尝试......但没有。

标签: angularjsangular5

解决方案


嗯,一旦您从服务中收到数据,该服务会调用您的后端来检索数据。您的组件应订阅该服务以接收组件中的数据。一旦它在您的组件中,您就可以在您的视图中以相同的属性使用它。

服务包括@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>

类似的东西


推荐阅读