Build dynamically page


#1

Hello everyone!

I’m enjoying the Ionic2 and is wonderful.
I need to build a page with the components dynamically.
Example:
getting the json will add components such as ion-label, ion-button, ion-checkbox, etc.
So ride the component tree with events depending on the business logic.

What better way to do this?

This link is broken:
https://angular.io/docs/ts/latest/api/core/DynamicComponentLoader-class.html
in this page


#2

Especially with ahead-of-time template compilation right around the corner, I would suggest rethinking your design so that you don’t need to be doing this at all.


#3

I understand,
but my project has dynamic formularies,
that users do create in the system.
I read from json/xml for to create formulary.


#4

may be Dynamic forms will help you

basically you need to create a template for each control and inject it in a general way


#5

a lot of fun this… thanks, is working!

Now I am trying to make include code from string:
Ex:

@Compone
export class MyPage {
engine: Engine;

constructor(...){
    this.engine = new Engine();

    testClick(){
            var code = "(function (){ return engine.testRule() )}())";
            var result = eval.call(null, code);
            console.log(result);
    }

}

class Engine {
testRule(){
return “asdasd”;
}
}

give a error: “engine not defined”.
Any suggestion?


#6

May i know why you want this kind of workout?
probably, you can use an interface for this type of workout,

please elaborate your need, i will try my best


#7

ok… thank you! great!
working!


#8

Any security consideration gone through your mind using eval?


#9

I used Function instead eval.
let func:Function = new Function(‘engine’, ’ your code here ');
let engine = new Engine();
let exec = func(engine)();