Introduction
YouTube Video Link:
In this article, I’ll show how to create a TodoMVC application using Angular2 and Aurelia to compare these frameworks. The article is in a table format with 2 columns named “Angular2” and Aurelia, which contains the steps to create a TodoMVC application in both these frameworks. The projects are created using CLI (Command Line Interface) tools that are part of these frameworks. The source code for these projects are available in my github page:
Angular2 Source Code: https://github.com/rajajhansi/ng2-todo-app
Aurelia Source Code: https://github.com/rajajhansi/au-todo-app
Steps to create a Todo MVC Application in Angular2 and Aurelia
The table below lists the steps to create a Todo MVC Application in Angular2 and Aurelia.
Angular2 | Aurelia |
Installing the ng CLInpm install angular-cli -g | Installing the au CLInpm install aurelia-cli -g |
Creating a new applicationng new ng2-todo-app | Creating a new applicationau new au-todo-app |
Running the applicationcd ng2-todo-appng serve | Running the applicationcd au-todo-appau run --watch |
Creating a Todo classng g class Todo | Creating a Todo classYou can either run the command:au generate Todo and move src/resources/Todo.ts into src folder and delete src/resources/elements/Todo.html OR Create a new file named Todo.ts in src folder, which is easier. |
todo.tsexport class Todo { id: number; description: string = ''; done: boolean = false; constructor(values: Object = {}) { Object.assign(this, values); } } |
todo.tsexport class Todo { id: number; description: string = ''; done: boolean = false; constructor(values: Object = {}) { Object.assign(this, values); } } |
Creating unit test for Todo class using jasmine - Angular2
todo.spec.ts
/* tslint:disable:no-unused-variable */ import { TestBed, async } from '@angular/core/testing'; import {Todo} from './todo'; describe('Todo', () => { it('should create an instance', () => { expect(new Todo()).toBeTruthy(); }); it('should accept values in the constructor', () => { let todo = new Todo({ description: 'hello', done: true }); expect(todo.description).toEqual('hello'); expect(todo.done).toEqual(true); }); it('should ignore values sent in wrong properties in the constructor', () => { let todo = new Todo({ title: 'hello', done: true }); expect(todo.description).toEqual(''); expect(todo.done).toEqual(true); }); });
Creating unit test for Todo class using jasmine - Aurelia
todo.spec.ts
/* tslint:disable:no-unused-variable */ import {Todo} from '../../src/todo'; describe('Todo', () => { it('should create an instance', () => { expect(new Todo()).toBeTruthy(); }); it('should accept values in the constructor', () => { let todo = new Todo({ description: 'hello', done: true }); expect(todo.description).toEqual('hello'); expect(todo.done).toEqual(true); }); it('should ignore values sent in wrong properties in the constructor', () => { let todo = new Todo({ title: 'hello', done: true }); expect(todo.description).toEqual(''); expect(todo.done).toEqual(true); }); });
Running unit testsng test |
Running unit testsau buildau test |
Creating a Service class for Todong g service Todo |
Creating a Service class for Todocreate a new folder named “src\services” and a file named todo.service.ts |
Installing the TodoMVC Stylesheetsnpm install todomvc-app-css todomvc-common --saveAdding custom style for toolbar |
Installing the TodoMVC Stylesheetsnpm install todomvc-app-css todomvc-common --saveAdding custom style for toolbar |
styles.css - Angular2
/* You can add global styles to this file, and also import other style files */ @import url('../node_modules/todomvc-common/base.css'); @import url('../node_modules/todomvc-app-css/index.css'); .app-root-loader { text-align: center; padding: 30px; } .toolbar { color: #777; /*background-color: lightslategray;*/ padding: 5px 10px; height: 20px; text-align: center; border-top: 1px solid #e6e6e6; float: right; }
styles.css - Aurelia
/* You can add global styles to this file, and also import other style files */ @import url('../node_modules/todomvc-common/base.css'); @import url('../node_modules/todomvc-app-css/index.css'); .app-root-loader { text-align: center; padding: 30px; } .toolbar { color: #777; /*background-color: lightslategray;*/ padding: 5px 10px; height: 20px; text-align: center; border-top: 1px solid #e6e6e6; float: right; }
Adding a new Todo Item in text box after entering the description and pressing enter keyAngular2 has (keyup.enter) event to trigger a JavaScript function upon pressing enter key after entering the description for a new Todo item. |
Adding a new Todo Item in text box after entering the description and pressing enter keyAurelia recommends to use <form> and wire the submit.trigger to trigger a JavaScript function upon pressing enter key. It also requires a <button type=”submit”> as well. To attach enter keypress event to any element, we can easily do that with Aurelia Custom attribute. au generate attribute keyup-enter |
keyup-enter.ts - Aurelia
import {autoinject} from 'aurelia-framework'; @autoinject() export class KeyupEnterCustomAttribute { element: Element; value: Function; enterPressed: (e: KeyboardEvent) => void; constructor(element: Element) { this.element = element; this.enterPressed = e => { let key = e.which || e.keyCode; if (key === 13) { this.value();//'this' won't be changed so you have access to your VM properties in 'called' method } }; } attached() { this.element.addEventListener('keypress', this.enterPressed); } detached() { this.element.removeEventListener('keypress', this.enterPressed); } }
Creating the application componentng g component TodoApp |
Creating the application componentau generate element todo-appAurelia has the concept of global resources and by adding a resource into global resources, you can use them in any views without having to do <require from=”path of the resource”></require> src/resources/index.tsimport {FrameworkConfiguration} from 'aurelia-framework'; export function configure(config: FrameworkConfiguration) { config.globalResources([ "./elements/todo-app", "./attributes/keyup-enter" ]); } |
Wiring Todo Item functionalities into the App component - Angular2
todo-app.component.ts
import { Component, OnInit } from '@angular/core'; import { Todo } from '../todo'; import { TodoService } from '../todo.service'; @Component({ selector: 'todo-app', templateUrl: './todo-app.component.html', styleUrls: ['./todo-app.component.css'], providers: [TodoService] }) export class TodoAppComponent implements OnInit { newTodo: Todo = new Todo(); filter: string = 'all'; filteredTodos: Todo[] = []; constructor(private todoService: TodoService) { } ngOnInit() { } addTodo() { this.todoService.addTodo(this.newTodo); this.newTodo = new Todo(); this.filterTodo(this.filter); } toggleTodoDone(todo) { this.todoService.toggleTodoDone(todo); this.filterTodo(this.filter); } removeTodo(todo) { this.todoService.deleteTodo(todo.id); this.filterTodo(this.filter); } filterTodo(filterCriteria: string) { this.filter = filterCriteria; this.filteredTodos = this.todoService.filterTodo(filterCriteria); } completeAllTodos() { this.todoService.completeAllTodos(); // this.checkIfAllTodosAreCompleted(); this.filterTodo(this.filter); } removeAllTodos() { this.todoService.removeAllTodos(); this.filterTodo(this.filter); } removeDoneTodos() { this.todoService.removeDoneTodos(); this.filterTodo(this.filter); } }
Wiring Todo Item functionalities into the App component - Aurelia
todo-app.ts
import {inject} from 'aurelia-framework'; import {Todo} from '../../todo'; import {TodoService} from '../../todo.service'; @inject(TodoService) export class TodoApp { newTodo: Todo = new Todo(); filter: string = "all"; filteredTodos: Todo[] = []; constructor(private todoService: TodoService) { } addTodo() { this.todoService.addTodo(this.newTodo); this.newTodo = new Todo(); this.filterTodo(this.filter); } toggleTodoDone(todo) { this.todoService.toggleTodoDone(todo); this.filterTodo(this.filter); } removeTodo(todo) { this.todoService.deleteTodo(todo.id); this.filterTodo(this.filter); } filterTodo(filterCriteria: string) { this.filter = filterCriteria; this.filteredTodos = this.todoService.filterTodo(filterCriteria); } completeAllTodos() { this.todoService.completeAllTodos(); //this.checkIfAllTodosAreCompleted(); this.filterTodo(this.filter); } removeAllTodos() { this.todoService.removeAllTodos(); this.filterTodo(this.filter); } removeDoneTodos() { this.todoService.removeDoneTodos(); this.filterTodo(this.filter); } }
Wiring Todo Item functionalities into the App View - Angular2
todo-app.component.html
<section class="todoapp"> <header class="header"> <h1>Todos</h1> <div class="toolbar"> <a href="#" (click)="removeAllTodos()"> Remove All </a> | <a href="#" (click)="removeDoneTodos()"> Remove Completed </a> | <a href="#" (click)="completeAllTodos()"> Complete All </a> </div> <br/> <input type="text" class="new-todo" placeholder="what needs to be done?" autofocus="" [(ngModel)]="newTodo.description" (keyup.enter)="addTodo()"> </header> <section class="main" *ngIf="filteredTodos.length > 0"> <ul class="todo-list"> <li *ngFor="let todo of filteredTodos" [class.completed]="todo.done"> <div class="view"> <input type="checkbox" class="toggle" (click)="toggleTodoDone(todo)" [checked]="todo.done"> <label>{{todo.description}}</label> <button class="destroy" (click)="removeTodo(todo)"></button> </div> </li> </ul> </section> <footer class="footer" > <span class="todo-count"><strong>{{filteredTodos.length}}</strong> {{filteredTodos.length === 1 ? 'item': 'items'}} left</span> <ul class="filters"> <li> <a class="{{filter == 'all' ? 'selected' : ''}}" href="#" (click)="filterTodo('all')">All</a> </li> <li> <a class="{{filter == 'active' ? 'selected' : ''}}" href="#" (click)="filterTodo('active')">Active</a> </li> <li> <a class="{{filter == 'completed' ? 'selected' : ''}}" href="#" (click)="filterTodo('completed')">Completed</a> </li> </ul> </footer> </section>
Wiring Todo Item functionalities into the App View - Aurelia
todo-app.html
<template> <section class="todoapp"> <header class="header"> <h1>Todos</h1> <div class="toolbar"> <a href="#" click.trigger="removeAllTodos()"> Remove All </a> | <a href="#" click.trigger="removeDoneTodos()"> Remove Completed </a> | <a href="#" click.trigger="completeAllTodos()"> Complete All </a> </div> <br/> <input type="text" class="new-todo" placeholder="what needs to be done?" autofocus="" value.bind="newTodo.description" keyup-enter.call="addTodo()"> </header> <section class="main" show.bind="filteredTodos.length > 0"> <ul class="todo-list"> <li repeat.for="todo of filteredTodos" class="${todo.done ? 'completed' : ''}"> <div class="view"> <input type="checkbox" class="toggle" checked.bind="todo.done"> <label>${todo.description}</label> <button class="destroy" click.trigger="removeTodo(todo)"></button> </div> </li> </ul> </section> <footer class="footer"> <span class="todo-count"><strong>${filteredTodos.length}</strong>${filteredTodos.length === 1 ? ' item ': ' items '} left</span> <ul class="filters"> <li> <a class="${filter == 'all' ? 'selected' : ''}" href="" click.trigger="filterTodo('all')">All</a> </li> <li> <a class="${filter == 'active' ? 'selected' : ''}" href="" click.trigger="filterTodo('active')">Active</a> </li> <li> <a class="${filter == 'completed' ? 'selected' : ''}" href="" click.trigger="filterTodo('completed')">Completed</a> </li> </ul> </footer> </section> </template>
Using custom element in app.html - Angular2
app.html
<todo-app></todo-app>
Using custom element in app.html - Aurelia
app.html
<template> <require from="./styles.css"></require>
<todo-app></todo-app>
</template>
Comparison of Angular2 and Aurelia
Angular2 |
Aurelia |
I see the framework code explicitly in my application code because Angular2 uses explicit declarations via decorators |
I don’t see the framework polluting my application code because Aurelia uses conventions |
Hard to switch to another framework because my application has too much of framework code. |
Easy to switch to another framework because my application code is reusable JavaScript code |
Uses non-standard syntax like [(ngModel)], *ngFor, *ngIf, (event), {{ }} for interpolation etc., in the HTML markup that are not part of the standards. | Follows web standards like web components, ECMAScript 6 string interpolation etc. |
Angular2 has great support from 3rd party vendors like Telerik who are writing the Angular2 directives. | Aurelia has great support from Syncfusion(http://aureliajq.syncfusion.com/). Aurelia UX bridge project is a community run project that has created components for Telerik KendoUI and Materialize. |
Angular2 is more popular because it is from google and people hear about it everywhere be it a conference or other software companies’ web sites like Microsoft ASP.NET Core or MSDN or Channel 9 etc. | Aurelia is gaining momentum because its creators are presenting in popular conferences like NDC and sites like Channel 9 etc. Aurelia is also supported for .NET Core officially and talked about in MSDN magazine and on Channel 9. More Channel 9 content is coming soon. |
Angular2 has been in development for a very long time. Angular2 documentation has gotten much better compared to Angular 1 documentation. | Aurelia has a very aggressive release cycle and they have frequent releases. The Aurelia.io hub documentation has gotten much better, very detailed oriented, technical and useful for anyone who wants to learn the framework. |
Plugins are available for IntelliJ, VSCode and other popular editors out there. Plunkr supports Angular2 templates for quick online application development. | Plugins are available for IntelliJ, VSCode and other popular editors out there. Aurelia team built GistRun (https://gist.run/) using Aurelia itself that can run your gists and is very handy for online application development. Aurelia has the plunker resources (https://github.com/jdanyow/aurelia-plunker) created by core team member Jeremey Dayow for use as well. |
There are a lot of books out there (started using the early releases of Angular2 but are constantly updated) already for Angular2. | There are only 2 books available out there for Aurelia (both are still under development) now. There are more books and video trainings coming soon. |
There are many learning resources like video tutorials out there from Pluralsight, Wintellect, egghead etc. besides a lot of other tutorials on YouTube. There are so many enthusiasts who blog regularly on Angular. | There are so many enthusiasts who regularly blog about Aurelia besides Aurelia’s core team members. There aren’t that many learning resources out there but the ones that are available are really top quality resources. Rob Eisenberg’s official 3 part Aurelia Virtual Training videos (https://www.picatic.com/modern-javascript-and-aurelia) on Vimeo are awesome. |
It is a great move from the Angular2 team to use TypeScript, which is a typed superset of JavaScript instead of their proprietary Dart language. | Aurelia itself is written using ES6 & 7 and has great starter kits (aka their skeleton navigation projects) in both ES6 and TypeScript. Some of the new plugins are built using TypeScript. |
When it comes to hiring front end developers to work in Angular2 projects, you need to look for skills like TypeScript, understanding of module systems like Webpack or SystemJs, and give an in-depth training on Angular2 fundamentals because it has a steep learning curve. | When it comes to hiring front end developers to work in Aurelia projects, all you need to look for is skills like JavaScript (ES6 or TypeScript is a plus), understanding of module systems like Webpack or SystemJs or RequireJs and give some training on Aurelia fundamentals because it has a simple learning curve. |
Although you’ll find many front end developers who might have heard about Angular2, knowledge of Angular 1 is not required at all because the framework has changed so much from version 1. | You’ll not find that many front end developers who might have heard about Aurelia, which shouldn’t matter because the framework itself is about 1.5 years old. Since it is a conventions based framework, it should be very easy to train any front end developer on Aurelia. |
Conclusion
Both Angular2 and Aurelia are very modern JavaScript frameworks with very good open source community backing them up.
If I were to start a project today, I would pick a modern, modular and standards based framework like Aurelia. While others may have a different opinion which is perfectly fine, my suggestion to the readers of this blog post would be to pick a framework that works for you, your team and your company.
Happy Coding!
This comment has been removed by the author.
ReplyDeleteI am definitely enjoying your website. You definitely have some great insight and great stories.
ReplyDeleteData Science course in rajaji nagar | Data Science with Python course in chenni
Data Science course in electronic city | Data Science course in USA
Data science course in pune | Data science course in kalyan nagar
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeleteonline Python certification course | python training in OMR | python training course in chennai
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
ReplyDeletejava training in chennai | java training in electronic city
java training in marathahalli | java training in btm layout
Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
ReplyDeleteSoftware Testing Training in Chennai | Best Software Testing Institute
Authorized Dotnet Training in Chennai | Dotnet Training in Chennai
PHP Training in Chennai | Best PHP Training Institute |PHP syllabus
Advanced Android Training in Chennai | Best Android Training in Chennai
AngularJS Training in Chennai |Advanced SAS Training in Chennai | Best SAS Training in Chennai
Awesome Post. It shows your in-depth knowledge of the content. Thanks for Posting.
ReplyDeleteSAS Training in Chennai
SAS Course in Chennai
SAS Training Institutes in Chennai
SAS Institute in Chennai
Clinical SAS Training in Chennai
SAS Analytics Training in Chennai
SAS Training in Velachery
SAS Training in Tambaram
SAS Training in Adyar
I liked your blog.Thanks for your interest in sharing the information.keep updating.
ReplyDeleteDevops Training in Chennai | Devops Training Institute in Chennai
Really happy to seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
ReplyDeleteData science Course Training in Chennai |Best Data Science Training Institute in Chennai
RPA Course Training in Chennai |Best RPA Training Institute in Chennai
AWS Course Training in Chennai |Best AWS Training Institute in Chennai
Devops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai
Jika nilai kartu pemain lebih besar dari pada bandar, maka bandar akan membayar pemain sebesar jumlah yang dipasang oleh pemain.
ReplyDeleteasikqq
dewaqq
sumoqq
interqq
pionpoker
bandar ceme terbaik
hobiqq
paito warna
bocoran sgp
data hk
I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the data science training in pune Providers who helped me a lot to achieve my dreams comes true. Really worth trying instant approval blog commenting sites
ReplyDeleteHi,
ReplyDeleteGood job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in pune. Because python course in pune is one of the best that one can do while choosing the course.
Really interesting
ReplyDeletefreeinplanttrainingcourseforECEstudents
internship-in-chennai-for-bsc
inplant-training-for-automobile-engineering-students
freeinplanttrainingfor-ECEstudents-in-chennai
internship-for-cse-students-in-bsnl
application-for-industrial-training
Good
ReplyDeleteinterview-
questions/aptitude/permutation-and-
combination/how-many-groups-of-6-persons-can-be-
formed
tutorials/oracle/or
acle-delete
technology/chrom
e-flags-complete-guide-enhance-browsing-
experience/
interview-
questions/aptitude/time-and-work/a-alone-can-do-1-
4-of-the-work-in-2-days
interview-
questions/programming/recursion-and-
iteration/integer-a-40-b-35-c-20-d-10-comment-about-
the-output-of-the-following-two-statements
NICE...
ReplyDeletehow to hack flipkart payment
react native developer resume
group selector css
chemistry interview questions
sample complaint letter to bank for wrong transaction
javascript int max value
ReplyDeletepassage writing in fiserv
vijay invested rs.50,000 partly at 10% and partly at 15%. his total income after a year was rs.7000. how much did he invest at the rate of 10%?
residue on ignition
the simple interest earned on a certain amount is double the money
GOOD...
ReplyDeletehow to hack flipkart
tp link wifi password hack
power bi developer resume
android secret codes and hacks pdf
slideshow html code for website
javascript max integer
tell me about yourself
given signs signify something and on that basis
kumaran systems interview pattern
bangalore traffic essay
good post.
ReplyDeleteAcceptance is to offer what a lighted
A reduction of 20 in the price of salt
Power bi resumes
Qdxm:sfyn::uioz:?
If 10^0.3010 = 2, then find the value of log0.125 (125) ?
A dishonest dealer professes to sell his goods at cost price but still gets 20% profit by using a false weight. what weight does he substitute for a kilogram?
Oops concepts in c# pdf
Resume for bca freshers
Attempt by security transparent method 'webmatrix.webdata.preapplicationstartcode.start()' to access security critical method 'system.web.webpages.razor.webpagerazorhost.addglobalimport(system.string)' failed.
Node js foreach loop
Nice..
ReplyDeletehow to hack with crosh
javascript integer max
apply css to iframe content
given signs signify something and on that basis assume the given statement to be true
zeus learning aptitude paper for software testing
how to hack wifi hotspot on android
she most of her time tomusic
unexpected token o in json at position 1
ywy
javascript sort array of objects by key value
Excellent post..
ReplyDeletedenmark web hosting
inplant training in chennai
useful post..
ReplyDeletemexico web hosting
moldova web hosting
albania web hosting
andorra hosting
armenia web hosting
australia web hosting
This comment has been removed by the author.
ReplyDelete
ReplyDeleteVery useful post...
python training in chennai
internships in hyderabad for cse 2nd year students
online inplant training
internships for aeronautical engineering students
kaashiv infotech internship review
report of summer internship in c++
cse internships in hyderabad
python internship
internship for civil engineering students in chennai
robotics course in chennai
nice.!
ReplyDeletepoland web hosting
russian federation web hosting
slovakia web hosting
spain web hosting
suriname
syria web hosting
united kingdom
united kingdom shared web hosting
zambia web hosting
inplant training in chennai
Hi..
ReplyDeleteThanks for sharing such a useful article. From your shared information i can easily understand how to create a TodoMVC application using Angular2 and Aurelia . And also you provided framework comparison between two of these.
Nice information.....
ReplyDeleteIntern Ship In Chennai
Inplant Training In Chennai
Internship For CSE Students
Online Internships
Coronavirus Update
Internship For MBA Students
iot internship
Usefull information....
ReplyDeletecoronavirus update
inplant training in chennai
inplant training
inplant training in chennai for cse
inplant training in chennai for ece
inplant training in chennai for eee
inplant training in chennai for mechanical
internship in chennai
online internship
Exelent information.
ReplyDeleteCoronavirus Update
Intern Ship In Chennai
Inplant Training In Chennai
Internship For CSE Students
Online Internships
Internship For MBA Students
ITO Internship
nice blog, good article, it helps many students, Thanks for sharing the information.
ReplyDeleteSalesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
Amazing post!!! This post is very comprehensive and i learn more ideas. Thanks for your post, i like more updates from your blog.. keep update
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeleteAWS Online Training
Online AWS Certification Training
Thanks for your marvelous posting! I really enjoyed reading it. you're a great author. I will be sure to bookmark your blog and will come back very soon..God bless uou HDPE Pipe Fittings
ReplyDeleteThis post is so helpfull and informative.keep updating with more information...
ReplyDeleteBest AngularJS Classes in Mumbai
Angularjs Training in Ahmedabad
Angular Training in Kochi
Angular Training in Trivandrum
Angularjs Training in Kolkata
This post is so interactive and informative.keep update more information...
ReplyDeletehadoop training in tambaram
Big data training in chennai
This comment has been removed by the author.
ReplyDeleteRegardless of the security break detailed last year, you actually need to search for another VPN that can do precisely exact thing NordVPN does. Nord VPN Crack
ReplyDeleteConnectify Hotspot Pro break is the most recent highlighted application that used to settle the things as indicated by your longing this is most recent form that works! Thums Up Download Connectify Me Full Version
ReplyDelete