Angular 2.0
blog.angularjs.org
blog.angularjs.org
Here is an example from the site:
<div>
Length (float):
<input type="text" ng-model="length" name="length" smart-float />
{{length}}<br />
<span ng-show="form.length.$error.float">
This is not a valid float number!</span>
</div>
How semantic is ng-show="form.length.$error.float? smart-float sounds like C++. If programming languages worked like this, we wouldn't have built many apps. The problem is that some frameworks assume that everything should be done with using configuration. What ends up happening is that the configuration (and conventions) becomes its own language. This is a waste of time in the long term; library conventions are not a portable skill set.Some things are just better off with plain JS and simple HTML. FB/Instagram's React is a much better approach to building HTML UIs; you get readable JS and HTML instead of configuration mess.
As for the "form.length.$error.float", it probably could be a bit more concise, but is it really that bad? What would be a "more semantic" way?
The main strength of angular, is that you are able to point your DOM elements to environment variables in your JavaScript code -- eliminating the need for traversing the DOM to find a mount node. If you are opposed to this functionality and insisting on traversing the DOM from the JS side, I'd love to hear why.
You can find small things you dislike in any framework, but rarely are they valid criticisms of the general concept. Often, these details are there for a reason, and just as often, they are flaws waiting to be fixed by an open source developer.
Angular wants you to learn its vocabulary, and encourages users to expand it further. Like you point out, smart-float is a directive specific to the example. To me, it is a foreign object I don't recognize in html. In fact, directives, scopes?
The big one. Dependency Injection, factories, modules. In JS, this is a solution looking for a problem. There are simpler alternatives to DI. They have issues, but only in theory.
Clarity matters a lot. ng-show="form.length.$error.float". Is there a more simpler way of doing it? There should be; I can't even tell what that means.
I think there are distinctly two camps. I'm in the one which wants frameworks to make me productive with the languages, specs and standards I already know. React (+ router) does this. Backbone does this too, depending on what you're building.
(Edit: replaced semantic with clarity)
Have you taken the time to play around with angular before airing your grievances? My hunch is yes and that you may just be simplifying things for others who haven't used it yet.
For those of you who haven't had the pleasure of working with angular: Once you've familiarized yourself with the verbiage, most of jeswin's concerns here come second nature just by glancing in one's source code. Let's take the example:
form.length.$error.float
The name form, albeit horribly chosen in this case, represents the parent form's identifier in angular (the form's name attribute). It would've made more sense to use <form name="formLengthValidationDemo"> or something more insightful so you could more easily see the name matching from HTML to JS.$error is simply the representation of any form validation errors that may have occurred. It's standard in angular, and there's plenty of documentation. Just google for "angularjs form validation" and you'll find a million resources at your disposal.
form.length.$error.float is checking if an error exists for the validation rule float. Given the limited amount of code in the sample, we'd have to arbitrarily assume that the "smart-float" directive is implicitly setting a custom validation rule via:
ngModel.$setValidity('float')
I'll have to agree to disagree regarding pattern usage and dependency injection. They do have a place, and it tends to be in larger applications which become a burden to maintain as your application grows. To be quite honest, I believe angular brought a simplicity to DI that has yet to be seen in many other frameworks. It entirely lowered the barrier to entry for writing testable code and heavily promoted unit testing at the same time.The declarative style that Angular coaxes you into makes things incredibly easy to understand - you can write code like
<header>
<navbar></navbar>
</header>
<main>
<sidebar></sidebar>
<content></content>
</main>
<footer>
<company-info></company-info>
<credits></credits>
</footer>
And instantly understand what the purpose of these elements are - they're easy to read, they're descriptive, and they're clearly custom elements not part of the normal HTML5 spec, so you can instantly recognize that they must be directives.I can also do simple directives like <loading-spinner></loading-spinner> and create a nice template for CSS to hook into by using the loading-spinner element tag without having to distract from the rest of my DOM with a nesting of 8 divs that can easily be tucked away in a reusable template.
The reason being, considering that HTML5 is an ever evolving spec that it might be possible for a new element to be introduced that could be using the same name as one of your examples. That might muck things up a bit. At least visually, as I would imagine the directives would likely continue working the same as before. It's just that the "they must be directives" logic would fail in that instance.
Interestingly, out of the box Angular provides directives as a, input, or form—meaning that when you write <input> you are, in fact, invoking a directive that provides extra features along with native tag's functionality. While using Angular, you may as well consider every HTML element a directive.
Nevertheless, Angular uses ng- prefix with their built-in directives that don't replicate some existing tag's functionality closely.
<sidebar></sidebar>
can instead be coded as: <span data-sidebar></span>
or something similar.http://w3c.github.io/webcomponents/spec/custom/
The only requirement is that they have a dash in the name. So while <sidebar> is not a valid HTML5 element, <a-sidebar> would be.
Yes, this is actually the recommended practice from the documentation. Built-in Angular directives are typically prefixed with `ng-`, and they suggest that other projects/developers use their own prefixes to avoid conflict.
Why not use XHTML at that point? If XHTML ever had a clear mission statement in life it was that.
I mean I thought XHTML was a curse a few years ago when it was The Thing Every Good Designer Uses™ since it couldn't be rendered as XML in the most popular browser. But hopefully that's not as much an issue anymore. Or maybe it is. I haven't kept up with IE.
Or you know, an adoption of only the needed part, instead of all the BS junk that comes with XML namespaces.
>Why not use XHTML at that point?
Because of all the other junk that comes with it. And because it comes from W3C.
When users gain the ability to define their own tags, you might not know which ones are driven by directives, the custom element, or both even.
Arguments from personal incredulity don't engage substantively with what they ostensibly claim to refute because they import a variable- the argument-maker's conception of what seems plausible- that really should do no work in a logical analysis.
The arguments adumbrated in the parent comment seem to have similar failure modes, adorned as they are with premises such as "to me, [the directive] is a foreign object I don't recognize," and "I can't even tell what that means." Someone who has never programmed before could look at some vanilla javascript and plead perplexity, but obviously this isn't an indictment of javascript itself. To really make the point, the parent comment would have to show that the learning curve is disproportionately arduous for the payoff at the summit, but reiterations of personal unfamiliarity were offered instead.
Jeswin gives no evidence of having made a reasonable attempt to understand Angular ("directives, scopes?"), but more crucially, displays little understanding of the benefits of Angular. DI is criticised as "a solution looking for a problem" in the context of javascript, as if dependency injection were a bandaid for not being a dynamic language. DI enables testability, and not even mentioning this advantage, let alone not providing a cogent argument for why the learning curve of DI doesn't justify the gains in testability, is to refuse to participate in the discussion entirely. Directives are similarly dismissed as "foreign objects," which they might be to some, but they're hugely powerful foreign objects that allow arbitrary behaviour to be written declaratively. Not knowing the benefits of Angular obviously contributes greatly to a reluctance to learn it, and perhaps a subsequent rationalisation of this reluctance as being provoked by something intrinsic to the framework.
Fittingly, after expressing bewilderment regarding Angular scoping, Jeswin goes on to divide the world into two camps, declaring membership in "the one which makes me productive with the languages, specs, and standards I already know", which is about the closest thing to a natural language scoping bug I've come across.
Dependency Injection is a redundant, useless pattern in dynamic languages; especially when it comes to testability.
In test.js:
//paymentService may be an instance or a class
services.paymentService = mockPaymentService;
....
//use paymentService in your tests here.
The above over-simplified example satisfies most test cases. You can convince me with some use-cases.(Edit: You weren't misrepresenting what I said. Removed that claim. I misread, apology.)
Beyond testing, DI makes it much easier to swap in different implementations of a dependency than simply throwing things into the global scope lets you do. Suppose I want to switch my model from one that communicates with Parse to one that communicates with Firebase. Supposing I adhere to the same interface, I should be able to simply drop it in place without affecting other functions or objects that still rely on the Parse version of the model.
Parse and Firebase example:
//someservice.js
...
//works as long as both retain the same interface.
provider = new FirebaseProvider; //new ParseProvider()
//add: just using an if condition, the old fashioned way.
getProvider: function() {
if (config.provider === 'parse')
return ParseProvider()
else
return FirebaseProvider()
Why is writing configuration cleaner than doing the above? That thought process is carried over from projects with lengthy build time.What alternatives do you recommend to DI?
In my test initialization, I'd probably just replace the value of "ns.someService" worldwide with a mock.
Having a window-wide namespace might make sense in the test, but it is pretty risky/limiting if you are writing a component that should be reused in contexts you don't fully control. There are other ways around that besides DI, but they will probably have similar trade-offs in safety EOU, etc.
Here a quick comparison of both: http://versus.com/en/angularjs-vs-react
Here a pretty good video of React's founder pointing on some weakness of Angular: http://www.youtube.com/watch?v=x7cQ3mrcKaY
The cycle probably goes thusly:
Large monolithic framework comes and shows everyone a new way of doing things (Angular/Django).
People think it is too large and monolithic, so make microframeworks (Flask/Whatever comes after Angular).
The next step will be a kind of happy medium.
I predict that the next winner will leverage web components and do the one thing that makes that paradigm better.
(That's why things like rivet and epoxy exist; because backbone doesn't do it right)
"Two way data-binding" is avoided. While it certainly makes for a nifty demo, and works for the most basic CRUD, it doesn't tend to be terribly useful in your real-world app. Sometimes you want to update on every keypress, sometimes on blur, sometimes when the panel is closed, and sometimes when the "save" button is clicked. In almost all cases, simply serializing the form to JSON is faster and easier. All that aside, if your heart is set, go for it.
Or is it simply ppl need to exercise their mental creativity?
JQuery and JS were certainly not dumped, it is just that people writing single page apps moved on and are now using tools that help them.
Well, you can't have Angular without JS so we'll focus on the point of jQuery here.
jQuery does a few things really well – so well that Angular itself uses jQuery (or jqLite by default). angular.element(selector) returns a jQuery object.
Angular also does a few things well. Code reusability and testability are much easier to achieve with Angular, in my opinion. Features like data-binding also help to reduce boilerplate code.
Well you certainly can use it without writing any JS:
https://github.com/angular/angular.dart
However, you're going to compile it to JS when you're done.
As a learning exercise, I wrote a page using just jquery, rewrote it in backbone, and then rewrote it in angular. Backbone helped me separate concerns; Angular helped me do that while writing _way_ less code, since I didn't have to manage keeping the DOM and the JS model in sync.
I redid a relatively trivial CRUD interface from backbone to Angular. The amount of code that I didn't need in Angular was ridiculous. Most of the code in backbone was moving stuff from the DOM into JS. Like var x = $('#elem').val(); kind of things over and over just did not need to be there in Angular.
I think that these kinds of interfaces hit a really good sweet spot with Angular and other databinding frameworks.
jQuery has nothing to do with whether the app is single page or not.
Those frameworks make writing single page apps very easy.
I have suffered trough JEE which is/was really humungous, and Angular is really tiny in comparison.
React is the Holy Grail of JS frameworks.
Here's my article where I analyze this in much more detail: http://blog.reverberate.org/2014/02/react-demystified.html
Also React does not "solve all the problems in the world" -- it says nothing about routing, validation, testability, and many of the other problems that Angular has solutions for.
Passing data to separate components without a shared parent is outside of what React is trying to accomplish but I've handled it before by passing a Backbone model to the separate components as props.
Harder than what?
Also, the "we wouldn't have built many apps" part is a stretch. It's actually the opposite, AngularJS is extremely popular and the most successful current JS framework.
And yes, AngularJS absolutely defines its own language. The directives create an enhanced HTML (that you can enhance even further), and it has its own expression language where you can ask the value of `form.length.$error.float` without fearing null pointers.
This is basically what Angular is about, and why it works as nicely and cleanly as it does. And it's true; learning a new framework is absolutely comparable to learning a new language. Rails is not simply standard Ruby; it defines loads of new stuff that automatically handles things for you below the surface. Spring completely changes the way you work with Java. Grails has its own DSLs for various tasks.
Every framework has a learning curve. And a framework that doesn't change how you think is as useless to learn as a language that doesn't change how you think. But if you don't like learning, you can always simply stick to what you're familiar with.
I agree with your conclusion, but I think you're misusing semantics. This isn't semantic, but neither would anything else be. As soon as we get to using logic, we don't have semantics.
That line is unclear and not easy to understand. That is why I object to it.
'unclear' is a better choice. And less pretentious too, than 'semantic'.
In more recent talks the React devs have avoided using JSX in examples and instead use the compiled form as JSX goes far enough from what people expect that it turns people away before they've given it a chance.
The most important idea to take from React is that UI components are much simpler when they are state machines.
The DOM is what the user sees. That's all. With React, you have a virtual DOM that can hold everything, not just what the user sees. It's a pure data structure, and can be manipulated as such.
Because that DOM is a pure data structure, React can figure out for you what parts have changed, and re-render those bits as needed.
I guess this is why Angular keeps the model separate from the DOM.
That said, the virtual DOM strikes me as a really good idea I'd like to see in Angular.
You won't regret taking a couple of hours to try to build something simple with it.
The weakness with Angular is not the view imo, but the $apply-cycle which can bog down even a modern browser with moderately sized data.
(You can do the same thing with pure JS, there are some forms of simplifying the React.DOM.div() calls, but coffeescript makes it beautiful.)
I could not care less. I find that talk about web programming has been polluted by non-terms like "semantic" that doesn't mean anything specific (in the context).
Especially the whole hoopla with regard to "semantic HTML", with designers (who don't know much if anything about programming, and just heard this "semantic" term from a few industry fad gurus) using it to insist developers should treat HTML as a format for reuse (as if the reason we write HTML is to enable better screen scrapping).
Endless discussions about whether it's ok to a DIV if it's purely for display purposes of not, as if HTML/CSS dont already make a clusterfuck of separating markup from presentation.
Fuck "semantic HTML" -- it's a presentation format, that also happens to have a not-that-functional styling component. If you wan't reuse and semantics, get those from the data level (the db, the REST endpoint, etc), not from code meant for browsers.
Why this is the top comment is beyond me. This is whining.
It is a DOM marker (HTML attribute, element, class or comment) with behavior (JavaScript) tied to it.
Angular lets you create your own HTML attributes. That's what a directive is.
I am personally much more attracted to the reactive style of Meteor's Blaze or ReactJS. It seems much easier for me to reason about, but maybe this has something to do with my background in video games which means that a render-loop seems really natural to me.
I don't have enough real world experience with the former to make a comparison so I'd love to hear from someone who is able to properly compare the two styles what the real pros and cons are.
I think Angular is better for "slightly more traditional" webapps such as dashboards. Its directives are nice for building small custom widgets, and the thin model wrappers $http and $resource can be useful (though I'm looking forward to what they add to these in v2.0). Data-binding is very straightforward and easy to understand.
I've built a couple of projects in Meteor, and I'm still a fan, though I've yet to have a real use case for the realtime (pub/sub) stuff: I'm still making straightforward webapps that would probably be just as easy (if not easier) to build in Angular or Backbone. The reason I'm using Meteor is more for productivity than for reactive realtime: I love that I get Mongo, a watched asset pipeline and a bunch of other stuff for free. I love being able to share/move code around easily between the client and server.
Sometimes the reactivity in Meteor can be quite subtle and difficult to get your head around, and I wish I was just using straightforward webservices instead; other times it's a productivity booster and keeps things simpler.
ReactJS is a really nice concise view library, with some extra stuff that Facebook put in that I'm not sure should really be in there (e.g. the synthetic events) and should maybe be a module instead (an approach I'm very happy to see Angular taking). ReactJS does for views and templates what Meteor does for client-server. It's also got its share of subtleties and gotchas though.
I'm also from a video games background and am also tending to favour Meteor and ReactJS. But I do think the extra power of these technologies brings an extra set of complexity and things to watch out for. But then Angular has transclusions, so......
That's pretty cool.
I thought the internals of Angular already had a reputation for being pretty horrible and indecipherable already. I doubt this will improve on any of that criticism.
Do you have any reason to believe that the Traceur compiler generates unreadable output with Angular?
No snark, I really did think this. Of course, Wordpress and Drupal do seem to have a lot of crazy architectural decisions that made maintenance difficult, so maybe I am just completely off.
Here are two JS files from a framework that I've written myself over the past few years, for my own use. Is the angular source code pretty much like this, or much more optimized?
https://github.com/EGreg/Q/blob/master/platform/plugins/Q/we...
https://github.com/EGreg/Q/blob/master/platform/plugins/Stre...
[1]: https://docs.google.com/file/d/0BwftRCZoTFiyRzhnVml3dlRiR1A5...
The word "literally" has officially lost all meaning.
http://www.merriam-webster.com/dictionary/literally
1 : in a literal sense or manner : actually <took the remark literally> <was literally insane>
2: in effect : virtually <will literally turn the world upside down to combat cruelty or injustice — Norman Cousins>
http://www.merriam-webster.com/dictionary/literally
1 : in a literal sense or manner : actually <took the remark literally> <was literally insane>
2 : in effect : virtually <will literally turn the world upside down to combat cruelty or injustice — Norman Cousins>
(As in, they drew a sword and severed his limbs, such that literal-literal blood was everywhere)
Very sad.
This is great for XYZ, but I need to do AB123C... well... shit.
JS not good enough? We'll invent new languages; Dart, Typescript, Coffeescript, etc. ES6 not yet done? We'll build a transpiler so we can fiddle with it until it's done - if ever.
I just wish the standardisation processes for web technologies would go faster. We get small revolutions every 2 years or so, but the standards behind them only get updated every decade.
Why not just take Require.JS and use it as a dependency injector, like any other client-side frameworks allow you to do?
IMO Angular is trying too hard to be everything, while it is now de facto a template system with an excellent support of custom directives and two-way data-binding.
For example, Angular could be a good choice for a View layer of an app built on top of Backbone, since it moves away from opinionating the View layer. But it's just too much fuss happening around this templating system in Angular.
Angular's injector, like Guice's injector is a service locator. Because the normal way to use AngularJS is to simply list your dependencies instead of requesting what you want from an injector instance, it is an IOC DI framework.
"We're in early stages of designing Angular 2.0, but some of our goals are:
- Angular will use the underlying web platform features available to it (e.g. Node.bind, template integration, Custom Elements, etc...)
- Web Components (Polymer, Ember, or any other framework/library) will work seamlessly within Angular apps and directives.
- Components written in Angular will export to Web Components (to be used by Polymer, Ember, or any other framework/library) .
We're working actively with the MDV, Web Components, and Polymer teams to make sure that our approaches remain compatible as all these projects evolve (and they will still evolve).
-- Misko & the Angular team" (https://groups.google.com/forum/#!msg/polymer-dev/4RSYaKmbtE...)
Does anyone know if the focus on Web Components is still there?
Where can I find a simple example?
Seems pretty simple, imo.
How do I rewrite the following using the new DI system?
function MyCtrl($http, Base64) {
$http.get('http://www.example.com').success(function (data) {
console.log(Base64.decode(data));
});
} import {Http} from 'angularjs/http';
import {Base64} from './base64';
@Inject(Http)
@Inject(Base64)
export class MyCtrl {
constructor(Http, Base64) {
Http.get('http://www.example.com').success(function (data) {
console.log(Base64.decode(data));
});
}
}
Not too bad, right?I'll stick to ES 5 / Angular 1.2 if we're required to write this much boilerplate to achieve the same thing.
import {Inject} from 'di/annotations';It's great to see a framework team take a fundamentally new approach. Many frameworks get stuck in a mindset while other frameworks pop around them with new and more innovative approaches.
Good luck to the Angular team.
As to the mobile-first changes, we'll see - I have some reservations on using Angular on lower specced mobiles, for the $watch()-cycle seems to me huge drain on batteries. But since the Angular guys know what they are doing, I am looking forward to nothing but goodness.
Why not just include restangular as one of the resource modules if they decide to go all-out modular?
I am hoping for multiple ngIncludes and a bit easier development of directives, other than that, keep up the good work, guys :)
You will need to go Playstation 3 native for performance, otherwise, you will not be able to do much computation.
Also, the docs say that they do not know when they will be done. While I can understand that we may not know problem that arise, it is a pet peeve of mine that I never have a an idea when Drupal 8 will be released. I know that open source contributions are hard to track, we have to estimate (guess) when our projects will be done in our work, so why can we not do it for the projects we love?
Not really, since it's not remotely in Beta yet. It sounds like early alpha at best.
oh, and don't forget better documentation :)
Rewriting a successful framework with no backward support is suicide. Please read this link before continuing on this path: http://www.joelonsoftware.com/articles/fog0000000069.html. Another informative example is Perl 6. The 'rewrite' killed Perl. Microsoft also did this time after time, forcing developers to constantly rewrite their applications instead of spending time writing new products. Even Python 3, with it's limited incompatibilities, had a very negative effect on the community: https://programmers.stackexchange.com/questions/63859/why-do....
Why should I bother supporting Angular 2.0, since 2 years from now the developers are going to get bored and want Angular 3.0? The community is NOT going to take the time to rewrite all their code to scratch your itch. My time is very limited, and I need to be selective where I use it. I love Angular, but there is zero chance I will rewrite any of my code for Angular 2.0. It's not going to happen. I'm quite certain that my sentiments are shared by other developers who have put in far more time and effort than I have.
My strong advice is to fix and optimize what you have. If there are areas that need rewriting or rearchitecting, then do it, but leave a clear upgrade path and don't break existing apps where possible. Sorry, but that's how software works.
You have a ground breaking, beautifully designed framework. Please don't destroy it because it's not perfect. Nothing is.
Can someone at Google please talk some sense into the developers running this project?
"Simplify the directive API
Integrate with other component frameworks using web standards
Improve performance
Allow tools like IDEs to analyze and validate templates"
I don't get why BlogSpot an so many other sites require javascript to o absolutely nothing of value just to see the site. It's maddening and appalling.
Also, I'm surprised I got downvoted for saying that we should be considering the disabled when making decisions on how to structure a blog. I know accessibility isn't _cool_ but it's the right thing to do, especially for a text-based site, like a blog.
(PS: mendelk, I'm not accusing you of downvoting me)
Could anybody with experience confirm/deny?
1.http://hanselminutes.com/413/im-a-blind-software-technician-...
What's the current best options?
Pick up a Backbone book and in two weeks your dangerous enough to use it. A month, you're in the groove. 6 months: Angul-who?
When you have implemented features enough to notice that it takes too many steps to make new views that resemble old ones, ease off from feature building, and make proper custom abstractions suitable for that particular project.
Also check out Backbone extension: Marionette for modularizing and backbone-documentmodel for non-linear forms.
Is this supposed to sell Backbone? Because I'm on a similar curve with Angular with just the online docs. Doing stuff in Angular is really unbelievably easy once you let go of your old preconceptions. It's a new way of thinking, but it's one that's very effective.
I'm planning to use it in my next project but haven't yet. It seems to fit the bill nicely.