1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import { Component , Input , ViewChild , OnDestroy , Type , OnChanges , SimpleChanges } from '@angular/core' ;
15+ import { Component , Input , OnDestroy , Type , OnChanges , SimpleChanges , viewChild } from '@angular/core' ;
1616import { CoreBlockDelegate } from '../../services/block-delegate' ;
1717import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component' ;
1818import { Subscription } from 'rxjs' ;
@@ -34,7 +34,7 @@ import { CoreSharedModule } from '@/core/shared.module';
3434} )
3535export class CoreBlockComponent implements OnChanges , OnDestroy {
3636
37- @ ViewChild ( CoreDynamicComponent ) dynamicComponent ?: CoreDynamicComponent < ICoreBlockComponent > ;
37+ readonly dynamicComponent = viewChild < CoreDynamicComponent < ICoreBlockComponent > > ( CoreDynamicComponent ) ;
3838
3939 @Input ( { required : true } ) block ! : CoreCourseBlock ; // The block to render.
4040 @Input ( { required : true } ) contextLevel ! : ContextLevel ; // The context where the block will be used.
@@ -118,9 +118,7 @@ export class CoreBlockComponent implements OnChanges, OnDestroy {
118118 * @returns Promise resolved when done.
119119 */
120120 async invalidate ( ) : Promise < void > {
121- if ( this . dynamicComponent ) {
122- await this . dynamicComponent . callComponentMethod ( 'invalidateContent' ) ;
123- }
121+ await this . dynamicComponent ( ) ?. callComponentMethod ( 'invalidateContent' ) ;
124122 }
125123
126124}
0 commit comments