﻿
{"id":7662,"date":"2018-04-17T20:58:54","date_gmt":"2018-04-17T20:58:54","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=7662"},"modified":"2018-04-17T20:58:54","modified_gmt":"2018-04-17T20:58:54","slug":"angular-4-event-binding","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/angular-4-event-binding\/","title":{"rendered":"Angular 4 &#8211; Event Binding"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde Angular 4 k\u00fct\u00fcphanesinde Event Binding olgusunu inceliyor olaca\u011f\u0131z. Tabi web programlama yahut &#8220;front end&#8221; ile az \u00e7ok ilgilenen her er ki\u015finin yabanc\u0131l\u0131k \u00e7ekmeyece\u011fi bir konuda oldu\u011fundan fazla detaya bula\u015fmadan ilgili k\u00fct\u00fcphanede olay i\u015flemlerinin nas\u0131l ceyran etti\u011fini irdeleyecek ve makalemizi sonland\u0131raca\u011f\u0131z.<\/p>\n<p>O halde, hi\u00e7 vakit kaybetmeden buyrun ba\u015flayal\u0131m&#8230;<\/p>\n<p>Angular uygulamalar\u0131nda a\u015fa\u011f\u0131daki prototipte oldu\u011fu gibi event olu\u015fturmaktay\u0131z.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;&#x5B;HTML Nesnesi] (OLAY\/EVENT)=&quot;\u0130\u015eLEMLER\/FONKS\u0130YONLAR&quot;&gt;\r\n<\/pre>\n<p>Yukar\u0131daki prototipi incelerseniz e\u011fer olaylar\u0131n parantez i\u00e7erisinde tan\u0131mland\u0131\u011f\u0131na dikkatinizi \u00e7ekerim.<br \/>\n\u015eimdi a\u015fa\u011f\u0131daki \u00f6rnekleri inceleyiniz.<\/p>\n<ul>\n<li>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  ngClickFunction() {\r\n    alert(&quot;Button is click&quot;);\r\n  }\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;button (click)=&quot;ngClickFunction()&quot;&gt;T\u0131kla&lt;\/button&gt;\r\n<\/pre>\n<\/li>\n<li>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  ngTextRead(text: string) {\r\n    alert(text);\r\n  }\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;button (click)=&quot;ngTextRead(txt1.value)&quot;&gt;T\u0131kla&lt;\/button&gt;\r\n&lt;input type=&quot;text&quot; #txt1  \/&gt;\r\n<\/pre>\n<p>Burada butona t\u0131kland\u0131\u011f\u0131 zaman inputtaki de\u011fere &#8220;#txt1&#8221; etiketi sayesinde ula\u015fabilmekteyiz.\n<\/li>\n<li>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  ngTextWrite(text: string) {\r\n    alert(text);\r\n  }\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; #txt1 (change)=&quot;ngTextWrite(txt1.value)&quot; \/&gt;\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>\u015euana kadar genel ge\u00e7er event yap\u0131lar\u0131n\u0131 ele ald\u0131\u011f\u0131m\u0131zdan dolay\u0131 \u00e7okta \u00fczerine durmaks\u0131z\u0131n direkt olarak yap\u0131sal a\u00e7\u0131dan iskeletini incelemi\u015f bulunmaktay\u0131z. Haliyle yava\u015f yava\u015f event yap\u0131lar\u0131n\u0131 Angular k\u00fct\u00fcphanesine \u00f6zel biraz daha derinle\u015ftirmeye ba\u015flayal\u0131m&#8230;<\/p>\n<p>Angular uygulamalar\u0131nda olaylar\u0131 belirli filtrelere tabii tutarak bind edebilmekteyiz. Yani uzun laf\u0131n k\u0131sas\u0131 filtreli olaylar olu\u015fturabilmekteyiz.<\/p>\n<p>A\u015fa\u011f\u0131daki kod blo\u011funu incelerseniz e\u011fer;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  text = &quot;&quot;;\r\n  onEnter(text: string) {\r\n    this.text = text;\r\n  }\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input #box (keyup.enter)=&quot;onEnter(box.value)&quot;&gt;\r\n&lt;p&gt;{{text}}&lt;\/p&gt;\r\n<\/pre>\n<p>&#8220;onEnter&#8221; event\u0131 &#8220;enter&#8221; tu\u015funa bas\u0131ld\u0131\u011f\u0131 zaman tetiklenecektir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/04\/Angular-4-Event-Binding.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/04\/Angular-4-Event-Binding.gif\" alt=\"Angular 4 - Event Binding\" width=\"212\" height=\"112\" class=\"aligncenter size-full wp-image-7672\" \/><\/a><\/p>\n<p>Benzer mant\u0131kla a\u015fa\u011f\u0131daki gibi farkl\u0131 bir tu\u015f kombinasyonuda belirleyebiliriz;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input #box (keyup.b)=&quot;onEnter(box.value)&quot;&gt;\r\n&lt;p&gt;{{text}}&lt;\/p&gt;\r\n<\/pre>\n<p>G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere &#8220;b&#8221; tu\u015funa bas\u0131ld\u0131\u011f\u0131 anda &#8220;onEnter&#8221; event\u0131 tetiklenecektir.<\/p>\n<p>Son olarak koleksiyonel durumlar\u0131 g\u00f6z \u00f6n\u00fcne almam\u0131z\u0131 sa\u011flayacak a\u015fa\u011f\u0131daki durumu de\u011ferlendirelim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  personeller = &#x5B;&quot;Ahmet&quot;, &quot;Ali&quot;, &quot;Yusuf&quot;, &quot;Ziya&quot;];\r\n  personelEkle(personel: string) {\r\n    if (personel) \/\/ Personel bo\u015f mu dolu mu? -&gt; TypeScript'te bu \u015fekilde direkt kontrol m\u00fcmk\u00fcn. \r\n      this.personeller.push(personel);\r\n  }\r\n}\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelerseniz e\u011fer &#8220;personeller&#8221; isminde bir string dizimiz mevcuttur. Ayr\u0131ca &#8220;personelEkle&#8221; isminde de ilgili diziye eleman eklememize yarayacak metodumuz vard\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input #txtpersonel type=&quot;text&quot; (keyup.enter)=&quot;personelEkle(txtpersonel.value)&quot; \/&gt;\r\n&lt;ul&gt;\r\n  &lt;li *ngFor=&quot;let personel of personeller&quot;&gt;\r\n    {{personel}}\r\n  &lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<p>Input&#8217;a girilen de\u011fer &#8220;enter&#8221; tu\u015funa bas\u0131ld\u0131\u011f\u0131 zaman tetiklenecek olan &#8220;keyup&#8221; event\u0131 arac\u0131l\u0131\u011f\u0131yla &#8220;personelEkle&#8221; fonksiyonu taraf\u0131ndan diziye eklenecektir. \u0130\u015fte b\u00f6yle durumda &#8220;ngFor&#8221; yap\u0131s\u0131 hemen tetiklenecek ve yeni eklenen veriyi de listelemeye dahil edecektir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/04\/Angular-4-Event-Binding-1.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2018\/04\/Angular-4-Event-Binding-1.gif\" alt=\"Angular 4 - Event Binding\" width=\"240\" height=\"320\" class=\"aligncenter size-full wp-image-7677\" \/><\/a><\/p>\n<p>Angular uygulamalar\u0131nda event binding mekanizmas\u0131n\u0131n ne \u015fekilde, hangi kurallarda cereyan etti\u011fini hafif y\u00fczeysel de\u011ferlendirmi\u015f bulunmaktay\u0131z.<\/p>\n<p>Umar\u0131m faydal\u0131 bir i\u00e7erik olmu\u015ftur.<\/p>\n<p>Sonraki 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 4 k\u00fct\u00fcphanesinde Event Binding olgusunu inceliyor olaca\u011f\u0131z. Tabi web programlama yahut &#8220;front end&#8221; ile az \u00e7ok ilgilenen her er ki\u015finin yabanc\u0131l\u0131k \u00e7ekmeyece\u011fi bir konuda oldu\u011fundan fazla detaya bula\u015fmadan ilgili k\u00fct\u00fcphanede&#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":7246,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2144],"tags":[2156,2146,2264,2267,2266,2265],"class_list":["post-7662","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-4","tag-angular","tag-angular-4","tag-angular-4-event-binding","tag-angular-event-binding","tag-angular-filtreli-olaylar","tag-event-binding"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/7662","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=7662"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/7662\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/7246"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=7662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=7662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=7662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}