首页 > 解决方案 > 如何在打字稿中动态设置对象元素

问题描述

filterForElement: string       
constructor(
        private api: someApiService) { }    
        someInitFunction(params:any) {
            this.filterForElement = params.filterForElement // Value is available onece component is initialize.
          }
        onChangeDrop() {
        this.api.setFilterModel({'state': {filterType: "text", type: "equals", filter: valueToUse}})
        }

这里不是我想用值替换的状态filterForElement

标签: javascriptangulartypescript

解决方案


试试这样:

this.api.setFilterModel({this.filterForElement: {filterType: "text", type: "equals", filter: valueToUse}})

推荐阅读