Asking your advise about dynamic/static loading components/pages/html

I went through this with Markdown, tried a bunch of things, and here’s what I eventually settled on:

  • Store your objects however is convenient for you. In my case, that’s markdown source.
  • Define two components; we’ll call them skeleton and bone for now.
  • skeleton has an input property giving it the source. In ngOnChanges, you need to parse that source into an array of elements, each corresponding to a different type of bone.
  • skeleton’s template looks something like this:
<template ngFor let-bone [ngForOf]="bones">
  <app-bone [bone]="bone"></app-bone>
</template>
  • Make sure each bone has a discriminator indicating its type, and then the BoneComponent template is a big giant switch:
<blockquote *ngIf="bone.tag === 'blockquote'">
  <app-bone *ngFor="let child of bone.children" [bone]="child"></app-bone>
</blockquote>

<br *ngIf="bone.tag === 'br'">

... every other block-level element we support...

Note that this can work recursively if you need it to, in that the inside of the blockquote case is effectively another skeleton. I’m using HTML elements here, but the general technique works equally well for other user-defined components (as types of bones).

4 Likes
Generate html components dynamically
Loading custom HTML from a file?
How to create dynamic posts (news feed)
Ionic code inside the HTML page
Render HTML tags in template
trustASHTML equivalent in Ionic2
Passing child component initialization data back to Parent
Is there a way to add (click) programatically?
Display html element from JSON object on ionic App
Html in my text fields
innerHTML content
[SOLVED] Page opened with navcontroller push is duplicating itself
How to render dynamic html
Ionic dynamic templates with aot
List of mixed type elements (different component in one collection)
(click) handler on dynamic text
How to, using a JSON file, pass a link to another ionic page (view)?
How do I dynamically add html to template from a class variable
Ng-model with objects
Once rendered the click function is not available
Create dynamic Ion-Grid using ViewContainerRef.createComponent()
Dynamically adding html/JS
Why rest api html data click attribute not working in angular 2 ? is there any way to do like angular 1?
Button and href tag
How to force template strings interpolation for text?
HTML displaying from MySQL
Ion-toggle (ionChange) triggered
Creating multiple pages with similar functionality
Trying to make a dinamic form
Using custom components inside ion-contnent
[Ionic 5 - Angular] Recommended way to add dynamic elements to the DOM
Having tough time with the Observer pattern
[SOLVED ]Ionic 2 ng-include alternate
How to add event to some asynchronous content after loaded
How do you inject dynamically constructed HTML that requires events to be subscribed to?
Create dynamic custom components and add it to an array
How to delete a single quote from string
Load remote page into ionic controller
Ionic v3 bind ionic page from ts file