diff --git a/src/addons/block/myoverview/components/myoverview/myoverview.ts b/src/addons/block/myoverview/components/myoverview/myoverview.ts index e31ff0d1d..bbf812037 100644 --- a/src/addons/block/myoverview/components/myoverview/myoverview.ts +++ b/src/addons/block/myoverview/components/myoverview/myoverview.ts @@ -176,6 +176,8 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem * @inheritdoc */ ngOnChanges(changes: SimpleChanges): void { + super.ngOnChanges(changes); + if (this.loaded && changes.block) { // Block was re-fetched, load content. this.reloadContent(); diff --git a/src/core/features/block/classes/base-block-component.ts b/src/core/features/block/classes/base-block-component.ts index c6073cac6..05bec595c 100644 --- a/src/core/features/block/classes/base-block-component.ts +++ b/src/core/features/block/classes/base-block-component.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { OnInit, Input, Component, Optional, Inject } from '@angular/core'; +import { OnInit, Input, Component, Optional, Inject, OnChanges, SimpleChanges } from '@angular/core'; import { CoreLogger } from '@singletons/logger'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; @@ -30,7 +30,7 @@ import { CorePromisedValue } from '@classes/promised-value'; @Component({ template: '', }) -export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockComponent, AsyncDirective { +export abstract class CoreBlockBaseComponent implements OnInit, OnChanges, ICoreBlockComponent, AsyncDirective { @Input() title!: string; // The block title. @Input() block!: CoreCourseBlock; // The block to render. @@ -54,15 +54,31 @@ export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockCompon * @inheritdoc */ async ngOnInit(): Promise { - if (this.block.configs && this.block.configs.length > 0) { - this.block.configs.forEach((config) => { - config.value = CoreTextUtils.parseJSON(config.value); - }); + await this.loadContent(); + } - this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name'); + /** + * @inheritdoc + */ + ngOnChanges(changes: SimpleChanges): void { + if (changes.block) { + this.parseConfigs(); + } + } + + /** + * Parse configs if needed. + */ + protected parseConfigs(): void { + if (!this.block.configs?.length || this.block.configsRecord) { + return; } - await this.loadContent(); + this.block.configs.forEach((config) => { + config.value = CoreTextUtils.parseJSON(config.value); + }); + + this.block.configsRecord = CoreUtils.arrayToObject(this.block.configs, 'name'); } /**