2015-12-23 32 views
0

我与angular2当前测试版本的任何疑问,请帮助我了解或告诉我一个正确的技术文档?Angular2 - 需要一些清晰度

1)这里是我的app.component这里我只出口AppComponent。但是我的@Component如何在这里得名?这是如何连接的?

import {Component} from 'angular2/core'; 


interface Hero { 
    id: number; 
    name: string; 
} 

@Component({ 
    selector: 'my-app', 
    template: ` 
     <h1>{{title}}</h1> 
     <h2>{{hero.name}} details!</h2> //but how i am getting name here? 
     <div><label>id: </label>{{hero.id}}</div> 
     <div> 
      <label>name: </label> 
      <div><input [(ngModel)]="hero.name" placeholder="name"></div> 
     </div> 
    ` 
}) 



export class AppComponent { 

    public title = "Tour of Heros"; 
    public hero : Hero = { 

     id :1, 
     name: 'Windstorm' 

    } 

} 
  • 这里是我的boot.ts只得到AppComponent孤单。不@Component但仍然是如何在HTML中可用的@component模板?如何boot.tsAppComponent让我template
  • import {bootstrap} from 'angular2/platform/browser' 
    import {AppComponent} from './app.component' 
    
    bootstrap(AppComponent); 
    

    任何一个澄清我。我对angular2非常陌生。 在此先感谢。

    回答

    2

    我觉得你的问题在quickstart页面大多回答:

    类成为角状的部件时,我们给它的元数据。我们使用Angular Component函数定义组件的元数据。

    在打字稿我们应用该功能,以班级为装饰用@符号前缀,并调用它只是组件类以上。
    @Component告诉角度,这个类是角状的部件。

    当Angular在boot.ts中调用bootstrap函数时,它读取AppComponent元数据,找到my-app选择器,找到名为my-app的元素标签,并在这些标签之间加载我们的应用程序。

    而且,看看由打字稿编译器生成的JavaScript文件:app.component.js。您将看到模板被添加到生成的AppComponent函数中。