最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
angular6使用ngContentOutlet實現(xiàn)組件位置交換的方法

小編給大家分享一下angular6使用ngContentOutlet實現(xiàn)組件位置交換的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

成都創(chuàng)新互聯(lián)服務(wù)項目包括武陵源網(wǎng)站建設(shè)、武陵源網(wǎng)站制作、武陵源網(wǎng)頁制作以及武陵源網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,武陵源網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到武陵源省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

ngContentOutlet指令介紹

ngContentOutlet指令與ngTemplateOutlet指令類似,都用于動態(tài)組件,不同的是,前者傳入的是一個Component,后者傳入的是一個TemplateRef。

首先看一下使用:

其中MyComponent是我們自定義的組件,該指令會自動創(chuàng)建組件工廠,并在ng-container中創(chuàng)建視圖。

實現(xiàn)組件位置交換

angular中視圖是和數(shù)據(jù)綁定的,它并不推薦我們直接操作HTML DOM元素,而且推薦我們通過操作數(shù)據(jù)的方式來改變組件視圖。

首先定義兩個組件:

button.component.ts

import { Component, OnInit } from '@angular/core';
@Component({
 selector: 'app-button',
 template: ``,
 styleUrls: ['./button.component.css']
})
export class ButtonComponent implements OnInit {
 constructor() { }
 ngOnInit() {

text.component.ts

import { Component, OnInit, Input } from '@angular/core';
@Component({
 selector: 'app-text',
 template: `
 
 
 `,
 styleUrls: ['./text.component.css']
})
export class TextComponent implements OnInit {
 @Input() public textName = 'null';
 constructor() { }
 ngOnInit() {
 }
}

我們在下面的代碼中,動態(tài)創(chuàng)建以上兩個組件,并實現(xiàn)位置交換功能。

動態(tài)創(chuàng)建組件,并實現(xiàn)位置交換

我們先創(chuàng)建一個數(shù)組,用于存放上文創(chuàng)建的兩個組件ButtonComponent和TextComponent,位置交換時,只需要調(diào)換組件在數(shù)組中的位置即可,代碼如下:

import { TextComponent } from './text/text.component';
import { ButtonComponent } from './button/button.component';
import { Component } from '@angular/core';
@Component({
 selector: 'app-root',
 template: `
 
  
 
 
`, styleUrls: ['./app.component.css'] }) export class AppComponent { public componentArr = [TextComponent, ButtonComponent]; constructor() { } public swap() { const temp = this.componentArr[0]; this.componentArr[0] = this.componentArr[1]; this.componentArr[1] = temp; } }

看完了這篇文章,相信你對angular6使用ngContentOutlet實現(xiàn)組件位置交換的方法有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!


文章標題:angular6使用ngContentOutlet實現(xiàn)組件位置交換的方法
當前地址:http://fisionsoft.com.cn/article/ppesdp.html