1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import { OnInit , Input , Component , Optional , Inject } from '@angular/core' ;
15+ import { OnInit , Input , Component , Optional , Inject , OnChanges , SimpleChanges } from '@angular/core' ;
1616import { CoreLogger } from '@singletons/logger' ;
1717import { CoreDomUtils } from '@services/utils/dom' ;
1818import { CoreUtils } from '@services/utils/utils' ;
@@ -30,7 +30,7 @@ import { CorePromisedValue } from '@classes/promised-value';
3030@Component ( {
3131 template : '' ,
3232} )
33- export abstract class CoreBlockBaseComponent implements OnInit , ICoreBlockComponent , AsyncDirective {
33+ export abstract class CoreBlockBaseComponent implements OnInit , OnChanges , ICoreBlockComponent , AsyncDirective {
3434
3535 @Input ( ) title ! : string ; // The block title.
3636 @Input ( ) block ! : CoreCourseBlock ; // The block to render.
@@ -54,15 +54,31 @@ export abstract class CoreBlockBaseComponent implements OnInit, ICoreBlockCompon
5454 * @inheritdoc
5555 */
5656 async ngOnInit ( ) : Promise < void > {
57- if ( this . block . configs && this . block . configs . length > 0 ) {
58- this . block . configs . forEach ( ( config ) => {
59- config . value = CoreTextUtils . parseJSON ( config . value ) ;
60- } ) ;
57+ await this . loadContent ( ) ;
58+ }
6159
62- this . block . configsRecord = CoreUtils . arrayToObject ( this . block . configs , 'name' ) ;
60+ /**
61+ * @inheritdoc
62+ */
63+ ngOnChanges ( changes : SimpleChanges ) : void {
64+ if ( changes . block ) {
65+ this . parseConfigs ( ) ;
6366 }
67+ }
6468
65- await this . loadContent ( ) ;
69+ /**
70+ * Parse configs if needed.
71+ */
72+ protected parseConfigs ( ) : void {
73+ if ( ! this . block . configs ?. length || this . block . configsRecord ) {
74+ return ;
75+ }
76+
77+ this . block . configs . forEach ( ( config ) => {
78+ config . value = CoreTextUtils . parseJSON ( config . value ) ;
79+ } ) ;
80+
81+ this . block . configsRecord = CoreUtils . arrayToObject ( this . block . configs , 'name' ) ;
6682 }
6783
6884 /**
0 commit comments