AngularJS2初学小结
发布时间:2020-12-17 10:06:36 所属栏目:安全 来源:网络整理
导读:本文的实例中用到了ng2-bootStrap,是用Angular2和bootStrap开发的第三方Component。感兴趣的同学可以戳链接看看。 ###Component 自定义Component -在Angular2中使用@Component 注解在自定义组件: import {Component} from '@angular/core';import {AlertCom
###Component
import {Component} from '@angular/core'; import {AlertComponent,DATEPICKER_DIRECTIVES} from 'ng2-bootstrap/ng2-bootstrap'; @Component({ selector: 'my-app',directives: [AlertComponent],templateUrl:'Demo.html' }) export class AppComponent { } 其中Demo.html就是一个html文件内容如下: <alert type="info">ng2-bootstrap hello world!</alert> 你就可以在你的index.html中使用
截图如下: 2.@Component 的属性 在@Component中有几个比较常用的属性,上面的eg中出现了三个。
当然还有一些其他的常用属性,现在几个我比较常用的几个属性 3.inputs 和 outputs
import {Component} from '@angular/core'; import {AlertComponent,DATEPICKER_DIRECTIVES} from 'ng2-bootstrap/ng2-bootstrap'; @Component({ selector: 'demo',inputs: ['h2Value'],template: ` <h2>{{h2Value}}</h2> ` }) export class InputComponent { public h2Value: string = "Hello"; } @Component({ selector: 'my-app',directives: [InputComponent],template: ` <div> <demo [h2Value]="customValue"></demo> </div> ` }) export class AppComponent { customValue: string = "Hello World!"; } 可以看到在第一个Component中 的innerHTML为 |