I am working on an app written in Angular 2, and we have many views that are written in Angular 1 from another application that we would like to use in our Angular 2 app with some minor changes. Is this possible? I've looked into this a little bit and read some tutorials but they all seem based on upgrading an Angular 1 project to Angular 2, not using Angular 1 in an existing Angular 2 project. Would I need to rewrite my app.module.ts and my route file in Angular 1 in order to achieve this and if so are there any other file I would need to rewrite?
Yes, you can. Basic Angular Directives such as ng-click are not changed, but the behavior of Two-ways data binding is changed. But you can be able to migrate with some minor changes in you view.
Somehow, you will be face some amount of refactoring from your Angular 1 JavaScript to Angular2 TypeScript and for that you will need to rewrite some of your codes like routes when you migrate your app.
But there's a lot of references for migration. Check it out the following link.
https://www.codementor.io/angularjs/tutorial/migrating-from-angular-1-to-angular-2
Regards.
Related
I have read Angular's official document for upgrading from 1.x to version 5. But I unable to achieve ngUpgrade.
Can anybody help to resolve this issue or help me how to proceed?
Old Project is in AngularJS 1.6 and I am using ui-router for routing mechanism.
Below is the sample code for the of the controller,
heroController:
myApp.controller("heroController", ["$scope", function ($scope) {
// Controller Code
}]);
index.cshtml code:
<body ng-app="myApp">
<div ui-view></div>
</body>
I have a wrapper of MVC for existing application. Now I want to migrate to newer version of Angular(Version 5 and upcoming versions).
Since the existing application have a lot of controllers, directives, services factories, thus I want to first ngUpgrade thereafter I will start migrating component wise.
NOTE:
I am not using any build tools to bundle js files, I am using MVC's bundle.
Two ways you can do,
(i) Best way is to rewrite the application.
(ii)Or migrate each module wise. You can read on How to migrate from the following blog.
https://vsavkin.com/migrating-angular-1-applications-to-angular-2-in-5-simple-steps-40621800a25b
Faced the same request, from a client, some time ago. After searching the internet for a quick fix for this found this guide. It has multiple steps, takes it one at a time. It is a lengthy process, but at least each step is described:
https://angular-2-training-book.rangle.io/handout/migrate/
Hope it helps
P.S. ngUpgrade needs this first: replace the ng-app directive with angular.bootstrap.
AngularJs and Angular are diffrent, in the sense that all Angular is a complete rewrite of AngularJs.
In other word AngularJs are all version of Angular 1 While Angular is version 2 upword.
I am trying to migrate my angularjs(1.6) to angular 5. As of now I am focusing over migration of one page and want to go for both frameworks angular js and angular 5 running in same application.
I have gone through various links and found some approaches like going for incremental migration i.e. from angular js to angular 2 then angular 4 later angular 5 ; Modifying the scope syntaxes etc
My query is that should I modify the above scope related syntaxes in my current angular js application or I should create a new angular 2 /5 project and then move my js application code to newly created angular 2/5 app.My application is huge one. Also, I want to use ngUpgrade. Not sure where to use. Pls verify the approach and help in this migration
'create a new angular 2 /5 project and then move your js application code to newly created angular 2/5 app' is better in my opinion
there are some huge architecture differences between Angularjs and angular2+.
angular.js is a classic MV* architecture framework, you may write code in controllers, services, splitting these files into different folders like a MVC structure.
while angular2+ is a component based framework.you can write app in component based pattern.just like react or vue .although you still can write it as a MVC structure.but remember why you want to refactor your project.
I've been working on a personal project for many years. This isn't for work and there is no money to be made. So I take my time doing the development on the project, and that means I'm still using AngularJS as my front-end UI library.
AngularJS is my "component" library where all the directives, components and services are there to "bootstrap" existing HTML from the web server. The back-end is handled with CakePHP which renders all the HTML.
There is no massive single-page app and there is no AngularJS routing. I load my UI library on each page request, and that's how I'd like to keep doing it.
I spend my day job working with Angular 5. I'm very good at it and I'm the go to guy when other developers have Angular questions.
Despite these skills I've been unable to figure out a migration path for my UI library from AngularJS to the latest Angular. Angular 2+ has been out for a couple of years and I'm still stuck with AngularJS.
Here is an example of my problem:
Take a look at the Material Angular project built with Angular 4. It's basically the same kind of library as my own UI library. It contains a collection of directives and components that you can use.
If you have a web server that responds with existing HTML and you want to use Material Angular as your UI library, then you can't. Let's take the autocomplete component as an example.
The documentation explains how to use autocomplete:
https://material.angular.io/components/autocomplete/overview
There is also a working example of the component:
https://stackblitz.com/angular/ggmpnaqqqxk
In the documentation it shows that you can use the component like this:
<mat-autocomplete>
<mat-option *ngFor="let option of options" [value]="option">
{{ option }}
</mat-option>
</mat-autocomplete>
But when you look at the working example you see the problem that I have. In their example, they have to bootstrap an entire Angular application container that is used to inject the Application HTML which has the autocomplete example.
They can't just use the <mat-autocomplete> component in an existing HTML page.
Now let's take a look at the exact same component done in AngularJS for the old Material Angular project.
It too has a component for autocomplete named <md-autocomplete> and the old version has basically the same features.
There is even a working example:
https://codepen.io/anon/pen/goLrpJ
It too bootstraps an AngularJS application, but it leaves the existing HTML intact. That allows you to use <md-autocomplete> directly in your existing HTML.
How do I create an Angular 5 application that can be used as a component library with existing HTML?
Angular Elements are supposed to address this problem in near future. As explained in detail in this write-up, they are able to provide self-bootstrapping, standalone custom elements.
Currently the issues remain unsolved that restrict the use of attributes and projected content on root component, this seriously narrows down the use of Angular components as custom elements in real-world scenarios.
I am new to angular 2 and created a simple page in angular 2.
Now I want to use server side rendering for my page.I read about angular universal and decided to use it.
But few doubts before starting.
Do we need webpack to implement it.Because i have not used webpack in my application(used basic Quickstart to givven here https://angular.io/guide/quickstart)
I tried to use universal but getting some errors so want to confirm.
Please let me know if i can use angular universal without webpack.
I have an existing angular / phonegap app that I'm trying to port to a windows metro app for win8. I've replaced my jQuery with a metro specific version and I've wrapped each angular module in the MSAp.execUnsafeLocalFunction method and I'm getting the application to sort of compile.
What is happening is that the page is built using angular ui router, so I'm able to see the dynamically created page, with angular ui router combining the 3 or 4 partials based on the route. However, when Angular starts to go through ng-bind, ng-repeat, etc... I'm getting the following error, "JavaScript runtime error: Unable to add dynamic content. A script attempted to inject dynamic content, or elements previously modified dynamically, the might be unsafe..."
I've looked to see how others have overcome this issue, but I have not found anything that works. I'm worried that what I'm doing is going to have force me to rewrite the application using the WinJS library.
Does anyone have any resources or experience that can help me with this?
What works for me is adding the ng-csp directive to the HTML tag. This disables some of the dynamic content stuff of Angular. I didn't even wrap anything in exeUnsafeLocaFunction. I'm not sure if it will work on Angular UI Router though...
More on the ng-csp directive here...