2017-04-11 102 views
-1

我對angular1不太熟悉,但對angular2不熟悉。所以面臨問題要了解angular2代碼。所以引導我瞭解一下angular2代碼。角度2引導代碼不明確

<div>Bootstrapping in Angular 1 using ng-app,</div> <div> 

angular.element(document).ready(function() { 
    angular.bootstrap(document, ['userApp']); 
}); 


<div>Bootstrapping in Angular 2,</div> 

import { bootstrap } from 'angular2/platform/browser'; 
import { UsersComponent } from './product.component'; 

bootstrap(UserComponent); 

請告訴我angular2引導代碼的含義。

+0

您使用預發行版本O fAngular 2.0.0。嘗試https://github.com/angular/angular –

回答

0

步驟1: - AppComponent.ts

第一步描述有關組件可以如何與DOM

結合可變
import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: `<h1>Hello {{name}}</h1>` 
}) 
export class AppComponent { name = 'Angular'; } 

步驟2:

二步驟將定義你的模塊,Angular2是用模塊構造的larity這意味着應用程序進行了構建模塊

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent } from './app.component'; 

@NgModule({ 
    imports:  [ BrowserModule ], 
    declarations: [ AppComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

第3步:

第三步在您的應用程序來啓動,自舉是在角必不可少的過程 - 這是其中應用程序當Angular進入生命時加載。引導Angular應用程序與Angular 1.x完全不同,但仍然是一個簡單的過程。我們來看看這是如何完成的。

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
import { AppModule }    from './app/app.module'; 

platformBrowserDynamic().bootstrapModule(AppModule); 

參考形式https://angular-2-trainingbook.rangle.io/handout/bootstrapping/

+0

這個鏈接已損壞,共享「https://angular-2-trainingbook.rangle.io/handout/bootstrapping/」 – Mou

+0

https:// angular-2-training- book.rangle.io/handout/bootstrapping/。這一個也很好從官方網站https://angular.io/docs/ts/latest/guide/ngmodule.html –