Angular 2 Musings

Keep it clean but fun.
Post Reply
KHill
Posts: 19
Joined: Fri Jun 03, 2016 1:02 am

Angular 2 Musings

Post by KHill »

At work, I've just started on a client's project, and we've opted to use Angular 2 (coupled with entity framework, and a bunch of other web-app agivens). I've never used it before (nor did I use Angular 1), but it's kind of fun to get into something that has little-no documentation because it really builds self-teaching skills. While it has a kind of steep learning curve, I'm starting to really enjoy it. Has anyone else worked with either version of Angular? And if so, I'm curious what your thoughts are on it, and more relevantly, how it could be applied to game development as essentially a substitute for something like PHP.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Angular 2 Musings

Post by Jackolantern »

I am working with Angular 1.4 on my current client project. An early release version of Angular 2 was available when we started but we quickly decided against using it because it was just too early. Now we are too far into development to change to Angular 2.

A lot of the problems we have come up against in Angular 1 have largely been passed over directly from Javascript. Namely, the lack of data schemas. Probably a lot like your project, we are targeting web services (Web API in .NET to be exact). We pass a lot of DTOs back and forth between the client and the web services. A lot of this data has similar objects in it that we keep seeing over and over again: credit cards, addresses, toll tags, etc. Take credit cards for example. We all pretty much know what that is going to include: credit card number, expiration date, card type, etc. There is some normalization of these field names due to the legacy web services that connect to the database that our web service layer connects to. But when it comes to sending DTOs from the client to the web services there is no normalization at all. So just for credit card number, you could have creditCardNumber, creditCardNbr, ccNumber, etc.

This didn't seem like such a large problem in the beginning. But now we have several things we want to implement where this is an issue. For example, I created a detailed logging system that stores representations of all of the data in memory on the client side to store into the logs so we can try to recreate client-side exceptions. The problem is that some fields need to be censored out of the logs, such as credit card numbers. Since credit card number could be stored under a number of different names and nothing is enforcing the naming conventions of it you would have to say what name you need censored out at each use, instead of being able to just list a number of fields to censor for the entire application. It makes the logging system very unsafe because it means that the dev could misspell the name or even forget at one use and suddenly we have user credit card numbers in the logs.

It was a controversial decision for the Angular team to push Typescript in Angular 2, but I think it was the right decision. We are now backtracking in our app and trying to add in Typescript to an existing application so we can have that type safety that would allow us to definitively refer to certain pieces of data.

I have not used Angular 2 enough to really comment much more on the topic than this. But I do envy Angular 2 projects that were setup with Typescript from day 1.

As for Angular replacing PHP or other server-side technologies, it won't actually replace them. It will vastly change how server-side codebases are created, making them much smaller. But they will still be needed for web services or websockets to actually send the data to the client. Since Angular is only client-side, you will still need the ability to send data back and forth and you also need a safe place for your logic. The client is wide-open to the user and can't be trusted, so for logging in, making payments, pulling up content, etc. you will still need a server-side technology. It will just be thinner than before.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Angular 2 Musings

Post by hallsofvallhalla »

So I built an entire project at work with Angular and at the end of it I was like wtf was this for... I do not see the use in angular. It is way too much work to do what I can do with Jquery or even raw js. Oh let me build this MVC structure to do 1 thing or I can just do this one thing.
Granted I have come to understand and sometimes love MVC but angular is one of those things I simply cannot understand how it saves anyone time or code. Maybe just me.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Angular 2 Musings

Post by Jackolantern »

To each their own I guess, because I love it now. There are definitely some parts that feel a little backwards or like they are wasting time, but the further I have gone I see their point. For example, in the beginning it was hard to understand why DOM manipulation had to be kept in directives, but then when we started writing unit tests it made sense (since DOM reliance makes unit tests very difficult).

But more than anything else, it has been great for organization. Keeping a strong separation between the HTML views and the app logic, as well as keeping separate pages/features in separate view/controller pairs has been very nice (although I admit that Angular puts more in the HTML than I was raised to accept lol). Plus, going on yourself and making everything in, say, jQuery means you are going to have to reinvent the wheel in a lot of cases. For example, routing and history. Most SPAs need a routing system so that users can type URLs into the address bar, bookmark pages, etc. And to keep this compatible with the SPA architecture, you will have to make that yourself. That is going to be a lot of work on a problem that has already been solved. There are of course things like Micro.js where you can pick out only the frameworky parts you need but there is something to say for knowing everything you are working with was built from the ground up to work with each other.
The indelible lord of tl;dr
KHill
Posts: 19
Joined: Fri Jun 03, 2016 1:02 am

Re: Angular 2 Musings

Post by KHill »

But more than anything else, it has been great for organization.
This 100%. While I can totally see the layers of MVC being over-complicated at times, I will never say that I don't know exactly what each portion of it does based on how organized it is.

I think one of the best uses in my project has been the ability to take Typescript files as components and be able to reuse them in parent classes simply by calling in those components. Angular's routing makes this very easy (once you get the hang of it), and massively cuts down on reused code.

That being said, you have a very valid point Halls, Angular doesn't really do anything that JQuery can't, I suppose it probably comes down to preference (and trust me, there's been times during this development cycle that I wish I could just slip in a line of JQuery to make it all better haha)
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Angular 2 Musings

Post by Jackolantern »

One thing that has been a pain is how other libraries and components really have to be made for Angular to work well with Angular (at least 1.x). For example, our project has heavily used Kendo UI for smart grids, date pickers and other UI components. Even though Kendo UI provides ng directives, the data binding just doesn't work right. It is only one-time binding and as best as I can tell it is because at its core, Kendo simply uses another architecture-style than angular and angular hates that.
The indelible lord of tl;dr
KHill
Posts: 19
Joined: Fri Jun 03, 2016 1:02 am

Re: Angular 2 Musings

Post by KHill »

Ah, most of our UI has been handled by bootstrap, we've generated our own theme for the site and it's worked surprisingly well. Binding works nicely, the only issue I was having was today when I was trying to use a modal to display a loading icon, but decided that I probably shouldn't be using a modal for that anyways :P
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Angular 2 Musings

Post by Jackolantern »

We use Bootstrap, too. I like it but I do kind of think the Bootstrap look is getting a little played out. It has just become so popular that it is almost starting to feel like the default style of the web which is not really a good thing.

As a side note, I tried out the Google Bootstrap-alternative, Material Design Lite (MDL) for a Hackathon my company did a couple of months back. And I have to say...it is really not a good choice unless you are making a by-the-numbers Google-style website. It has some decent components but they are not flexible. We had a ton of problems with it. Of course we only had one week so maybe it was just some nuance that I didn't have the time to understand, but at least out-of-the-box it was considerably more difficult to work with than Bootstrap.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Angular 2 Musings

Post by hallsofvallhalla »

I ran into the same thing with MDL and this is coming from a fanboi of google stuff. It just didn't feel as fluid to me.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Angular 2 Musings

Post by Jackolantern »

I am glad it is not just me. I was also surprised how poorly the responsiveness was for it out of the box.
The indelible lord of tl;dr
Post Reply

Return to “Off-Topic”