[SalesForce] AngularJS 4 on Visualforce Pages (or in Lightning Components)

Some time ago we used Angular 1.x on Visualforce pages for several apps. Now some of these Apps are aged and more or less in need of redesign. This redesign is not because of any actual shortcomings of Angular 1.x, but for other internal reasons and requirement changes.

This made me look closer on the current versions of Angular. Now there is Angular 4.x and the old version 1.x seems to be totally outdated…

They skipped Angular 3 and starting with Angular 2.x very fundamental design changes are introduced by the Angular developers, which makes it harder to use Angular by a simple <script> inclusion of one or many static resources like it was possible with Angular 1.x

Also the usage of TypeScript might be more difficult on Visualforce.

Searching the web, I came up with these links addressing Angular 2 – but this might still be valid and true even for Angular 4.x:

The concept in Chris W's answer here Feasability of Angular2 in Salesforce (through VF page) seems not very easy, since I would not like to develop locally and use REST and SOAP. Instead, I'm looking for a way to include some js-files (as done in good old Angular 1.x days) in a VF-page an write some pure JS for my app (not TS, no TypeScript). I did not dive into Angular 4.x deeply enough to see all implications and concepts yet. So this approach might be totally stupid – but I'd like to ask here before spending a long time research on Angular 4 concepts just to find out Visualforce and Angular 4 simply do not match at all…

Is there in the meantime any meaningful approach to use Angular 4 on Visualforce?

Has anyone found an meaningful usage of Angular 4 in Lightning Components? My assumption is, that it's not meaningful at all to combine Lightning Components with Angular 4 because the concepts do not match.

Best Answer

On using Angular within Lightning Components, the real gotcha is mentioned at the end of Christophe Coenraets's blog post Creating Lightning Components with React and taken from the security Requirements Checklist):

Any Lightning package that uses Angular or React or other third party DOM-based templating frameworks will automatically fail the security review until such time as we provide custom lightning components to properly encapsulate these frameworks. This is to avoid template injection attacks resulting from double interpolation. In order to use another framework as part of a package that uses Lightning, please use an iframe or Visualforce container until approved Lightning containers are published.

On the feasibility, mixing a framework that manipulates the DOM (Angular) with a framework that injects a virtual DOM layer (Locker Service) to enforce security policy is not likely to end well (until Salesforce have the time/inclination to make them work together). As TypeScript is translated to JavaScript to run, I assume that language problem could be overcome by tweaking the tooling (or maybe existing tooling is already suitable).

With Angular 1 and Angular 2 being significantly different, going from Angular 1 to native Lightning Components instead might make sense.

Related Topic