简体   繁体   English

AngularJS到Angular4到AngularJS

[英]Angularjs to angular4 to angularjs

I have an APP that I am progressively porting to angular 4. 我有一个正在逐步移植到angular 4的APP。

Right now, I have some component that are in Angular 4 other in AngularJS. 现在,我在AngularJS的Angular 4中有一些组件。 I face a problem when passing from angularjs -> angular4 -> angularjs. 我从angularjs-> angular4-> angularjs传递时遇到问题。 the first transition from JS to 4 work perfectly, but then, I am stuck with my Angular 4 component on the main screen. 从JS到4的第一个过渡效果很好,但是随后,我在主屏幕上陷入了Angular 4组件的困境。 he URL change, but the page don't redirect to the Angular JS component, my ng-outlet doesn't refresh anymore. URL更改了,但是页面没有重定向到Angular JS组件,我的ng-outlet不再刷新了。

The ROUTER is in angularJS. ROUTER在angularJS中。

The Angular 4 Component are dowgraded using : 使用以下命令对Angular 4组件进行降级:

import {
    Injectable,
    ModuleWithProviders,
    NgModule
} from '@angular/core';

import {
    APP_MODULE_NAME
} from '../../constants';

declare const angular: angular.IAngularStatic;
import {
    downgradeInjectable,
    downgradeComponent
} from '@angular/upgrade/static';


// Singleton Module
@NgModule()
@Injectable()
export class ComponentHelper {
    constructor() {}

    static forRoot(): ModuleWithProviders {
        return {
            ngModule: ComponentHelper
        }
    }

    public static DowngradeFactory(componentName: string, className: any): void {
        angular.module(APP_MODULE_NAME).factory(componentName, downgradeInjectable(className));
    }

    public static DowngradeDirective(componentName: string, className: any): void {
        angular.module(APP_MODULE_NAME).directive(componentName, downgradeComponent({
            component: className
        }))
    }
}

I am doing this in the router 我正在路由器中执行此操作

{
    path: '/pj/:project_id/ds/:datastore_id/list/ng4/all',
    component: 'downgradeNG4',
    name: 'DowngradeNG4'
}, {
    path: '/pj/:project_id/ds/:datastore_id/search/:search_id/list/all',
    name: 'NormalJS',
    component: 'normalJS'
},

at some point in AngularJS I do this So that I redirect to NG4 component. 在AngularJS中,我这样做是为了重定向到NG4组件。

const path = `pj/${self.projectID}/ds/${self.currentDatastoreID}/list/ng4/all`;
$location.path(path);

Now while in the angular 4 component, if I click on a UI MENU that is in angular JS, it doesn't redirect event if the path change in the browser change. 现在,在角度4组件中,如果我单击角度JS中的UI菜单,则如果浏览器中的路径更改,它也不会重定向事件。

Not all Component/Module are downgraded, should I downgrade everyservice and subcomponent? 并非所有组件/模块都降级了,我应该降级每个服务和子组件吗? Or only (like now) the component called directly from AngularJS router ? 还是仅(像现在一样)直接从AngularJS路由器调用的组件?

Should I downgrade them all? 我应该全部降级吗?

I've been into this process before ( immigrating from angluarjs to angular ). 我之前曾经参与过这个过程(从angluarjs迁移到angular)。 I strongly recommend you to just rewrite all your component in angular 6 again ( there is some basic changes from angular 4 to 6 too ) It will less time than this method. 我强烈建议您再次用角度6重写所有组件(从角度4到6也有一些基本变化),比这种方法要少一些时间。 you can keep your html and css with minimum changes. 您可以将html和css进行最小的更改。

anyway if you still insist in your way. 无论如何,如果您仍然坚持自己的方式。 just divide it into separate parts which can work by themselves. 只需将其分为可以独立工作的各个部分即可。 * You can run angularjs and angular at the same time in one page *您可以在一页中同时运行angularjs和angular

and if you need to pass data from angularjs to angular I would do it in another way like using localstorage. 如果您需要将数据从angularjs传递到angular,我可以采用另一种方式,例如使用localstorage。

anyway it's really hard o understand with your explanations where is the problem, even with errors in the console , angular debugging take time. 无论如何,通过您的解释很难理解问题出在哪里,即使控制台出现错误,角度调试也需要时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM