简体   繁体   English

Angular 2 Dart:在Dart中使用NgModule

[英]Angular 2 Dart: use of NgModule in dart

I am developing a modular web Angular 2 dart application, where modules are interchangeable and each carry its own responsibility/function. 我正在开发一个模块化的Web Angular 2 dart应用程序,其中的模块是可互换的,每个模块都有自己的职责/功能。 I started with the following link: 我从以下链接开始:

https://angular.io/docs/dart/latest/guide/ngmodule.html , but the documentation is not finished... I continued with the TypeScript reference, where i learned @NgModule https://angular.io/docs/dart/latest/guide/ngmodule.html ,但是文档还没有完成...我继续阅读TypeScript参考,在那里我学会了@NgModule

I tried implementing @NgModule but couldn't even find it in the dart packages source code, how can i accomplish grouping of Multiple Components, Directives, their services, and pipes in Dart? 我尝试实现@NgModule,但是甚至在dart包源代码中找不到它,如何在Dart中完成多个组件,指令,它们的服务和管道的分组? Is there anything like @NgModule as in TypeScript? 在TypeScript中是否有类似@NgModule的东西?

I tried bootstraping multiple App Root Components, which worked, but i don't believe it is a right solution to the problem. 我尝试自举多个App Root组件,这些都起作用,但是我认为这不是解决此问题的正确方法。 And if not how can i share data in between? 如果没有,我之间如何共享数据?

in my main.dart i have: 在我的main.dart中,我有:

    import 'package:angular2/platform/browser.dart';
    import 'package:test/app_component.dart';
    import 'package:test/app1_component.dart';

    main() {
       bootstrap(AppComponent);
       bootstrap(App1Component);
    }

Where AppComponent and App1Component are root app components; 其中AppComponent和App1Component是根应用程序组件; Would this be equivalent to @NgModule in https://angular.io/docs/ts/latest/guide/ngmodule.html 这是否等效于https://angular.io/docs/ts/latest/guide/ngmodule.html中的 @NgModule

Angular2 Dart doesn't have the concept of modules. Angular2 Dart没有模块的概念。 NgModule was introduced mainly to allow lazy loading of parts of the application. 引入NgModule主要是为了允许应用程序部分的延迟加载。 Since Dart allows lazy loading (called deferred loading in Dart) by default, there was no need to implement NgModule . 由于Dart默认情况下允许延迟加载(在Dart中称为延迟加载 ),因此无需实现NgModule

Here's an article about lazy loading in Angular2 Dart: https://medium.com/@matanlurey/lazy-loading-with-angular-dart-14f58004f988#.6ryctgg5q 这是有关Angular2 Dart中的延迟加载的文章: https ://medium.com/@matanlurey/lazy-loading-with-angular-dart-14f58004f988#.6ryctgg5q

There's also a repo that illustrates how you can lazily load specific routes: https://github.com/kulshekhar/angular-dart-routing-lazy-loading 还有一个仓库说明了如何懒加载特定的路由: https : //github.com/kulshekhar/angular-dart-routing-lazy-loading

Using this, you can use interchangeable components in places where you were using interchangeable modules 使用此功能,您可以在使用可互换模块的地方使用可互换组件。

AngularDart确实使用了模块https://angulardart.dev/glossary#M

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

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