表格行中的按钮Angular 5

时间:2018-07-06 14:13:21

标签: angularjs angular5

嗨,我对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字段中显示一个按钮来上传签名的文件。我怎样才能达到这个结果?我整个上午都在尝试...但是什么也没有。

1 个答案:

答案 0 :(得分:0)

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

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

类似的东西