何时在 Angular 2 中使用 @angular 标签? [英] When to use @angular tags in Angular 2?

查看:24
本文介绍了何时在 Angular 2 中使用 @angular 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 boot.ts 文件中使用下面的代码引导我的应用程序:

I was trying to bootstrap my application using code below in a boot.ts file:

import {bootstrap}    from 'angular2/platform/browser'
import {ROUTER_PROVIDERS} from 'angular2/router'

import {AppComponent} from './app.component'

bootstrap(AppComponent,[ROUTER_PROVIDERS]);

效果很好.

现在我想尝试添加 Google 地图,因此导入了 angular2-google-maps 包,创建了一个 map.component.ts 文件并将其添加到路由器映射中(在 app.component.ts 文件中定义).

Now I wanted to try and add Google Maps so imported angular2-google-maps package , created a map.component.ts file and added this to the router mapping (defined in the app.component.ts file).

对于上面的包,import {bootstrap} from '@angular/platform-b​​rowser-dynamic';用于 plunker 代码(作为入门代码提供).

For the above package, import {bootstrap} from '@angular/platform-browser-dynamic'; is used in the plunker code (provided as a starter code).

现在,如果我在我的 index.html 页面中添加一个 选择器,就会显示地图.

Now the map is displaying if I add a <map> selector in my index.html page.

我希望它遵循之前定义的路由.

I want it to follow the routing which was defined earlier.

引导也发生了两次(一次用于 AppComponent,一次用于 Map)

Bootstrapping is also happening twice (once for the AppComponent and once for the Map)

如何正确引导地图组件,以便仅对主应用程序进行引导?

How to bootstrap the map component properly so that bootstrapping happens only for the Main app?

还有 @angularangular2 包之间有什么区别以及何时使用它们?

Also what is the difference between @angular and angular2 packages and when to use them?

推荐答案

@angular 适用于 RC(候选发布)版本,angular2 适用于测试版.

@angular is for RC (release candidate) versions and angular2 for beta versions.

例如,在 RC 版本中,angular2/core 变为 @angular/core.您还可以注意到 SystemJS 配置有所不同,因为您没有捆绑 JS 文件.

In RC versions, for example, angular2/core becomes @angular/core. You can also notice that the SystemJS configuration is different since you don't have bundled JS files.

现在您需要将 Angular2 模块配置到 SystemJS 配置的 map 和 packages 块中.有关更多详细信息,请参阅此链接:

Now you need to configure Angular2 modules into map and packages blocks of your SystemJS configuration. See this link for more details:

这篇关于何时在 Angular 2 中使用 @angular 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆