user2843943 user2843943 - 13 days ago 6
TypeScript Question

can't use a variable as a parameter

I'm trying to insert the parameters in this url but I can't get it to work. here is my code:

filterFunction(newValue, parameter){
this.workorderservice.searchWorkorders(1, 20, {sort: {}, search: {predicateObject: {'workorder.location.street': newValue}}, pagination: {start: 0}})

.subscribe(data =>{ this.rows = data.json()
this.links = this.parselink.parse(data.headers.get('link'))
console.log(this.rows)
})

}


I try to replace 'workorder.location.street' with parameter

Answer

You cannot use a parameter name like that. Even though your question was a bit vague, I guess you should do this:

   filterFunction(newValue, parameter) {

     let predicateObject: any = {};
     predicateObject[parameter] = newValue;

     this.workorderservice.searchWorkorders(1, 20, {sort: {}, search: {predicateObject: predicateObject}, pagination: {start: 0}})

        .subscribe(data =>{ this.rows = data.json()
            this.links = this.parselink.parse(data.headers.get('link'))
            console.log(this.rows)
        })

    }
Comments