Angular-gridster2: Saving grid state on itemChange can access only static functions, services

Created on 26 May 2018  路  2Comments  路  Source: tiberiuzuld/angular-gridster2

itemChange callback function cannot access local class variables, function or injected services. It can only access static methods and variables. I am injecting a service in my class which has a post api call to save grid state to database. I cannot call an instance of this service ex this.mydbservice inside the itemChange callback function. Is there a non static way to save the state of grid on every item change

some relevant code below....

constructor(private userService: UserService, private router: Router, private route: ActivatedRoute)
{
}
itemChange(item: GridsterItem, itemComponent: GridsterItemComponentInterface) {
console.info('itemChanged', item, itemComponent);
savetoDb(item,itemComponent) //cannot call this function here
}

savetoDb(item,itemComponent )
{
call injected service savetoDb function here
this.userService.saveTodb...............
}

Most helpful comment

thanks that worked. closing this

All 2 comments

try using this:

 this.options = {
         itemChangeCallback: this.itemChange.bind(this)
 }

thanks that worked. closing this

Was this page helpful?
0 / 5 - 0 ratings