﻿
{"id":25463,"date":"2022-08-20T21:36:34","date_gmt":"2022-08-20T21:36:34","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=25463"},"modified":"2022-08-20T21:36:34","modified_gmt":"2022-08-20T21:36:34","slug":"angular-gelismis-component-yapilanmasi-ng-container","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/angular-gelismis-component-yapilanmasi-ng-container\/","title":{"rendered":"Angular \u2013 Geli\u015fmi\u015f Component Yap\u0131lanmas\u0131 | ng-container"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde Angular mimarisinde HTML&#8217;in d\u0131\u015f\u0131nda i\u015flevsel bir alan olu\u015fturmam\u0131z\u0131 sa\u011flayan <code>ng-container<\/code> \u00f6zelli\u011fini inceliyor olaca\u011f\u0131z.<\/p>\n<h3>ng-container Nedir?<\/h3>\n<p><code>ng-container<\/code>, sayfa \u00fczerinde HTML elementleriyle u\u011fra\u015fmaks\u0131z\u0131n bir b\u00f6l\u00fcm\/alan olu\u015fturmam\u0131za olanak sa\u011flayan, Document Object Model(DOM) i\u00e7erisinde tan\u0131mlanmayan lakin i\u00e7inde i\u00e7erik bar\u0131nd\u0131rabilen, \u00f6z\u00fc itibariyle ne directive, ne component ne de class yahut interface olan, sade ve sadece bir s\u00f6zdizimi\/syntax \u00f6\u011fesinden ibaret olan bir \u00f6zelliktir.<\/p>\n<p>Misal olarak;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &lt;h1&gt;Ba\u015fl\u0131k 1&lt;\/h1&gt;\r\n    &lt;p&gt;\u0130\u00e7erik&lt;\/p&gt;\r\n    &lt;ng-container&gt;\r\n      Container i\u00e7erik\r\n    &lt;\/ng-container&gt;\r\n<\/pre>\n<\/div>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container.png\" alt=\"Angular \u2013 Geli\u015fmi\u015f Component Yap\u0131lanmas\u0131 | ng-container\" width=\"247\" height=\"70\" class=\"alignleft size-full wp-image-25467\" \/><\/a>Yukar\u0131daki \u015fablonu ele al\u0131rsak e\u011fer bunun render edilmi\u015f hali yandaki g\u00f6rseldeki gibi olacakt\u0131r. <code>ng-container<\/code>&#8216;\u0131n render edildikten sonra herhangi bir HTML elementine kar\u015f\u0131l\u0131k gelmedi\u011fine dikkatinizi \u00e7ekerim.<\/p>\n<h3>ng-container Nerelerde Kullan\u0131l\u0131r?<\/h3>\n<p><code>ng-container<\/code>&#8216;\u0131 genellikle <a href=\"https:\/\/www.gencayyildiz.com\/blog\/angular-4-ngif-direktifi\/\" rel=\"noopener\" target=\"_blank\">ngIf<\/a>, <a href=\"https:\/\/www.gencayyildiz.com\/blog\/angular-4-ngfor-dongusu\/\" rel=\"noopener\" target=\"_blank\">ngFor<\/a> vs. gibi direktifler e\u015fli\u011finde kullanmaktay\u0131z. Bu durumlara \u00f6rnek olmas\u0131 hasebiyle a\u015fa\u011f\u0131daki \u00e7al\u0131\u015fmay\u0131 inceleyebilirsiniz:<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n  programmingLanguages = &#x5B;\r\n    { name: &quot;Angular&quot;, active: true },\r\n    { name: &quot;React&quot;, active: true },\r\n    { name: &quot;Typescript&quot;, active: true },\r\n    { name: &quot;Javascript&quot;, active: true },\r\n    { name: &quot;Php&quot;, active: false }\r\n  ]\r\n<\/pre>\n<\/div>\n<p>Yukar\u0131da, i\u00e7erisinde baz\u0131 programlama dillerinin bilgilerini bar\u0131nd\u0131ran bir koleksiyon tan\u0131m\u0131 mevcuttur. Bizler bu koleksiyon i\u00e7erisindeki programlama dillerinden aktif olanlar\u0131 ekrana listelemek istiyorsak t\u00fcm \u00f6\u011feleri tek tek ngIf direktifi ile kontrol etmemiz gerekmektedir. <code>ng-container<\/code>&#8216;\u0131 kullanmaks\u0131z\u0131n bu i\u015flemi ger\u00e7ekle\u015ftirebilmek i\u00e7in <code>span<\/code> HTML \u00f6\u011fesini a\u015fa\u011f\u0131daki gibi kullanabiliriz.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &lt;ul&gt;\r\n      &lt;span *ngFor=&quot;let language of programmingLanguages&quot;&gt;\r\n        &lt;li *ngIf=&quot;language.active&quot;&gt;{{language.name}}&lt;\/li&gt;\r\n      &lt;\/span&gt;\r\n    &lt;\/ul&gt;\r\n<\/pre>\n<\/div>\n<p>Render neticesi :<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-1.png\" alt=\"Angular \u2013 Geli\u015fmi\u015f Component Yap\u0131lanmas\u0131 ng-container\" width=\"246\" height=\"108\" class=\"aligncenter size-full wp-image-25471\" \/><\/a><br \/>\nYa da component&#8217;lerin html dosyalar\u0131n\u0131 temiz tutabilmek ve render neticesinde \u00fcretilecek kaynak kodu da m\u00fcmk\u00fcn mertebe performansl\u0131 olacak \u015fekilde sade bir \u015fekilde sunabilmek i\u00e7in <code>ng-container<\/code>&#8216;\u0131 kullanarak burada daha do\u011fru bir tercihte bulunabiliriz.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &lt;ul&gt;\r\n      &lt;ng-container *ngFor=&quot;let language of programmingLanguages&quot;&gt;\r\n        &lt;li *ngIf=&quot;language.active&quot;&gt;{{language.name}}&lt;\/li&gt;\r\n      &lt;\/ng-container&gt;\r\n    &lt;\/ul&gt;\r\n<\/pre>\n<\/div>\n<p>Render neticesi :<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-2.png\" alt=\"Angular \u2013 Geli\u015fmi\u015f Component Yap\u0131lanmas\u0131 ng-container\" width=\"256\" height=\"537\" class=\"aligncenter size-full wp-image-25472\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-2.png 256w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-2-143x300.png 143w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><br \/>\nDikkat ederseniz aktif olmayan programlama dillerinin yerine ekstradan bir html eleman\u0131 \u00fcretilmeyece\u011fi i\u00e7in maliyet ve performans a\u00e7\u0131s\u0131ndan lehimize bir davran\u0131\u015f sergilenmi\u015f olmaktad\u0131r.<\/p>\n<h3>ng-container \u0130le ng-template \u0130li\u015fkisi<\/h3>\n<p><code>ng-container<\/code> ile var olan <code>ng-template<\/code>&#8216;ler i\u00e7erisindeki \u015femalar\u0131 a\u015fa\u011f\u0131daki gibi <code style=\"color:red;\"><strong>ngTemplateOutlet<\/strong><\/code> ile dinamik bir \u015fekilde \u00e7ekebilirsiniz.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n  template: `\r\n    &lt;div class=&quot;div1&quot;&gt;\r\n      &lt;ng-container *ngTemplateOutlet=&quot;div1content&quot;&gt;&lt;\/ng-container&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=&quot;div2&quot;&gt;\r\n      &lt;ng-container *ngTemplateOutlet=&quot;div2content&quot;&gt;&lt;\/ng-container&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=&quot;div3&quot;&gt;\r\n      &lt;ng-container *ngTemplateOutlet=&quot;div3content&quot;&gt;&lt;\/ng-container&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;ng-template #div1content&gt;div1 i\u00e7eri\u011fi&lt;\/ng-template&gt;\r\n    &lt;ng-template #div2content&gt;div2 i\u00e7eri\u011fi&lt;\/ng-template&gt;\r\n    &lt;ng-template #div3content&gt;div3 i\u00e7eri\u011fi&lt;\/ng-template&gt;\r\n`,\r\n  styles: &#x5B;`\r\n    .div1 { color:red; }\r\n    .div2 { color:blue; }\r\n    .div3 { color:green; }\r\n`]\r\n<\/pre>\n<\/div>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2022\/08\/Angular-\u2013-Gelismis-Component-Yapilanmasi-ng-container-3.png\" alt=\"Angular \u2013 Geli\u015fmi\u015f Component Yap\u0131lanmas\u0131 ng-container\" width=\"89\" height=\"62\" class=\"aligncenter size-full wp-image-25473\" \/><\/a><br \/>\n\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<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde Angular mimarisinde HTML&#8217;in d\u0131\u015f\u0131nda i\u015flevsel bir alan olu\u015fturmam\u0131z\u0131 sa\u011flayan ng-container \u00f6zelli\u011fini inceliyor olaca\u011f\u0131z. ng-container Nedir? ng-container, sayfa \u00fczerinde HTML elementleriyle u\u011fra\u015fmaks\u0131z\u0131n bir b\u00f6l\u00fcm\/alan olu\u015fturmam\u0131za olanak sa\u011flayan, Document Object Model(DOM) i\u00e7erisinde tan\u0131mlanmayan&#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":7400,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2420],"tags":[2156,4646,4645,4648,4647],"class_list":["post-25463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular","tag-angular","tag-angular-ng-container","tag-ng-container","tag-ng-template","tag-ngtemplateoutlet"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25463","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=25463"}],"version-history":[{"count":7,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25463\/revisions"}],"predecessor-version":[{"id":25474,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/25463\/revisions\/25474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/7400"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=25463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=25463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=25463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}