Difference between Angularjs and angular [duplicate] - angularjs

This question already has answers here:
AngularJS vs Angular [closed]
(7 answers)
Closed 5 years ago.
What is the Difference between Angularjs and angular(eg. cli and versions)?
I want to work Angular but I don't know differences for select one of them. I googled but don't explicitly mention differences between them.

AngularJS is the first version of Angular.
AngularCLI is a tool used to generate angular components, They are not comparable.
What you might mean, is what is the difference between Angular and AngularJS.
The answer to this question is that AngularJS is the first version of Angular.
It works with javascript and it is still getting supported but it is not compatible with Angular.
I'd suggest you start with Angular (Can also be called Angular2 or Angular4).
It is very confusing, but to sum it up, AngularJS is an old version.
Angular is the newer version and since everyone is migrating to Angular.
I would suggest you learn Angular instead of AngularJS.

AngularJS typically refers to Angular 1, or the original angular which has some differences between Angular 2+.
Some of the logic and keywords are different from 1 to 2+.
Angular CLI is a command-line interface for the current version of Angular, Angular 4.
Angular CLI provides a generator/framework for a new project using Angular.
The current documentation on angular.io is in Angular CLI.

Angular CLI stands for Angular Command Line Interface. As the name says, it is a command line tool for creating angular apps. It is recommended to use angular cli for creating angular apps as you don't need to spend time installing and configuring all the required dependencies and wiring everything together.
angular-cli provides you with boilerplates and therefore, saves your time.
whereas AngularJS is a client side framework of JavaScript which is based on MVC Architecture and provides a Single-page application solution for dynamic websites.
If you want choose any technology then following points should be considered:
Code Re-usability
Maintenance of the existing code
Testing of the code
Modularity and Scalibility for Team Development

Related

AngularJS - Defining Components using .components() vs using TypeScript [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Months ago, I decided to study Angular. When I was doing some advance and create some app using it, I realize that Angular 2 is in Developer preview, so it's a matter of time before it's going to be released. Because Angular 2 is not going to be compatible with Angular 1, and there are a lot of changes, the question is, is it better to continue developing with Angular 1.x or start developing Angular 2?
It's a fact that we don't always have to be using the latest version nor the newest language on the market, but in this case, the app is still small so I could change without problems.
Let me preface by saying, I'm assuming you and everyone who will be reading this is already comfortably with Angular 1 (now referred to as AngularJS, as opposed to simply Angular for the newer versions). That being said, let's get into some of the additions and key differences in Angular 2+.
They added an angular cli.
You can start a new project by running ng new [app name].
You can serve your project by running ng serve
learn more here: https://github.com/angular/angular-cli
Your angular code is written in ES6 Typescript and it compiles at runtime to Javascript in the browser.
To get a full grasp on this I recommend checking out some the resource list I have at the bottom of my answer.
Project Structure
In a basic structure, you will have a app/ts folder where you'll be doing most your work and a app/js You'll find in the app/js folder files with a .js.map extension. They "map" your ".ts" files to your browser for debugging as your browser cannot read native typescript.
Update: It's out of beta. The project structure changed a bit, in most cases and if you're using the angular cli, you'll be working in the
src/app/ folder. In a starter project, you'll have the following.
app.component.css
app.component.html
app.component.spec.ts
app.component.ts
app.module.ts
index.ts
app.component.css: CSS file you should use specific to the component.html
app.component.html: A view (variable declared in the app.component.js)
app.component.spec.ts: used for testing app.component.ts
app.component.ts: Your code that binds to app.component.html
app.module.ts: This it what kicks off your app and where you define all plugins, components, services, etc. This is the equivalent of the app.js in Angular 1
index.ts used to define or export project files
Additional information:
Pro tip: you can run ng generate [option] [name] to generate new services, components, pipes, etc.
Also the tsconfig.json file is important as it defines TS compile rules for your project.
If you're thinking I have to learn a whole new language?... Uh... kinda, TypeScript is a superset of JavaScript. Don't be intimidated; it's there to make your development easier. I felt like I had a good grasp on it after just a few hours playing with it, and had it all down after 3 days.
You bind to your HTML similarly like how you would if in an Angular 1 directive. So variable like $scope and $rootScope have been deprecated.
This one you may have been implied. Angular 2 is still a MV* but you'll be using 'components' as a way to bind code to your templates, for instance, take the following
import { Component } from '#angular/core';
#Component({
selector:'my-app',
template: '<h1> Hello World! </h1>'
})
export class AppComponent {}
Here think of the import statement as your dependency injection in a v1 controller. You use import to import your packages, where the import {Component} says you'll be making a component you'd like to bind to your HTML.
Notice the #Component decorator you have a selector and template. Here think of the selector as your $scope that you use like you use v1 directives where the name of the selector is what you use to bind to your HTML like so
<my-app> </my-app>
Where <my-app> is the name of your custom tag you'll use that will act as a placeholder for what's declared in your template. i.e.) <h1> Hello World! </h1>. Whereas this would look like the following in v1:
HTML
<h1>{{hello}}</h1>
JS
$scope.hello = "Hello World!"
Also can you add something between these tags to generate a loading message, like this:
<my-app> Loading... </my-app>
Then it will display "Loading..." as the loading message.
Note that what's declared in template is the path or the raw HTML you'll be using in your HTML in your selector tag.
A fuller implementation of Angular 1 would look more like this:
HTML
<h1 ng-controller="myCtrl">{{hello}}</h1>
In v1 this would look something like
JS
angular.module('controller', [])
.controller('myCtrl', function( $scope) {
$scope.hello = "Hello World!"
})
This is what I really like about v2. I found directive was a steep learning curve for me in v1 and even when I had them figured out I often had the CSS render not how I intended. I find this is way simpler.
V2 allows for easier scalability of your app since you can break up your app up easier than you could in v1. I like this approach as you can have all your working parts in one file as opposed to having several in angular v1.
What about converting your project from v1 to v2?
From what I've heard from the development team if you'd like to update your v1 project to v2 you'll just be going through and deleting deprecated blobs and replace your $scopes with selectors. I found this video helpful. It's with some of the Ionic team that are working side by side with the angular team as v2 has a stronger focus on mobile https://youtu.be/OZg4M_nWuIk
UPDATE: I updated by adding examples as official implementations of Angular 2 have surfaced.
UPDATE 2: This still seems to be a popular question so I just thought I'd some resource I found very helpful when I started working with angular 2.
#Helpful Resources:
For more on ES6, I recommend checking out The New Boston's ECMAScript 6 / ES6 New Features Tutorials - YouTube Playlist
To write Typescript functions and see how they compile to Javascript check out the Typescript language Playground
To see a function by function breakdown of what the Angular 1 equivalence is in Angular 2 see the Angular.io - Cookbook -A1 A2 Quick Reference
It might help you to understand the comparison of Angular 1 vs Angular 2.
The Angular 2 proved to have lots of benefits over Angular 1:
It is entirely component based.
Better change detection
Ahead of Time compilation (AOT) improves rendering speed.
TypeScript is primarily used for developing Angular 2 applications.
Angular 2 has better performance over Angular 1.
Angular 2 has a more powerful templating system than Angular 1.
Angular 2 has simpler APIs, lazy loading, easier debugging.
Angular 2 is much more testable than Angular 1.
Angular 2 provides nested components.
Angular 2 provides a way to execute more than two systems together.
And So On...
Angular 2 and Angular 1 is basically a different framework with the same name.
angular 2 is more ready for the current state of web standards and the future state of the web ( ES6\7, immutiablity, components, shadow DOM, service workers, mobile compatibilty, modules, typescript and so on and so on... )
angular 2 killed many main features in angular 1 like - controllers, $scope, directives (replaced with #component annotations), the module definition, and much more, even simple things like ng-repeat has not left the same as it was.
any way, change is good, angular 1.x had it flaws, and angular 2 is more ready for the future web requirements.
to sum things up - i do not recommend you to start an angular 1.x project now - this is probably the worst time to do so as you will have to migrate later to angular 2, i you set youre mind about angular than choose angular 2, google has already launched a project with angular 2, and by the time you finish the project angular 2 should already be in the spotlight.
if you want something stabler, you can think about react\elm and flux and redux as JS frameworks.
angular 2 is going to be awesome, that's for no doubt.
No framework is perfect. You can read about flaws in Angular 1 here and here. But that doesn't mean it is bad. The question is what problem are you solving. If you want to roll out a simple app quickly, which is lightweight, with limited data binding usage then go ahead with Angular 1. Angular 1 was built 6 years back to solve rapid prototyping which it does pretty well. Even if your use case is complex still you can use Angular 1 but then you should be aware of nuances and best practices around building a complex web app. If you are developing an app for learning purpose I would suggest to move to Angular 2 as that is where the future of Angular is.
The one stand-out feature in Angular v2 and also in ReactJs is that they both have embraced the new Web-Components architecture of development. What this means is that we can now create independent Web-Components and plug-and-play them to any website in the world that has the same technology stack of the this Web-Component. Cool! yeah very cool. :)
The other most prominent change in Angular v2 is that it's primary development language is none other than TypeScript. Although TypeScript belongs to Microsoft, and it is a superset of JavaScript of 2015 (or ECMAScript6/ES6), but it has some features that are very promising. I would recommend the readers to checkout TypeScript in a bit detail (which is fun of-course) after reading this tutorial.
Here I would say that the guys trying to interrelate Angular v1 and Angular v2 further confuse the readers, and in my humble opinion, Angular v1 and Angular v2 should be treated as two different frameworks. In Angular v2, we have Web-Components' concept of developing web applications, while in Angular v1 we have to play with Controllers, and (sadly or luckily) no controllers are present in Angular v2.
One thing to notice is angular2 is using typescript.
I did angular1 with cordova in my intern and now i am doing a angular 2. I think angular2 will be the trend as it more structured in my opinion but the cons is that there are few resources to refer when you have problem or difficulties. angular 1.x has tons of personalized directives that can be super easy to use.
Hope it helps.
Angular 2 is much better than 1, at least in what it offers: support for web components, using typescript, performance and overall simplicity of the interface, was the reason I decided to start a project using angular 2. However, from the get go, I realized there are issues in angular 2 (e.g. routing with apache) for which very little or no documentation is available, so the documentation and community of angular 2 is the biggest pitfall for angular 2, as it isn't developed enough.
I would say, if you need to raise a site quickly for a short deadline use the well known angular 1, if you're in a longer project, and can afford the time to investigate new issues (that you might be the first to encounter, which could be a bonus if you think of the contribution, you might give to the angular 2 community) than go with angular 2.

Upgrade AngularJS to Angular 6 in Cordova App

I have a Cordova app built using Angular 1 i.e. Angular JS. How I can upgrade the app yo latest angular version.
Will it require complete code re-write to TypeScript (TS)??
TypeScript is not a requirement for writing Angular 2+. However, Angular 2-7 does not have much in common with AngularJS as it doesn't have the same architecture or components. For example, from what i've read about it, AngularJS used a MVC model, Angular2+ does not.
So to answer your question, you will indeed need to rewrite most of your application. Going from Angular 2 to 7 is much easier as not much has changed.

Can I use Angular1 plugin in Angular2 application?

I am very new to Angular 2 and would like to know if Angular 1 plugins can be used in Angular 2. I have used ng-knob in ionic 1 app. Some suggested to use jQuery knob instead but I really want to use ng-knob as it has many more options.
Is it possible to use ng-knob in angular 2? Even if there is a harder way I would not hesitate to try it but I really wan't to use ng-knob.
Any help with sample code is greatly appreciated.
As Angular2 framework is different from Angular1 framework, I'm afraid to say that you can't use Angular1 plugin(s) for Angular2.
Angular2 is a new framework and recently became stable. So, if you are looking for Angular2 plugin(s), its very hard to find them(as of now) as community is still developing Angular2 plugin(s).
Check out the Upgrading with The Upgrade Adapter section in angular.io - point 2 and other sections till 8.
https://angular.io/docs/ts/latest/guide/upgrade.html
Use angular.umd.js file instead of angular.dev.js or angular.js for 2.x. It supports both angular1 application and angular2 application to run side by side. This way you can use 1.x plugin with angular 1.x application and still run angular 2.x application side by side. You can use Zone.js to merge two way binding between angular 1.x application and 2.x application.
But this can be complex and if you are not comfortable with advanced hacks, you should take the answer of using 1.x plugins in 2.x versions. Unless you are ready to port your 1.x plugin to 2.x plugin yourself.
Zone.js intro - https://www.youtube.com/watch?v=V9Bbp6Hh2YE Good resource from Misko.

How to use angular 1.3.4 and angular 2 together [duplicate]

This question already has an answer here:
Running Angular and AngularJS frameworks side by side
(1 answer)
Closed 3 years ago.
I have already an application which is build on angular 1.3.4 and I want to change it to angular 2 but module wise.
lets say I've 5 modules on my page I want to migrate one module to angular 2 and other should work as it is like before with 1.3 so slowly slowly I can convert but till that it should not stop working.
I include both angular 2 and angular 1.3.4 libraries and it saying angular is not defined in console
Please read this blog:
http://angularjs.blogspot.nl/2015/08/angular-1-and-angular-2-coexistence.html
It explains how to run it together and how to finally upgrade to Angular 2.
The important thing of this link is:
For this to work, four things need to interoperate between Angular 1
and Angular 2:
Dependency injection
Component nesting Transclusion
Change detection
To make all this possible, we're building a library
named ng-upgrade. You'll include ng-upgrade and Angular 2 in your
existing Angular 1 app, and you'll be able to mix and match at will.
So you need ng-upgrade. See more information about that here: https://angular.io/docs/ts/latest/guide/upgrade.html

AngularJS vs Angular [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Months ago, I decided to study Angular. When I was doing some advance and create some app using it, I realize that Angular 2 is in Developer preview, so it's a matter of time before it's going to be released. Because Angular 2 is not going to be compatible with Angular 1, and there are a lot of changes, the question is, is it better to continue developing with Angular 1.x or start developing Angular 2?
It's a fact that we don't always have to be using the latest version nor the newest language on the market, but in this case, the app is still small so I could change without problems.
Let me preface by saying, I'm assuming you and everyone who will be reading this is already comfortably with Angular 1 (now referred to as AngularJS, as opposed to simply Angular for the newer versions). That being said, let's get into some of the additions and key differences in Angular 2+.
They added an angular cli.
You can start a new project by running ng new [app name].
You can serve your project by running ng serve
learn more here: https://github.com/angular/angular-cli
Your angular code is written in ES6 Typescript and it compiles at runtime to Javascript in the browser.
To get a full grasp on this I recommend checking out some the resource list I have at the bottom of my answer.
Project Structure
In a basic structure, you will have a app/ts folder where you'll be doing most your work and a app/js You'll find in the app/js folder files with a .js.map extension. They "map" your ".ts" files to your browser for debugging as your browser cannot read native typescript.
Update: It's out of beta. The project structure changed a bit, in most cases and if you're using the angular cli, you'll be working in the
src/app/ folder. In a starter project, you'll have the following.
app.component.css
app.component.html
app.component.spec.ts
app.component.ts
app.module.ts
index.ts
app.component.css: CSS file you should use specific to the component.html
app.component.html: A view (variable declared in the app.component.js)
app.component.spec.ts: used for testing app.component.ts
app.component.ts: Your code that binds to app.component.html
app.module.ts: This it what kicks off your app and where you define all plugins, components, services, etc. This is the equivalent of the app.js in Angular 1
index.ts used to define or export project files
Additional information:
Pro tip: you can run ng generate [option] [name] to generate new services, components, pipes, etc.
Also the tsconfig.json file is important as it defines TS compile rules for your project.
If you're thinking I have to learn a whole new language?... Uh... kinda, TypeScript is a superset of JavaScript. Don't be intimidated; it's there to make your development easier. I felt like I had a good grasp on it after just a few hours playing with it, and had it all down after 3 days.
You bind to your HTML similarly like how you would if in an Angular 1 directive. So variable like $scope and $rootScope have been deprecated.
This one you may have been implied. Angular 2 is still a MV* but you'll be using 'components' as a way to bind code to your templates, for instance, take the following
import { Component } from '#angular/core';
#Component({
selector:'my-app',
template: '<h1> Hello World! </h1>'
})
export class AppComponent {}
Here think of the import statement as your dependency injection in a v1 controller. You use import to import your packages, where the import {Component} says you'll be making a component you'd like to bind to your HTML.
Notice the #Component decorator you have a selector and template. Here think of the selector as your $scope that you use like you use v1 directives where the name of the selector is what you use to bind to your HTML like so
<my-app> </my-app>
Where <my-app> is the name of your custom tag you'll use that will act as a placeholder for what's declared in your template. i.e.) <h1> Hello World! </h1>. Whereas this would look like the following in v1:
HTML
<h1>{{hello}}</h1>
JS
$scope.hello = "Hello World!"
Also can you add something between these tags to generate a loading message, like this:
<my-app> Loading... </my-app>
Then it will display "Loading..." as the loading message.
Note that what's declared in template is the path or the raw HTML you'll be using in your HTML in your selector tag.
A fuller implementation of Angular 1 would look more like this:
HTML
<h1 ng-controller="myCtrl">{{hello}}</h1>
In v1 this would look something like
JS
angular.module('controller', [])
.controller('myCtrl', function( $scope) {
$scope.hello = "Hello World!"
})
This is what I really like about v2. I found directive was a steep learning curve for me in v1 and even when I had them figured out I often had the CSS render not how I intended. I find this is way simpler.
V2 allows for easier scalability of your app since you can break up your app up easier than you could in v1. I like this approach as you can have all your working parts in one file as opposed to having several in angular v1.
What about converting your project from v1 to v2?
From what I've heard from the development team if you'd like to update your v1 project to v2 you'll just be going through and deleting deprecated blobs and replace your $scopes with selectors. I found this video helpful. It's with some of the Ionic team that are working side by side with the angular team as v2 has a stronger focus on mobile https://youtu.be/OZg4M_nWuIk
UPDATE: I updated by adding examples as official implementations of Angular 2 have surfaced.
UPDATE 2: This still seems to be a popular question so I just thought I'd some resource I found very helpful when I started working with angular 2.
#Helpful Resources:
For more on ES6, I recommend checking out The New Boston's ECMAScript 6 / ES6 New Features Tutorials - YouTube Playlist
To write Typescript functions and see how they compile to Javascript check out the Typescript language Playground
To see a function by function breakdown of what the Angular 1 equivalence is in Angular 2 see the Angular.io - Cookbook -A1 A2 Quick Reference
It might help you to understand the comparison of Angular 1 vs Angular 2.
The Angular 2 proved to have lots of benefits over Angular 1:
It is entirely component based.
Better change detection
Ahead of Time compilation (AOT) improves rendering speed.
TypeScript is primarily used for developing Angular 2 applications.
Angular 2 has better performance over Angular 1.
Angular 2 has a more powerful templating system than Angular 1.
Angular 2 has simpler APIs, lazy loading, easier debugging.
Angular 2 is much more testable than Angular 1.
Angular 2 provides nested components.
Angular 2 provides a way to execute more than two systems together.
And So On...
Angular 2 and Angular 1 is basically a different framework with the same name.
angular 2 is more ready for the current state of web standards and the future state of the web ( ES6\7, immutiablity, components, shadow DOM, service workers, mobile compatibilty, modules, typescript and so on and so on... )
angular 2 killed many main features in angular 1 like - controllers, $scope, directives (replaced with #component annotations), the module definition, and much more, even simple things like ng-repeat has not left the same as it was.
any way, change is good, angular 1.x had it flaws, and angular 2 is more ready for the future web requirements.
to sum things up - i do not recommend you to start an angular 1.x project now - this is probably the worst time to do so as you will have to migrate later to angular 2, i you set youre mind about angular than choose angular 2, google has already launched a project with angular 2, and by the time you finish the project angular 2 should already be in the spotlight.
if you want something stabler, you can think about react\elm and flux and redux as JS frameworks.
angular 2 is going to be awesome, that's for no doubt.
No framework is perfect. You can read about flaws in Angular 1 here and here. But that doesn't mean it is bad. The question is what problem are you solving. If you want to roll out a simple app quickly, which is lightweight, with limited data binding usage then go ahead with Angular 1. Angular 1 was built 6 years back to solve rapid prototyping which it does pretty well. Even if your use case is complex still you can use Angular 1 but then you should be aware of nuances and best practices around building a complex web app. If you are developing an app for learning purpose I would suggest to move to Angular 2 as that is where the future of Angular is.
The one stand-out feature in Angular v2 and also in ReactJs is that they both have embraced the new Web-Components architecture of development. What this means is that we can now create independent Web-Components and plug-and-play them to any website in the world that has the same technology stack of the this Web-Component. Cool! yeah very cool. :)
The other most prominent change in Angular v2 is that it's primary development language is none other than TypeScript. Although TypeScript belongs to Microsoft, and it is a superset of JavaScript of 2015 (or ECMAScript6/ES6), but it has some features that are very promising. I would recommend the readers to checkout TypeScript in a bit detail (which is fun of-course) after reading this tutorial.
Here I would say that the guys trying to interrelate Angular v1 and Angular v2 further confuse the readers, and in my humble opinion, Angular v1 and Angular v2 should be treated as two different frameworks. In Angular v2, we have Web-Components' concept of developing web applications, while in Angular v1 we have to play with Controllers, and (sadly or luckily) no controllers are present in Angular v2.
One thing to notice is angular2 is using typescript.
I did angular1 with cordova in my intern and now i am doing a angular 2. I think angular2 will be the trend as it more structured in my opinion but the cons is that there are few resources to refer when you have problem or difficulties. angular 1.x has tons of personalized directives that can be super easy to use.
Hope it helps.
Angular 2 is much better than 1, at least in what it offers: support for web components, using typescript, performance and overall simplicity of the interface, was the reason I decided to start a project using angular 2. However, from the get go, I realized there are issues in angular 2 (e.g. routing with apache) for which very little or no documentation is available, so the documentation and community of angular 2 is the biggest pitfall for angular 2, as it isn't developed enough.
I would say, if you need to raise a site quickly for a short deadline use the well known angular 1, if you're in a longer project, and can afford the time to investigate new issues (that you might be the first to encounter, which could be a bonus if you think of the contribution, you might give to the angular 2 community) than go with angular 2.

Resources