Reputation: 1729
Back when Angular was the thing, we used it to build an application for a client. To simplify it to the core, it's basically a dynamic system that allows an easy way to create questions and answers (even very complex ones), with display and valid conditions. Once no more questions are available, the system generates different offers that match the answers.
What allows it to be so dynamic is that we rely on $scope.$eval(). It made what was an ultracomplex application with new bugs when a new question was added a simple application that has been reliable for 3 years, with lots of upgrades and evolutions.
Now, I'm looking into Angular 4 to determine if there is an upgrade path that exists.
So if we have a questions that looks like this :
{
"id": "the_question",
"answers: [{
"text": "yes",
"value": true
},{
"text": "no",
"value": false
}]
}
and offers like this :
[{
"id": "offer1",
"condition": "session.answers.the_question == true"
},{
"id": "offer2",
"condition": "session.answers.the_question == false"
}]
The system will tell us that offer1 is the proper one if user choosed "yes", or even propose multiple offers, and so on.
Thing is, in angular 4, $scope is dead, and $eval is gone with it.
So, is there anything in Angular 4 that would allow us the evaluate angular expressions at runtime against a specific object (I would even take experimental classes that might evolve in the future) ?
I had been looking into the Compiler class, but it seems to focus more on Component that more simple things.
Upvotes: 2
Views: 1013
Reputation: 1729
Got it to work by extracting the appropriate code from angularjs unminified source file and keeping its structure. I used tslint to make sure every function required was present. That represented less than 50 function to copy/paste.
I had to rewrite the way the providers where used and used a light version of the original Scope class to get rid of what was not needed.
Upvotes: 1