簡體   English   中英

降級的Angular2組件未在angular 1內渲染

[英]Downgraded Angular2 component not rendered inside angular 1

我們有一種獨特的情況,我們使用打字稿,將ng1和2混合使用,但不使用任何模塊加載器。 我能夠同時引導ng 1和ng2,但是我無法從降級的angular 2組件得到任何響應,我在代碼中放置了一個斷點,並看到代碼可以運行,但是該組件什么也沒顯示。

我沒有任何錯誤,沒有在編譯階段,也沒有在運行時。

這是代碼:

myapp.js - Angular 1應用程序定義,es2015

(function() {
    'use strict';
    angular.module('myApp', []);
})();

myapp.ng2.ts -angular 2應用程序定義,打字稿

namespace MyApp {

let NgModule = ng.core.NgModule;
let BrowserModule = ng.platformBrowser.BrowserModule;
let UpgradeAdapter = ng.upgrade.UpgradeAdapter;

@NgModule({
   imports: [BrowserModule]
})

export class MyAppNg2 {}

export const upgradeAdapter = new UpgradeAdapter(MyAppNg2);

$(document).ready(function() {
    upgradeAdapter.bootstrap(document.body, ['MyApp'], {strictDi: false});
});

}

fullDetails.component.ts-角度2,打字稿

namespace MyApp.Components.Misc {

    let Component = ng.core.Component;

    @Component({
        selector: 'full-details-header',
        template: `This is ng2 component`
    })

    export class FullDetailsHeaderComponent {
    }

}

bootstrap.js -angular1,es2015

angular.module('myApp').component('fullDetailsHeader', MyApp.upgradeAdapter.downgradeNg2Component(MyApp.Components.Misc.FullDetailsHeaderComponent));

很難說,因為我認為這是針對Angular的Beta版,我還沒有完成升級過程,但是對於Angular 2+版,您還需要在entryComponents數組中聲明要降級的entryComponents您的主要模塊:

@NgModule({
   imports: [BrowserModule],
   entryComponents: [FullDetailsHeaderComponent]
})

假設這是針對Angular beta的,並且您沒有太多工作,那么我將廢棄它並使用最新版本的Angular並遵循官方指南 在我看到的用於在Beta版本和Angular版本之間創建ng1 / ng2混合應用程序的示例中,有太多不同之處,我認為不值得解決與Beta升級過程相關的問題。

這仍然是一個很難找到問題和示例的領域,因此,如果您有與Angular 2+版本升級過程有關的問題,請提出一個新問題並ping通我。

首先,這是一個plunkr ,其中顯示了降級Angular組件並在AngularJS中使用它的工作示例。 這也將在降級過程中使用多次包含,僅適用於4.0.0+版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM