﻿
{"id":25323,"date":"2022-06-26T19:40:27","date_gmt":"2022-06-26T19:40:27","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=25323"},"modified":"2022-06-26T19:43:12","modified_gmt":"2022-06-26T19:43:12","slug":"angular-14-standalone-components-directives-pipes","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/angular-14-standalone-components-directives-pipes\/","title":{"rendered":"Angular 14 &#8211; Standalone Components\/Directives\/Pipes"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Angular mimarisinde, stratejik temellendirmeleri mod\u00fcller e\u015fli\u011finde kuruyor ve uygulaman\u0131n genel in\u015faat\u0131n\u0131 bu mod\u00fcller \u00e7er\u00e7evesinde s\u0131n\u0131rland\u0131r\u0131yoruz. \u00d6zellikle component, directive ya da pipe yap\u0131lanmalar\u0131n\u0131 hususi mod\u00fcller ile geli\u015ftiriyor ve ihtiya\u00e7 noktas\u0131nda kullan\u0131lacak yap\u0131y\u0131, o noktadaki sorumlu mod\u00fcl taraf\u0131ndan import ederek eri\u015filebilir k\u0131l\u0131yoruz. <span style=\"font-size:12px;\">Bu duruma en g\u00fczel \u00f6rnek olarak youtube kanal\u0131mda yay\u0131nlad\u0131\u011f\u0131m  <a href=\"https:\/\/www.youtube.com\/playlist?list=PLQVXoXFVVtp1DFmoTL4cPTWEWiqndKexZ\" rel=\"noopener\" target=\"_blank\">mini e-ticaret<\/a> projesini inceleyebilirsiniz. \u0130lgili projenin kaynak kodlar\u0131n\u0131 inceleyebilmek i\u00e7in <a href=\"https:\/\/github.com\/gncyyldz\/Mini-E-Ticaret-Client\" rel=\"noopener\" target=\"_blank\">github<\/a> reposuna da g\u00f6z atabilirsiniz.<\/span> Halbuki bu durum her bir component, directive ve pipe yap\u0131lanmas\u0131 i\u00e7in ayr\u0131 bir mod\u00fcl olu\u015fturman\u0131n getirisi olan kod maliyetiyle birlikte, istemsiz bir karma\u015f\u0131kl\u0131\u011fa da sebebiyet verebilmektedir. \u015eimdi gelin bu i\u00e7eri\u011fimizde bu karma\u015f\u0131kl\u0131\u011f\u0131n neler olabilece\u011fini masaya yat\u0131r\u0131p tart\u0131\u015fal\u0131m ve alternatif \u00e7\u00f6z\u00fcm olarak Angular 14 ile birlikte gelen Standalone Components\/Directives \/Pipes \u00f6zelli\u011fi \u00fczerine isti\u015fare eyleyelim. Hadi ba\u015flayal\u0131m&#8230;<\/p>\n<p>Misal olarak bir component olu\u015fturmak istedi\u011fimizde en basitinden bu component&#8217;in i\u015flevsel hale gelebilmesi i\u00e7in ne gibi in\u015falarda bulunmam\u0131z gerekti\u011fini g\u00f6zlemleyerek girizgah yapal\u0131m isterim.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component, OnInit } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-hello',\r\n  template: `&lt;h3&gt;Hello&lt;\/h3&gt;`,\r\n  styleUrls: &#x5B;'.\/hello.component.scss']\r\n})\r\nexport class HelloComponent implements OnInit {\r\n\r\n  constructor() { }\r\n\r\n  ngOnInit(): void {\r\n  }\r\n}\r\n<\/pre>\n<\/div>\n<p>\u015eimdi bu component&#8217;i uygulama s\u00fcrecinde kullanabilmek ve bu component&#8217;te kullan\u0131lacak di\u011fer yap\u0131lar\u0131 da entegre edebilmek i\u00e7in bu component&#8217;i temsil edecek bir mod\u00fcl olu\u015fturmam\u0131z gerekecektir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { NgModule } from '@angular\/core';\r\nimport { CommonModule } from '@angular\/common';\r\nimport { HelloComponent } from '.\/hello.component';\r\n\r\n@NgModule({\r\n  declarations: &#x5B;\r\n    HelloComponent\r\n  ],\r\n  imports: &#x5B;\r\n    CommonModule\r\n  ],\r\n  exports: &#x5B;\r\n    HelloComponent\r\n  ]\r\n})\r\nexport class HelloModule { }\r\n<\/pre>\n<\/div>\n<p>Tabi olu\u015fturulan bu mod\u00fcle bakarsak e\u011fer &#8216;HelloComponent&#8217; hem declare edilmeli hem de ba\u015fka bir component&#8217;te selector \u00fczerinden kullan\u0131labilmesi i\u00e7in export edilmelidir. \u015eimdi bu component&#8217;i &#8216;app.component.html&#8217; dosyas\u0131nda kullanabilmek i\u00e7in a\u015fa\u011f\u0131daki gibi selector&#8217;\u0131n\u0131 \u00e7a\u011f\u0131rmam\u0131z gerekecektir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;app-hello&gt;&lt;\/app-hello&gt;\r\n<\/pre>\n<\/div>\n<p>T\u00fcm bu s\u00fcrecin sa\u011fl\u0131kl\u0131 bir \u015fekilde i\u015fleyebilmesi i\u00e7in olu\u015fturulan &#8216;HelloModule&#8217;\u00fc uygulaman\u0131n ana mod\u00fcl\u00fc olan &#8216;AppModule&#8217;e import etmemiz gerekmektedir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { NgModule } from '@angular\/core';\r\nimport { BrowserModule } from '@angular\/platform-browser';\r\n\r\nimport { AppRoutingModule } from '.\/app-routing.module';\r\nimport { AppComponent } from '.\/app.component';\r\nimport { HelloModule } from '.\/hello\/hello.module';\r\n\r\n@NgModule({\r\n  declarations: &#x5B;\r\n    AppComponent\r\n  ],\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    AppRoutingModule,\r\n    HelloModule\r\n  ],\r\n  bootstrap: &#x5B;AppComponent]\r\n})\r\nexport class AppModule { }\r\n<\/pre>\n<\/div>\n<p><div id=\"attachment_25328\" style=\"width: 365px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/06\/yok-artik.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-25328\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/06\/yok-artik.png\" alt=\"\" width=\"355\" height=\"238\" class=\"size-full wp-image-25328\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/06\/yok-artik.png 355w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/06\/yok-artik-300x201.png 300w\" sizes=\"auto, (max-width: 355px) 100vw, 355px\" \/><\/a><p id=\"caption-attachment-25328\" class=\"wp-caption-text\">Yok art\u0131k, m**n* y\u0131m.\ud83e\udd78<\/p><\/div>G\u00f6r\u00fcyorsunuz ki, bir Angular uygulamas\u0131nda basit bir component&#8217;i mimarisel olarak oyuna sokabilmek i\u00e7in neler yap\u0131lmas\u0131 gerekmektedir. \u0130\u015fte kastedilen kod maliyetine bir \u00f6rnek. Karma\u015f\u0131kl\u0131\u011fa gelirsek e\u011fer Angular&#8217;\u0131 yeni \u00f6\u011frenen birisi i\u00e7in bu mod\u00fcler yap\u0131lanmay\u0131 anlamak ve \u00f6zellikle i\u015flevsel olarak export ve declare davran\u0131\u015flar\u0131n\u0131 kafada oturtmak \u00f6\u011frenmeyi zorla\u015ft\u0131ran etkenlerin ba\u015f\u0131nda geliyor diye d\u00fc\u015f\u00fcn\u00fcyorum. Ayr\u0131ca bu tarz bir \u00e7al\u0131\u015fmada ince hatalar\u0131n yap\u0131lmas\u0131 ve mimarisel gereksinim olan kurall\u0131 tan\u0131mlamalar\u0131n unutulmas\u0131 gayet muhtemel&#8230;(ki 5 y\u0131la yak\u0131nd\u0131r Angular ile geli\u015ftirme yapmaktay\u0131m, hala ve hala export&#8217;lar\u0131 import&#8217;lar\u0131 unutmaktan vazge\u00e7emedim : )<\/p>\n<p><strong><em>Peki bu kod maliyetinden ve karma\u015f\u0131kl\u0131ktan nas\u0131l kurtulabiliriz la hoca?<\/em><\/strong> \u015feklinde sorunuzu duyar gibiyim&#8230; \u0130\u015fte bu makalenin muhtevas\u0131 bu sorunun cevab\u0131 i\u00e7indir&#8230; El-cevap; <em><strong>Standalone Components\/Directives\/Pipes<\/strong><\/em>&#8230;<\/p>\n<h3 style=\"color:#FF8204;\">Standalone Components\/Directives\/Pipes<\/h3>\n<p>Angular Standalone Components\/Directives\/Pipes, uygulamay\u0131 mod\u00fcler ba\u011f\u0131ml\u0131l\u0131klardan kurtarmay\u0131 hedefleyen ya da bir ba\u015fka deyi\u015fle mod\u00fcl ihtiyac\u0131n\u0131 azaltarak uygulaman\u0131n in\u015fa s\u00fcrecini kolayla\u015ft\u0131rmay\u0131 ama\u00e7layan yeni bir niteliktir.<\/p>\n<blockquote><p><em style=\"color:green;\">Standalone Components\/Directives\/Pipes \u00f6zelli\u011fi, v14&#8217;te developer preview seviyesindedirler. Kararl\u0131 bir yenilik olmad\u0131klar\u0131 i\u00e7in bu i\u00e7erikte sunulacak olanlar\u0131n d\u0131\u015f\u0131nda potansiyel olarak de\u011fi\u015fikliklere u\u011frayabilirler.<\/em><\/p><\/blockquote>\n<p>\u015eimdi yine yukar\u0131da olu\u015fturdu\u011fumuz component&#8217;i standalone olarak tasarlamak istersek bu sefer de a\u015fa\u011f\u0131daki gibi basit bir konfig\u00fcrasyonel ayar yapmam\u0131z yeterli olacakt\u0131r.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component, OnInit } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-hello',\r\n  template: `&lt;h3&gt;Hello&lt;\/h3&gt;`,\r\n  styleUrls: &#x5B;'.\/hello.component.scss'],\r\n  standalone: true\r\n})\r\nexport class HelloComponent implements OnInit {\r\n\r\n  constructor() { }\r\n\r\n  ngOnInit(): void {\r\n  }\r\n}\r\n<\/pre>\n<\/div>\n<p><strong>7.<\/strong> sat\u0131rda g\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere &#8216;Component&#8217; dekorat\u00f6r\u00fcn\u00fcn i\u00e7erisinde &#8216;standalone&#8217; parametresine &#8216;true&#8217; de\u011ferini vererek ilgili component&#8217;in bir standalone component oldu\u011funu bildiriyoruz. B\u00f6ylece art\u0131k bu component&#8217;in declare edilebilir bir component&#8217;ten ziyade ba\u011f\u0131ms\u0131z bir component oldu\u011funu ifade etmi\u015f oluyoruz. Tabi bu durumda da &#8216;selector&#8217; \u00fczerinden bir kullan\u0131m sergilemek istiyorsak e\u011fer bunun i\u00e7in art\u0131k hedef component&#8217;in bulundu\u011fu mod\u00fclde ya da component&#8217;in ta kendisinde bu standalone component&#8217;in import edilmesi gerekmektedir! Evet, yanl\u0131\u015f okumad\u0131n\u0131z, standalone component&#8217;ler kullan\u0131lacaklar\u0131 noktalarda import edilmek zorundad\u0131rlar!<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@NgModule({\r\n  declarations: &#x5B;\r\n    AppComponent\r\n  ],\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    AppRoutingModule,\r\n    HelloComponent\r\n  ],\r\n  bootstrap: &#x5B;AppComponent]\r\n})\r\nexport class AppModule { }\r\n<\/pre>\n<\/div>\n<p>Yukar\u0131daki kod blo\u011funa bakarsan\u0131z e\u011fer, standalone component olan &#8216;HelloComponent&#8217;i &#8216;AppComponent&#8217;te kullanabilmek i\u00e7in &#8216;AppComponent&#8217;in declare edildi\u011fi &#8216;AppModule&#8217;de import ediyoruz. B\u00f6ylece selector \u00f6zelli\u011fini &#8216;AppComponent&#8217;te kullanmaya devam edebiliyoruz.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;app-hello&gt;&lt;\/app-hello&gt;\r\n<\/pre>\n<\/div>\n<p>Ayn\u0131 durum directive ve pipe yap\u0131lanmalar\u0131 i\u00e7in de ge\u00e7erlidir. Misal olarak a\u015fa\u011f\u0131daki \u00e7al\u0131\u015fmalar\u0131 inceleyebilirsiniz;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@Directive({\r\n  selector: '&#x5B;appHello]',\r\n  standalone: true\r\n})\r\nexport class HelloDirective {\r\n\r\n  constructor(private element: ElementRef) {\r\n    element.nativeElement.innerHTML = &quot;Hello&quot;;\r\n  }\r\n\r\n}\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@Pipe({\r\n  name: 'hello',\r\n  standalone: true\r\n})\r\nexport class HelloPipe implements PipeTransform {\r\n\r\n  transform(value: string) {\r\n    return &quot;Hello&quot;;\r\n  }\r\n\r\n}\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@NgModule({\r\n  declarations: &#x5B;\r\n    AppComponent\r\n  ],\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    AppRoutingModule,\r\n    HelloComponent, HelloDirective, HelloPipe\r\n  ],\r\n  bootstrap: &#x5B;AppComponent]\r\n})\r\nexport class AppModule { }\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;h3 appHello&gt;&lt;\/h3&gt;\r\n\r\n{{ &quot;&quot; | hello }}\r\n<\/pre>\n<\/div>\n<h3 style=\"color:#FF8204;\">Bir Standalone Yap\u0131da Ba\u015fka Bir Standalone Yap\u0131y\u0131 Kullanmak<\/h3>\n<p>Standalone yap\u0131lar, herhangi bir mod\u00fcle ba\u011f\u0131ml\u0131l\u0131klar\u0131 olmad\u0131\u011f\u0131 i\u00e7in kendi aralar\u0131nda kullan\u0131l\u0131rken import tan\u0131mlamas\u0131n\u0131 direkt &#8216;Component&#8217; dekorat\u00f6r\u00fcn\u00fcn &#8216;imports&#8217; parametresi \u00fczerinden ger\u00e7ekle\u015ftirmektedirler.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component, OnInit } from '@angular\/core';\r\nimport { HelloPipe } from '..\/pipes\/hello.pipe';\r\n\r\n@Component({\r\n  selector: 'app-hello',\r\n  template: `\r\n    &lt;h3&gt;Hello&lt;\/h3&gt;\r\n    {{ &quot;&quot; | hello }}\r\n            `,\r\n  styleUrls: &#x5B;'.\/hello.component.scss'],\r\n  standalone: true,\r\n  imports: &#x5B;HelloPipe]\r\n})\r\nexport class HelloComponent implements OnInit {\r\n\r\n  constructor() { }\r\n\r\n  ngOnInit(): void {\r\n  }\r\n}\r\n<\/pre>\n<\/div>\n<p>Misal olarak yukar\u0131daki kod blo\u011funu incelerseniz; standalone component olan &#8216;HelloComponent&#8217;, standalone pipe olan &#8216;HelloPipe&#8217;\u0131 kullanmak istedi\u011finde bunu <strong>12.<\/strong> sat\u0131rda oldu\u011fu gibi &#8216;imports&#8217; parametresi e\u015fli\u011finde bildirmektedir.<\/p>\n<h3 style=\"color:#FF8204;\">Standalone Yap\u0131larda Mod\u00fcler Yap\u0131lar\u0131 Kullanmak<\/h3>\n<p>Ayn\u0131 \u015fekilde standalone bir yap\u0131da mod\u00fcler bir yap\u0131lanmay\u0131 kullanabilmek i\u00e7in de &#8216;imports&#8217; parametresinde gerekli tan\u0131mlaman\u0131n yap\u0131lmas\u0131 gerekmektedir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component, OnInit } from '@angular\/core';\r\nimport { HelloPipe } from '..\/pipes\/hello.pipe';\r\nimport { MatButtonModule } from '@angular\/material\/button';\r\n\r\n@Component({\r\n  selector: 'app-hello',\r\n  template: `\r\n    &lt;h3&gt;Hello&lt;\/h3&gt;\r\n    {{ &quot;&quot; | hello }}\r\n    &lt;button mat-raised-button color=&quot;primary&quot;&gt;Primary&lt;\/button&gt;\r\n            `,\r\n  styleUrls: &#x5B;'.\/hello.component.scss'],\r\n  standalone: true,\r\n  imports: &#x5B;HelloPipe, MatButtonModule]\r\n})\r\nexport class HelloComponent implements OnInit {\r\n\r\n  constructor() { }\r\n\r\n  ngOnInit(): void {\r\n  }\r\n}\r\n<\/pre>\n<\/div>\n<p>Misal olarak yukar\u0131daki \u00f6rne\u011fi incelerseniz standalone component olan &#8216;HelloComponent&#8217; i\u00e7erisinde material button kullanabilmek i\u00e7in &#8216;MatButtonModule&#8217; mod\u00fcl\u00fcn\u00fcn import edilmesi gerekmektedir.<\/p>\n<h3 style=\"color:#FF8204;\">AppModule&#8217;den Kurtulmak<\/h3>\n<p>Standalone component&#8217;ler de amac\u0131n m\u00fcmk\u00fcn mertebe mod\u00fcler yap\u0131lanmadan kurtulmak oldu\u011funu s\u00f6ylemi\u015ftik. Hatta bunu biraz daha ilerleterek uygulamay\u0131 &#8216;AppModule&#8217;den de kurtarmak \u015feklinde d\u00fc\u015f\u00fcnebiliriz. Bu niyeti ger\u00e7ekle\u015ftirmek i\u00e7in uygulamada &#8216;AppModule&#8217;\u00fc silerek ba\u015flayabiliriz. \ud83e\udd78\ud83e\udd78<strong><em>&#8216;AppModule&#8217;\u00fc silmek mi? \u0130yide hoca o zaman uygulama takla atmam\u0131z m\u0131 lo?<\/em><\/strong> dedi\u011finizi duyar gibiyim \ud83d\ude42 Tabi ki de uygulama takla atar. Lakin uygulamada &#8216;AppModule&#8217;\u00fcn getirdi\u011fi ba\u011f\u0131ml\u0131l\u0131klar\u0131 ortadan kald\u0131racak ama bir yandan da onun t\u00fcm sorumlulu\u011funu \u00fcstlenecek bir noktaya ihtiyac\u0131m\u0131z olacakt\u0131r. Bu da &#8216;main.ts&#8217; dosyas\u0131d\u0131r.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { bootstrapApplication, BrowserModule } from '@angular\/platform-browser';\r\n.\r\n.\r\n.\r\n\r\nif (environment.production) {\r\n  enableProdMode();\r\n}\r\n\r\n\/\/platformBrowserDynamic().bootstrapModule(AppModule)\r\n\/\/  .catch(err =&gt; console.error(err));\r\n\r\nbootstrapApplication(AppComponent, {\r\n  providers: &#x5B;\r\n    { provide: &quot;url&quot;, useValue: &quot;https:\/\/...&quot; },\r\n    importProvidersFrom(\r\n      BrowserModule,\r\n      AppRoutingModule,\r\n      BrowserAnimationsModule\r\n    )\r\n  ]\r\n})\r\n<\/pre>\n<\/div>\n<p>Yukar\u0131da &#8216;main.ts&#8217; dosyas\u0131n\u0131n son halini g\u00f6rmektesiniz. \u0130\u00e7eri\u011fine bakarsan\u0131z e\u011fer <strong>10<\/strong> ile <strong>11.<\/strong> sat\u0131r aral\u0131\u011f\u0131nda yorum sat\u0131r\u0131 olarak ayarlanan <code>platformBrowserDynamic<\/code> fonksiyonu devam\u0131nda ana mod\u00fcl\u00fc &#8216;AppModule&#8217; olarak belirlememizi sa\u011flayan <code>bootstrapModule<\/code> fonksiyonu ile uygulamay\u0131 &#8216;AppModule&#8217;e ba\u011f\u0131ml\u0131 bir hale getiriyorduk. Haliyle ilgili kod k\u0131sm\u0131 silinerek bu ba\u011f\u0131ml\u0131l\u0131k ortadan kald\u0131r\u0131lm\u0131\u015ft\u0131r. Bunun yerine, <strong>13<\/strong> ile <strong>22.<\/strong> sat\u0131r aral\u0131\u011f\u0131nda oldu\u011fu gibi <em>&#8216;@angular\/platform-browser&#8217;<\/em> path&#8217;in de olan <code>bootstrapApplication<\/code> metodu sayesinde art\u0131k uygulaman\u0131n ana mod\u00fcl\u00fcnden ziyade direkt ana component&#8217;i bildirilmekte ve ard\u0131ndan &#8216;AppModule&#8217;de ki importlar ikinci parametre olarak &#8216;providers&#8217;a kar\u015f\u0131l\u0131k verilmektedir. B\u00f6ylece art\u0131k uygulama mod\u00fclerli\u011fe olan ba\u011f\u0131ml\u0131l\u0131\u011f\u0131ndan tamamen izole olmu\u015f bir vaziyette temellendirilmektedir. <\/p>\n<p>Burada \u00f6zellikle dikkat etmenizi istedi\u011fim nokta <strong>16.<\/strong> sat\u0131rdaki <code>importProvidersFrom<\/code> fonksiyonudur. \u015eimdi normal \u015fartlarda bizler &#8216;providers&#8217;a singleton olarak tutulacak olan nesneleri vermeye, mod\u00fclleri ise import etmeye al\u0131\u015fk\u0131n\u0131z. Amma velakin burada import edilecek mod\u00fcller de &#8216;providers&#8217; \u00fczerinden verilmektedir. Hah i\u015fte buradaki ayr\u0131m\u0131 yaratabilmek i\u00e7in mod\u00fcllerin <code>importProvidersFrom<\/code> metodu arac\u0131l\u0131\u011f\u0131 ile verilmesi gerekmektedir.<\/p>\n<h3 style=\"color:#FF8204;\">Routing ve Lazy Loading<\/h3>\n<p>Uygulama standalone altyap\u0131s\u0131 sayesinde mod\u00fcler yap\u0131lanmadan soyutland\u0131\u011f\u0131na g\u00f6re bu durum routing i\u015flemleri i\u00e7inde ayr\u0131 bir nitelik kazand\u0131rmaktad\u0131r. Nihayetinde lazy loading s\u00fcre\u00e7lerinde mod\u00fcler yap\u0131lanmalar\u0131 <code>loadChildren<\/code> ile bildiriyorken, standalone component&#8217;leri ise mod\u00fclleri olmad\u0131\u011f\u0131 i\u00e7in <code>loadComponent<\/code> fonksiyonu ile bildirmemiz gerekmektedir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.\r\n.\r\n.\r\nconst routes: Routes = &#x5B;\r\n  {\r\n    path: &quot;hello&quot;, loadComponent: () =&gt; import(&quot;.\/hello\/hello.component&quot;)\r\n      .then(component =&gt; component.HelloComponent)\r\n  },\r\n  {\r\n    path: &quot;example&quot;, loadChildren: () =&gt; import(&quot;.\/example\/example.module&quot;)\r\n      .then(module =&gt; module.ExampleModule)\r\n  }\r\n];\r\n.\r\n.\r\n.\r\n<\/pre>\n<\/div>\n<p>Tabi bu tan\u0131mlamadan sonra ilgili routing i\u015flemlerinin yap\u0131laca\u011f\u0131 component hangisi olursa olsun &#8216;imports&#8217; \u00f6zelli\u011fine &#8216;RouterModule&#8217;\u00fcn eklenmesi gerekmektedir. Misal olarak routing i\u015fleminin &#8216;AppComponent&#8217;te yap\u0131laca\u011f\u0131n\u0131 varsayarsak e\u011fer a\u015fa\u011f\u0131daki gibi ismi ge\u00e7en mod\u00fcl\u00fcn bildirilmesi zaruridir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.scss'],\r\n  standalone: true,\r\n  imports: &#x5B;HelloComponent, HelloPipe, HelloDirective, RouterModule]\r\n})\r\nexport class AppComponent {\r\n  title = 'standaloneExample';\r\n}\r\n<\/pre>\n<\/div>\n<p>Nihai olarak,<br \/>\nAngular mimarlar\u0131n\u0131n, uygulama s\u00fcre\u00e7lerinde ana akt\u00f6rlerden biri olan component yap\u0131lanmas\u0131n\u0131n herhangi bir mod\u00fcle ba\u011f\u0131ml\u0131 olmaks\u0131z\u0131n geli\u015ftirilmesini ve b\u00f6ylece kod maliyetini d\u00fc\u015f\u00fcrmek ile birlikte kullan\u0131m kolayl\u0131\u011f\u0131n\u0131 hedefledi\u011fini g\u00f6rmekteyiz. Nacizane fikir olarak g\u00fczel ve umut verici bir geli\u015fme oldu\u011funun alt\u0131n\u0131 \u00e7izerek yaz\u0131m\u0131z\u0131 noktal\u0131yorum.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<p>Not : \u00d6rnek \u00e7al\u0131\u015fmay\u0131 a\u015fa\u011f\u0131daki github adresinden inceleyebilirsiniz.<br \/>\n<a href=\"https:\/\/github.com\/gncyyldz\/StandaloneComponentsExample\" rel=\"noopener\" target=\"_blank\">https:\/\/github.com\/gncyyldz\/StandaloneComponentsExample<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Angular mimarisinde, stratejik temellendirmeleri mod\u00fcller e\u015fli\u011finde kuruyor ve uygulaman\u0131n genel in\u015faat\u0131n\u0131 bu mod\u00fcller \u00e7er\u00e7evesinde s\u0131n\u0131rland\u0131r\u0131yoruz. \u00d6zellikle component, directive ya da pipe yap\u0131lanmalar\u0131n\u0131 hususi mod\u00fcller ile geli\u015ftiriyor ve ihtiya\u00e7 noktas\u0131nda kullan\u0131lacak yap\u0131y\u0131, o noktadaki&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":25346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2420,4610],"tags":[4617,4614,4615,4616,4621,4618,4619,4620],"class_list":["post-25323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular","category-angular-14","tag-angular-standalone","tag-angular-standalone-components","tag-angular-standalone-directives","tag-angular-standalone-pipes","tag-importprovidersfrom","tag-standalone-components","tag-standalone-directives","tag-standalone-pipes"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=25323"}],"version-history":[{"count":24,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25323\/revisions"}],"predecessor-version":[{"id":25349,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25323\/revisions\/25349"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/25346"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=25323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=25323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=25323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}