【问题标题】:Angular Dart 2.0 with multiple components具有多个组件的 Angular Dart 2.0
【发布时间】:2015-09-30 18:42:10
【问题描述】:

我在 Angular Dart 2.0 中有三个组件,它们是菜单、公司、地址。这是引导它的最佳方法。在单个 main.dart 文件中或使用将每个 component.dart 文件导入主文件和每一个引导程序。我的代码如下,请帮助 菜单.dart

@Component(
    selector: 'menu'
)

@View(
    templateUrl: 'lib/menu.html'
)
class Menu{

}

公司.dart

import 'package:angular2/angular2.dart';
@Component(
    selector: 'company'
)

@View(
    templateUrl: 'lib/company.html'
)

class Company{

}

如何定义主函数

import 'package:angular2/angular2.dart';
import 'package:angular2/src/reflection/reflection.dart' show reflector;
import 'package:angular2/src/reflection/reflection_capabilities.dart'
show ReflectionCapabilities;

import 'lib/menu.dart';
import 'lib/company.dart';
import 'lib/address.dart';
main() {
  reflector.reflectionCapabilities = new ReflectionCapabilities();
  bootstrap(Menu);
  bootstrap(Company);
  bootstrap(Address);

}

这是正确的方法吗

【问题讨论】:

    标签: dart angular-dart


    【解决方案1】:

    bootstrap() 的第一个参数是聚合物应用程序的根组件。您可能不会在您的页面中创建 3 个独立的 Angular 应用程序。

    创建一个额外的应用程序组件并将其传递给引导程序

    bootstrap(Application);
    

    如果您将所有代码添加到一个文件中或将其拆分为每个组件的文件只是一种偏好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 2014-11-28
      • 2016-11-18
      • 2013-07-16
      • 2015-11-14
      • 2015-09-12
      • 1970-01-01
      相关资源
      最近更新 更多