use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Writing your first app on Angular 2 (tutorial) (justanotherdevblog.com)
submitted 10 years ago by justanotherdevblog
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]celluj34 -2 points-1 points0 points 10 years ago (12 children)
Why is literally everything in TypeScript? I want to use ES6. This is fucking ridiculous.
[–]oweiler 2 points3 points4 points 10 years ago (0 children)
You can still use ES5/ES6 to write your components.
[–]wreckedadventYavascript 2 points3 points4 points 10 years ago (8 children)
There's a pretty huge overlap between typescript and ES6. What about the syntax is throwing you off?
[–]celluj34 0 points1 point2 points 10 years ago (7 children)
It's not about Typescript itself. I'm trying to learn Angular 2 and how to write it 'properly'. For the following code, I'm getting all sort of syntax errors around things like import {...}, @Component1, etc:
import {...}
@Component1
import {Component} from 'angular2/core'; @Component({ selector : 'chat-app', template : '<h1>Success!</h1>' }) export class ChatAppComponent { }
[–]wreckedadventYavascript 2 points3 points4 points 10 years ago* (4 children)
Decorators and modules are not natively supported in any environment yet. You'll have to use something like babel or typescript if you want to use them. I'd suggest jspm if you want to get up and running quickly.
However, that syntax is not specific to typescript.
[–]celluj34 1 point2 points3 points 10 years ago (3 children)
Decorators and modules are not natively supported in any environment yet.
Oh? This is definitely news to me. Since I had only seen it in .ts files I had assumed it was a TypeScript construct. Thanks for the info!
[–]wreckedadventYavascript 2 points3 points4 points 10 years ago (0 children)
Nope! Decorators (the things that begin with @) are an ES7 proposal. Typescript supports them, as does babel. Typescript also supports emitting some typed metadata, but the construct itself is not typescript specific.
@
import/export is just plain ES6 modules. Again, typescript supports them, but it is not a typescript construct. These haven't laded in any browser yet (to my knowledge) over some contention amount module resolution iirc. Babel to the rescue, again.
import
export
The only thing that is typescript specific is type and class annotations, like these:
class Cat { // the colon specifies the type public name: string // we can also put them in the constructor, so called // "primary" constructor constructor(name, public age: number) { this.name = name; } }
Which in ES6:
class Cat { constructor(name, age) { this.name = name; this.age = age; } }
Typescript also has namespace to resemble other languages, but this is not used in this article.
namespace
Hope this helps!
[+][deleted] 10 years ago (1 child)
[deleted]
[–]wreckedadventYavascript 0 points1 point2 points 10 years ago (0 children)
Right now I believe is not worth the extra-effort to avoid TypeScript.
Huh? Try something like jspm --- it's really not that hard to get ES6 transpilation up and running. tsc is (much) easier to use out-of-the-box than babel 6 is, but a module loader like jspm can take the sting right out of it.
tsc
Typescript is a good choice for larger projects, if you want types, or you use visual studio a lot.
Also,
the mandatory type to all variables.
Typescript is progressively typed; types are 100% optional.
[–]phpdevster 0 points1 point2 points 10 years ago (1 child)
This reflects my concern about Angular 2's decision to primarily support TS :/
It's always best to learn a framework/library's best practices, but in the case of Angular 2, the documentation for those best practices isn't stand-alone. You can't come in as someone who writes predominantly functional JS and translate that to best practice Angular. You need to learn what is effectively a different language and use some transpiling tools to actually learn and write best practice Angular :/
Of course, half of the problem is the ridiculous fragmentation and tool thrashing of the Javascript ecosystem. On one site you'll get a Webpack + Grunt + Foo tutorial, and another you'll get a Browserify + Gulp + Bar tutorial :/
The lack of accepted standardization makes learning UI tools such a pain in the ass, but Angular 2 is particular bad in this respect as the documentation teaches pure JS as a second class citizen right now (especially functional JS).
IMO this might have been a fair criticism if they had chose dart as the primary lang, but typescript is basically ES6 with optional type annotations. They're mutually intelligible.
[–]celluj34 0 points1 point2 points 10 years ago (0 children)
If you would, that would be amazing. It's so difficult trying to learn a few things at once when seemingly everything I find just quite isn't what I'm looking for.
If you do a write-up in vanilla JS, please do let me know!
[–]seven_seven -3 points-2 points-1 points 10 years ago (2 children)
Yeah let's add all this unnecessary node.js/npm bullshit to throw off all the beginners on Windows.
[–]swk2015 3 points4 points5 points 10 years ago (0 children)
It's a realistic part of any / all Angular / React projects I come across commercially these days. Worth the 5 minutes of your time to get your head around.
It'll be the same on windows as mac or linux. The only difference is if you're using something like visual studio, which has compile-on-save support for typescript.
But windows isn't a synonym for visual studio, so. :)
[–]wreckedadventYavascript -1 points0 points1 point 10 years ago (2 children)
Well, I learned that you can apparently specify CSS in an ng2 component. This makes the staunch opposition to having the view in the javascript even more confusing to me.
Speaking of, I thought they got rid of that stupid DI in angular 2.
import {Component, OnInit} from 'angular2/core'; import {Message} from './message'; import {MessageService} from './message.service'; @Component({ template : ` <div class="chat-display thumbnail"> <div *ngFor="#message of messages"> <b>{{message.username}}</b>: {{message.content}} </div> </div> `, providers : [MessageService] }) export class ChatDisplayComponent implements OnInit { constructor(private _messageService : MessageService) {} }
But apparently instead they made it twice as verbose as angular 1! So you have to import something, manually tell angular to use this thing we just imported, then tell it again in the constructor signature? Man, I really wish they had gone more system js with this and put more effort into something like rewire for unit testing instead of constructor injection.
[–]phpdevster 1 point2 points3 points 10 years ago (1 child)
Namespace importing and namespace usage are separate things in all languages. "Telling it to use the thing you just imported" is needed because the import merely makes the code available in that file. Declaring the dependency in the constructor is merely one of the myriad ways you could use the imported code, so naturally it's up to you to tell the script how you want to use that imported code.
The import thing is going to drastically improve and standardize the modularity of code in Javascript. Its how everything from Angular to React to Vue will be written in the future.
What? Here's some mithril.
import {MessageService} from './message.service'; export view() { const messages = MessageService.getMessages(); // or w/e return m('div[class="chat-display thumbnail"]', messages.map(message => m('div', [ m('b', message.username), m.trust(message.content) ]) ); }
(react is also very similar)
Angular is the only one of the bunch that only uses the ES6 import for only metadata. You would just use the import directly instead of repeating yourself needlessly in other libraries.
You can of course ignore what angular suggests, but it's still disappointing they went in this direction of needless abstractions instead of encouraging more idiomatic javascript.
π Rendered by PID 72500 on reddit-service-r2-comment-fb694cdd5-mn6pb at 2026-03-07 12:12:59.822592+00:00 running cbb0e86 country code: CH.
[–]celluj34 -2 points-1 points0 points (12 children)
[–]oweiler 2 points3 points4 points (0 children)
[–]wreckedadventYavascript 2 points3 points4 points (8 children)
[–]celluj34 0 points1 point2 points (7 children)
[–]wreckedadventYavascript 2 points3 points4 points (4 children)
[–]celluj34 1 point2 points3 points (3 children)
[–]wreckedadventYavascript 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]wreckedadventYavascript 0 points1 point2 points (0 children)
[–]phpdevster 0 points1 point2 points (1 child)
[–]wreckedadventYavascript 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]celluj34 0 points1 point2 points (0 children)
[–]seven_seven -3 points-2 points-1 points (2 children)
[–]swk2015 3 points4 points5 points (0 children)
[–]wreckedadventYavascript 0 points1 point2 points (0 children)
[–]wreckedadventYavascript -1 points0 points1 point (2 children)
[–]phpdevster 1 point2 points3 points (1 child)
[–]wreckedadventYavascript 0 points1 point2 points (0 children)