Angular - ng | angular component用法
畫面需要重複利用的內容時,可利用嵌入內容設計(transclusion)來達成,是一個內容投射(contentprojection)的概念Contentprojectionwithng-content(投射全部內容)如下圖所示,在app-root畫面,使用了兩個auth-form的元件內容,但auth-form的title因為寫死了,所以現在畫面都長一樣,有沒有更好的做法呢?可以使用ng-content!使用ng-content所以在兩個auth-form內寫了
的內容,然後auth-form加上ng-content如此ng-content就會把我們定義的內容投射進去(因為在左邊我們也沒有定義其他內容)成功的置換了title,大功告成...
畫面需要重複利用的內容時,可利用嵌入內容設計 (transclusion) 來達成,是一個內容投射 (content projection) 的概念
Content projection with ng-content (投射全部內容)如下圖所示,在 app-root 畫面,使用了兩個 auth-form的元件內容,但auth-form的 title 因為寫死了,所以現在畫面都長一樣,有沒有更好的做法呢? 可以使用 ng-content !
使用 ng-content所以在兩個 auth-form 內寫了<h3> 的內容,然後auth-form 加上 ng-content
如此 ng-content 就會把我們定義的 <h3> 內容投射進去 (因為在左邊我們也沒有定義其他內容)
成功的置換了 title,大功告成
Using ng-content with projection slots (用 select 指定投射內容)現在我們希望把下面的按鈕也換掉,所以多加了一個按鈕
但會發現按鈕都在上面,因為現在只有使用<ng-content>,所以他會把 “所有” 內容都投射進去
所以如果想要把 title 的位置放上面,按鈕在下面的位置可以使用 ng-content + select
這個例子
ng-content + select (HTML tag or css selector 語法) 1<ng-content select="像是使用 css selector"></ng-content>1234567//用 class 去找<ng-content select=".card-body"></ng-content>...<div class="card-block" body card>...</div>...1234567//用 attibute 去找<ng-content select="[card][body]"></ng-cont...取得本站獨家住宿推薦 15%OFF 訂房優惠
Angular 動態 Component angular component教學 angular架構 angular 8教學 Angular component Angular Angular 裝飾器 angular component教學
本站住宿推薦 20%OFF 訂房優惠,親子優惠,住宿折扣,限時回饋,平日促銷
Angular - ng | angular component用法
16 17 18 19 20, import Component, Output, EventEmitter } from '@angular/core'; @Component( selector: 'auth-remember', template: ` <label> Read More
[Angular 大師之路] Day 16 | angular component用法
... 這種會改變DOM 結構的語法,像是 *ngIf 或 *ngFor 等等,在Angular 裡都稱為Structural Directive,這種用法看起來跟我們自己設計directive (像是 ... Read More
[Angular 大師之路] 自己的樣板語法自己做(Structural Directives ... | angular component用法
... 這種會改變DOM 結構的語法,像是*ngIf 或*ngFor 等等,在Angular 裡都稱為Structural Directive,這種用法看起來跟我們自己設計directive (像 ... Read More
[Angular2速成班]來寫個TodoApp(1) | angular component用法
之前的文章介紹過Angular CLI的基本用法之後,本篇文章開始就來寫一個 ... selector: 用來表示在HTML上的哪個element要套用這個component. Read More
[Angular] 另外一種簡單的方式載入Component | angular component用法
原本Angular 就提供動態載入Component 的方式,但是Angular 又提供另外一種更簡單的方式,ngComponentOutlet,簡單到一個變態的境界. Read More
[功能介紹-1] Angular架構- iT 邦幫忙 | angular component用法
Templates. 裡面的 component.html 檔就是template,它看起來像是一個html的檔案,可以在裡面用資料綁定 ... Read More
[功能介紹-4] 組件間的溝通 - iT 邦幫忙 | angular component用法
import Component, Input } from '@angular/core'; import Hero } from './hero'; @Component( selector: 'app-hero-child', template: ' <h3>hero.name}} ... Read More
元件之間的互動 | angular component用法
component-interaction/src/app/hero-child.component.ts content_copy import Component, Input } from '@angular/core'; import Hero } from './hero' ... Read More
元件樣式 | angular component用法
@Component( selector: 'app-root', template: ` <h1>Tour of Heroes</h1> <app-hero-main [hero]="hero"></app-hero-main> `, styles: ['h1 font-weight: normal; } ... Read More
服務與依賴注入簡介 | angular component用法
src/app/hero-list.component.ts (constructor) Read More
訂房住宿優惠推薦