diff --git a/public/app/plugins/datasource/mysql/query_ctrl.ts b/public/app/plugins/datasource/mysql/query_ctrl.ts index c33f709d076..67ca7b6d694 100644 --- a/public/app/plugins/datasource/mysql/query_ctrl.ts +++ b/public/app/plugins/datasource/mysql/query_ctrl.ts @@ -164,12 +164,20 @@ export class MysqlQueryCtrl extends QueryCtrl { icon: 'exclamation-triangle', yesText: 'Switch', onConfirm: () => { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); }, }) ); } else { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); } } diff --git a/public/app/plugins/datasource/postgres/query_ctrl.ts b/public/app/plugins/datasource/postgres/query_ctrl.ts index 39743775032..4327b3ae8db 100644 --- a/public/app/plugins/datasource/postgres/query_ctrl.ts +++ b/public/app/plugins/datasource/postgres/query_ctrl.ts @@ -196,12 +196,20 @@ export class PostgresQueryCtrl extends QueryCtrl { icon: 'exclamation-triangle', yesText: 'Switch', onConfirm: () => { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); }, }) ); } else { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); } }