何时在Angular 2中使用@angular标签? [英] When to use @angular tags in Angular 2?
问题描述
我试图用下面的代码在 boot.ts
文件中引导我的应用程序:
进口从 ./app {引导}从 'angular2 /平台/浏览器'
进口{ROUTER_PROVIDERS}从 'angular2 /路由器'
进口{AppComponent} .component'
bootstrap(AppComponent,[ROUTER_PROVIDERS]);
效果很好。
现在我想尝试添加Google Maps,导入 angular2-google-maps
包,创建了一个 map.component.ts
文件,并将其添加到路由器映射中(在 app.component.ts
文件中定义) / p>
对于上面的包,从'@ angular / platform-browser-dynamic'导入{bootstrap};
为在 plunker代码(作为起始代码提供)使用。
现在,如果我在 index.html中添加
< map>
选择器,地图就会显示
我希望它遵循之前定义的路由。
Bootstrapping也发生了两次(一次为 AppComponent
,一次为 Map
)
如何正确引导地图组件,以便引导只发生在主应用程序中?
还有什么区别 @angular
和 angular2
软件包以及何时使用它们?
@angular
用于RC(候选版本)版本和 angular2
例如,在RC版本中, angular2 / core
变为 @ beta版本。角/芯
。您还可以注意到,因为您没有捆绑的JS文件,所以SystemJS配置不同。
现在您需要将Angular2模块配置为SystemJS的地图和包模块组态。详情请参阅此链接:
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]);
It worked fine.
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).
For the above package, import {bootstrap} from '@angular/platform-browser-dynamic';
is used in the plunker code (provided as a starter code).
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.
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?
Also what is the difference between @angular
and angular2
packages and when to use them?
@angular
is for RC (release candidate) versions and angular2
for beta versions.
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.
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屋!