Angular學習 模組和元件的動態載入

2021-08-02 05:27:21 字數 546 閱讀 8580

可以利用路由的loadchildren來動態載入angular模組和元件。

1. 建立乙個要動態載入的模組(包含相應的元件)

dyn-plugin.module.ts

import from '@angular/core';

import from '@angular/common';

import from './pfc-plugin-routing.module';

import from './pfc-plugin.component';

@ngmodule()

export default class dynpluginmodule

注意:要有default 。

元件的**就省略了。

2. 通過路由的loadchildren來動態載入模組。

guimain-routing.module.ts

let baseroute: route = ,,]

}@ngmodule()

export class guimainroutingmodule

Angular學習 元件通訊

父元件不僅可以給子元件傳遞簡單的資料,還可以把自己的方法及整個父元件傳給子元件。1 父元件呼叫子元件的時候傳入資料 2 子元件引入input模組 3 子元件中 input接收父元件傳過來的資料 如果要將整個父元件傳給子元件,可以把this傳過去 如果父元件有haha屬性,可以在子元件裡直接使用thi...

angular 父元件和子元件

export class childcomponent implements oninit ngoninit greeting name string 按鈕呼叫child2的greeting方法 viewchild child1 child1 childcomponent ngoninit void...

angular共享模組的使用,含共享元件的使用

這裡的共享模組的書寫形式是看了大漠大神的nicefish後弄出來的,熟悉了angular2後再去看大神的專案感覺不一樣了 現在來說明一下怎麼運用 ng g c testcommon 這裡下了angular cli按理說就能使用ng命令,但是如果angular cli版本低了的話會有警告最後可能出錯不...