-
父子組件通訊
(1)通訊前提:定義輸入屬性,它是通過input裝飾器來修飾的。導(dǎo)入:
import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'
(2)首先接收數(shù)據(jù)則導(dǎo)入Input裝飾器,發(fā)送數(shù)據(jù)則導(dǎo)入Output,EventEmitter
(3)使用Input裝飾器
@Input() private message : string;
發(fā)送端設(shè)置:[message]="msgToChild"
(4)使用Output裝飾器
聲明:@Output() private outer = new EventEmitter<string>();
發(fā)送數(shù)據(jù):outer.emit('something');
接收端接收代碼:(outer="receive($event)")
查看全部 -
服務(wù)使用
(1)建立xxx.service.ts
(2)在模塊(app.module.ts)中引入,同時在@NgModule中的providers中注入依賴(引入服務(wù))
(3)在組件導(dǎo)入服務(wù)類
查看全部 -
自定義指令使用
(1)建立xxx.directive.ts文件,在@Directive下的selector中聲明標(biāo)簽名。
(2)通過導(dǎo)入ElementRef、Renderer輔助元素的渲染
?constructor(el : ElementRef, render : Renderer){
?render.setElementStyle(el.nativeElement, 'backgroundColor','yellow');
}
(3)在模塊中引入指令,同時在declarations中引入指令。
(4)在組件中通過標(biāo)簽名引用自定義指令
查看全部 -
1. ngIf指令用于插入或移除dom節(jié)點
<p *ngIf="isShowMore">Angular2</p>
2. [(ngModel)]="isShowMore"? ?定義綁定信息,雙向綁定指令,使用的時候需要引入“@angular/forms”,如下:
import {FormsModule} from "@angular/forms"
查看全部 -
(1)tsconfig.json :typeScript編譯器的配置文件
(2)代碼放在app目錄下
(3)組件文件xxx.component.ts
(4)selector聲明標(biāo)簽名,templateUrl聲明外鏈模版文件
(5)模塊文件xxx.module.ts
(6)模塊文件中在declarations,bootstrap將【組件】定義到模塊里
(7)啟動文件main.ts,將聲明的模塊導(dǎo)入到這個文件,通過platformBrowserDynamic()動態(tài)引導(dǎo)啟動,最后在這里導(dǎo)入依賴庫
reflect-metadata(動態(tài)引導(dǎo)),zone.js(瀏覽器異步事件)
(8)在webpack.config.js聲明上述的啟動文件的路徑,在index.html通過script引入webpack.config.js打包出來的bundle.js(<script src="./bundle.js"></script>)
(9)在index.html中使用根組件my-app
查看全部 -
webpack.config.js
查看全部 -
webpack
查看全部 -
Angular的裝飾器
查看全部 -
裝飾器的說明
查看全部 -
TypeScript與面向?qū)ο蠼Y(jié)合點多
查看全部 -
TypeScript的例子
查看全部 -
核心的內(nèi)容展示
查看全部 -
一個Angular由多個模塊組成
查看全部 -
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 應(yīng)用模塊的交互
查看全部 -
TypeScript的裝飾器
查看全部
舉報