久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      Angular學(xué)習(xí)之聊聊獨(dú)立組件(Standalone Component)

      本篇文章帶大家繼續(xù)angular的學(xué)習(xí),簡(jiǎn)單了解一下Angular中的獨(dú)立組件(Standalone Component),希望對(duì)大家有所幫助!

      Angular學(xué)習(xí)之聊聊獨(dú)立組件(Standalone Component)

      Angular 14一項(xiàng)令人興奮的特性就是Angular的獨(dú)立組件(Standalone Component)終于來了?!鞠嚓P(guān)教程推薦:《angular教程》】

      在Angular 14中, 開發(fā)者可以嘗試使用獨(dú)立組件開發(fā)各種組件,但是值得注意的是Angular獨(dú)立組件的API仍然沒有穩(wěn)定下,將來可能存在一些破壞性更新,所以不推薦在生產(chǎn)環(huán)境中使用。

      基本使用

      angular.io/guide/stand…

      standalone 是 Angular14 推出的新特性。

      它可以讓你的 根模塊 AppModule 不至于那么臃腫

      所有的 component / pipe / directive 都在被使用的時(shí)候 在對(duì)應(yīng)的組件引入就好了

      舉個(gè)例子 這是之前的寫法 我們聲明一個(gè) Footer 組件

      然后在使用的 Module 中導(dǎo)入這個(gè)組件

      import { Component } from '@angular/core';  @Component({   selector: 'app-footer',   template: ` <footer class="dark:bg-gray-800 dark:text-gray-50">Footer</footer> `, }) export class FooterComponent {}
      登錄后復(fù)制

      import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FooterComponent } from './footer.component';  @NgModule({   declarations: [HomeComponent, FooterComponent],   exports: [],   imports: [CommonModule], }) export class AppModuleModule {}
      登錄后復(fù)制

      這種寫法導(dǎo)致我們始終無法擺脫 NgModule

      但其實(shí)我們的意圖就是在 AppComponent 中使用 FooterComponent

      換成 React 中的寫法 其實(shí)會(huì)更便于管理和理解

      用上我們的新特性 standalone

      Footer 組件就改造成這樣

      import { Component } from '@angular/core';  @Component({   selector: 'app-footer',   // 將該組件聲明成獨(dú)立組件   standalone: true,   template: ` <footer class="dark:bg-gray-800 dark:text-gray-50">Footer</footer> `, }) export class FooterComponent {}
      登錄后復(fù)制

      然后比如在 Home 頁(yè)面 我們就可以這樣使用

      import { Component } from '@angular/core';  import { FooterComponent } from '@components/footer/footer.component';  @Component({   selector: 'app-home',   standalone: true,   // 聲明需要使用的 component / pipe / directive 但是它們也必須都是獨(dú)立組件   imports: [FooterComponent],   template: `<app-footer></app-footer>`, }) export class WelcomeComponent {}
      登錄后復(fù)制

      獨(dú)立組件可以直接用于懶加載 本來我們必須借助 NgModule 來實(shí)現(xiàn)

      import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router';  import { CustomPreloadingStrategy } from '@views/basic-syntax/router/customPreloadingStrategy';  const routes: Routes = [   {     path: 'home',     // 之前想要實(shí)現(xiàn)懶加載 這里必須是一個(gè)NgModule 現(xiàn)在使用獨(dú)立組件也可以 并且更加簡(jiǎn)潔     loadComponent: () => import('@views/home/home.component').then((mod) => mod.HomeComponent),   }, ];  @NgModule({   imports: [RouterModule.forRoot(routes, { preloadingStrategy: CustomPreloadingStrategy })],   exports: [RouterModule], }) export class AppRoutingModule {}
      登錄后復(fù)制

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)