5 ms·
I'm coming at this from the perspective of someone who has never used Angular 1.x or 2.x. I guess the first thing on my mind is: can I make Angular 2 work just
by maxharris 10y ago
I'm coming at this from the perspective of someone who has never used Angular 1.x or 2.x.
I guess the first thing on my mind is: can I make Angular 2 work just like React does? Is there any way to use it without making/(being allowed to make) separate HTML templates and CSS files? If not, this is a serious disadvantage. Having the view layer scattered across 3X the files (vs React) would make it very hard to follow the code in a large project.
Also, are there any real advantages over React that would be big enough for someone to consider pushing for a switch? If so, what are they?
- bdcravens 10y agoYou don't have to make separate files. You can inline the template in a component
- Bahamut 10y agoOne can use the @Component decorator with the template & style options - currently it seems to be the norm to do so, at least until the template compiler is understood more widely (it is pretty fresh), although long term having the template and styles in the same file probably will not be sustainable for more complex components. Angular 2 has some serious perf advantages over anything else out there, reportedly up to 2x React in some scenarios (i.e. repaint perf). It also is set up for incremental rendering, as opposed to React's blocking rendering loop, which can allow for more flexible UX. With the new bundling system for Angular 2, I believe it is currently a fraction of the size of React (I think the Angular team achieved < 10 KB app framework size, although I haven't checked out the new npm packages to be sure). React wins out on simplicity though, including how simple it is to communicate between components. React is also currently a lot more mature, with a much more mature third party ecosystem. Edit: I stand corrected on the size, but the 10 KB minified & gzipped is the Angular team's goal I remember reading.
- keithnz 10y agoI read something a while ago that I think really sums the key difference, is that angular and other frameworks inject javascript into html and its awkward. React injects HTML into javascript, and it seems, that way around is a lot more powerful as you have all of javascript to manipulate html rather than having HTML/Templating/Extensions to manipulate Javascript. The two advantages are speed (it's supposed to be faster) and its closer to the web component standard than react, so if/when web components become mainstream it could be a lot easier migrating from angular2. However, both of those wouldn't be my prime reasons for choosing a framework though.
- exclusiv 10y agoI think a lot is preference. I think HTML in JS is dirty just like HTML in server side strings. Other people feel the opposite, that putting new tags which are similar to inline onclicks and other events that we moved away from w jQuery is dirty. There is truth to both. Angular gives a lot of flexibility in code style and structure. You can componetize everything and have all your component files in one folder. You can inline it. Or you can go more MVC style folder structure like I do. I personally like my html being approachable to junior devs and not being so chopped up and abstracted away from static HTML markup like it might be with React. Not sold on the new tag styles of A2 but I suppose it will just take some adjustment.
- jhall1468 10y ago> Other people feel the opposite, that putting new tags which are similar to inline onclicks and other events that we moved away from w jQuery is dirty. Not even remotely the same thing. HTML has a hierarchical structure which isn't a particularly good structure for a web application. Javascript syntax allows far more control over the hierarchy. Your example is akin to saying putting a tank in an airplane is the same thing as putting an airplane in a tank. > You can inline it. Pretty thin separation between inline templates and JSX. But then, I've never understood why people think putting their template in a different file is somehow separation of concerns. > I personally like my html being approachable to junior devs and not being so chopped up and abstracted away from static HTML markup like it might be with React. Oh it's abstracted, with completely invalid HTML syntax and template variables. That's not to say that it's bad, I quite like the simplicity of the event/binding syntax of Angular 2. But JSX and Angular Templates are just two sides of the same coin.
- slmyers 10y ago> Not even remotely the same thing. HTML has a hierarchical structure which isn't a particularly good structure for a web application. Is there a "good" structure for a web application that jumps to your mind?
- balamaci 10y ago"Is there any way to use it without making/(being allowed to make) separate HTML templates and CSS files? If not, this is a serious disadvantage" Translation: "Can I sh*t where I eat? If not, this is a serious disadvantage"
- iSnow 10y agoIf you want React, just use React.