Sunday, 29 November 2015

Difference between ng-model and ng-bind

ng-bind has one-way data binding ($scope --> view). It has a shortcut {{ val }} which displays the scope value $scope.val inserted into html where val is a variable name.

ng-model is intended to be put inside of form elements and has two-way data binding ($scope --> view and view --> $scope) e.g. <input ng-model="val"/>.

7VhPb+I+EP00HCuRP6TtEbrt/i4/aaVK3bNJTGLhZLKOKdBP33E8SXAClG6p2q7KAezx2J6Z9/yCMwpu8s1Pxcrsf0i4HPnjZDMKfox8/+pqjN/GsLWGyRh7xpAqkViT1xnuxRMnI81LVyLhleOoAaQWpWuMoSh4rB0bUwrWrtsCpLtrydJmx85wHzM5tP4Wic4oLT/q7P9xkWbNzl50bUfmLF6mClYF7Tfyg0X9scM5a9aiRDdj2/U9KtCWDAEtWLLCCekJIHcMildd+Shd4VakYI9OX4pi6RZoDirhaiey4BbRVQC4kGnlmxsuDcINejb8uwOjbfkULyiU4xOimF+GXsiicTyPkmv/ggr9yOSKcrOGSm8bjHiCkFEXlM4ghYLJ2846q3HgZgss6izTucSmh81KK1i2yBoLL5Kp4Q125xLipTXdCYyydSCaeqZrozEhHMyYTBWsVExegzRD4jZTKadpA59JiweeNg4512pb4y6ZFo/u/oxgTVu/rujYoLqfiAEF52AQSQxztgBMcheM6M/KUKUeuLB8nKKDd1VuukFspfY3rGIoebMaBmYXbIZ7QHcwmsqvM6H5fcnqmq5RfXrQZiypYTSdVLLKVMTAP8Sc0uNKc9KtQygOq08TUBPo2Db6Red63amG15z1bEcxIrKdFbCaKe8A2IPg638QrBaEDwGLYvlqCndUzuiZdVTOmkf8CbidLHH1VMyOmVmNQwmi0NXOyr+MoaPDZNyjQ/8Z9Tp/bNgIOjq0qfwdQ6ia3/p7+EiHl59JfxtqfwvwaWh9rACjyn1uBV5IUT441X/5/+ZbRXSoepPeCetjYR8INOuYfPYWGoBqnxqDhV4t6/19XpL14/7nl/XmprfDuyK9mAu8Mvbph0fNnPEBq25AgrmtFVAYDi6QQj0TkyI1F8cY6WEudjNzcAVecKc0MAetzU1yr0IAei9kzdRMJAnHCTtEPyocRpuIxFhI6lNGl+f4E+cFDlzhHgmZ7JGQ4F0khGJ5g+Bj7nsEHwmR23cqp4n+VyXKGYkR9s7xOxIDu92rESsJ3Vuw4PYZ

DEMO

Talking between Controllers using $emit, $broadcast and $on in AngularJS

AngularJS provides $on, $emit, and $broadcast services for event-based communication between controllers.

7ZlRc6o6EMc/jY/tABG0j7XtaV/uzJ1x5pxzHyNEZIrEG7BqP303yQYIUFu97UV76oPDbmCT/PcHZMmA3Cy394KuFn/xiKUDz4m2A3I78Lzx2IF/6dhph++AJR2xSCLtcivHNHlm6MTr4nUSsdw6seA8LZKV7Qx5lrGwsHxUCL6xT5vz1O51RWPTY+WYhjRte38lUbHAaXlB5X9gSbwwPbvBlW6Z0fAxFnydYX8Dj8zVTzcvqYmFE906GMHX9s7YY9NTZo3omfOl5RAsr9TD2Sa2IBl9suw0yR5tfWZcREzUBkbuILmCcwgkj5bbG5bKBJvk6dH/eKW1VE+wDIey/wLPGxI/cD3HJZE/I+QCIzzRdI1zG3hDOZ5pyFdMN+bFzqQLogEZYEw2i6Rg0xUNZcsG2ATfolimYLlwqDLDZK/Syhc04hs04pTmUhVIwCQvBH8sMw9yTFZMJEtWMCFjJ1mMJ+IwmSgYot8xd+XCid8zDmHETqZetxKfYOrNraLNTcUdCKN9ixpz5hajmMq4jFwJDQeo9Tt1x7vU1j3/XzT/ACndK9QEpXRHfWqJabW1HHhBCp1Ocnlje0GsjrW+ugG6qbedg+y+kfQkZMcHqSV7W/MK67OV3XVs2YmRuBfZ8c349Wn3glOSffSnPmT6lR1XZ19f9uZDZtir7KY8sHRviphF17ICACuUWiShrR1MXOx+o0LK+MeSi0Wt0qAhFnTH10KlZs/ataAiZnhZ99qgLXpNVLMMrGtqfIKltEie7GF2CY09/M0TmEC14jS5wZyWVZcJoaeHV9WX7W8FIs7lyHWC0dh1x4E/HOFLwcTVkrTiKgxKFY4ko6tiOJaM0uiBDDXsbzI+kIyudfjRz4xL/5PYwFHuZUO97Ptiw2+klJg3w6FstAJ5/bEB7+wzYAMHtZcNVfb0xUYZ57+y0QrUIxtdheR5sqFE+2bjA9noqnZPjw0keC8bqpLpiw23UUsPTdxD2WgFGvXHRldtqOu/OVdjriAJ/l3LT+yq4UJ/x7+GE7zhals11j5ZzQSnUUhziFJWlDroaxXlGxDaH7qlZ56k6Q1Pud4NMJsX5sxai6N+uvyEEpfcqn2XA+DtCzrDgkGlWam+l7lGnCa6n4kYbjZ9BmJsCbtHJ0zXHD6RPOBjUh7/xMgnT50ppQx2AT6dD8auEYg04hzNHZjVjp8+vdrbJXcv

The key thing to remember when using $scope to fire your events, is that they will communicate only with immediate parent or child scopes only! Scopes aren’t always child and parent. We might have sibling scopes. Using $scope to fire an event will miss out sibling scopes, and just carry on up! They do not go sideways!

So to solve this problem we can use $broadcast and $emit.

$broadcast

We could fire an event down from ParentCtrl to SiblingOneCtrl using $broadcast:

$emit

If we wanted to communicate upwards, from SiblingOneCtrl to ParentCtrl, you guessed it, we can use $emit.

Sunday, 8 November 2015

What is AngularJS ?

AngularJS is a JavaScript framework which simplifies binding JavaScript objects with HTML UI elements.

Let us understand this with a simple Example.

So if we analyze the above code (Control Binding In Plain Javascript) visually it looks something as shown below.

5Vlbc9o6EP41PKaDbS7mMdA0fTnTzuTMtH0UtrDVyBaVZS759ZGsFbZsTAzBzckJDyCt1quVvo+9wMBbJLt7jtbxPyzEdOAOw93A+zxwXd8fyncl2GvBeChnShBxEmqRUwoeyBMGITwX5STEmaUoGKOCrG1hwNIUB8KSIc7Z1lZbMWrvukaR2bEUPASINqU/SChiOJY7KeVfMYlis7MzmemVJQoeI87yFPYbuN6qeOnlBBlbcNDdUE89X8/3MB+NzE6p5dETY4kl4Dgrbw9OS+wLSdHG2pOS9NG+nyXjIeYVJe9OgssZk4bUKNktMFUAG/DGvjdbzoLVauIGsyme3mjTX7qqH+6X4xScfa1JAGCDaA7XoQWZ2BtUcShBhinjImYRSxG9K6XzAjmstpA4zGORUDl05BDviPgJYjX+pcafxmqWCr5XS4Wamui1qVrULqh9a7w6cW7QyVjOA3isoQNsEYhHuM1OcX64vHvMEixdU4zT6q4LFwbfUMebwtcHqBEdHjlY+c6I9Lq7CX0EeKqKZd2QVzPkj21D+pwNQ7ecI3Uko7ZWCllVQw4qhy9FBZk6EgsO1ROx+mIIOHmSIUU0azKEY4oE2dgOtdKiHYSOYLv6gjuTw9aXA+3B1fCGm7PwnlB5h/MVKxwrgZ/8yVWILBZudBy+lQruaL0rF+UoUp//7kSeYZ6iBBuD0jdtU2s0eFWyRlFlGxOBH9aowHwr867NpCxGIdvCJKIoU4Aotq0IpQtGmQ7wJh/JBwRnj7iyMixeB0c2mAsMKHSmZWvAqcM4hO/4tsyvjikb4mpuNWnrGAOt7/k5IEMir4CcE1lhLH+rauL/DIM7ruHgeE0czJVXcfD6gMFsfuUkrRMzpOlDXq4smTTdZwTukqMLnVdE4IsvHpyr8F9zX7CcfCz+m5jzNvwHo1dPNos8E9I//hEzzchUaP+NVOPAifrqTFr6DxMCm11Lr52JYfQlYe9QKUBWuLw1Gbk1E7NaR9G1NfH8Fwy9aWviHKtVr59PzbgkVl/saelI2sCAVuAMYrxooisxGkGmbuhsYrQ4PD2vXWrzq7d2yYFfqk5yMA3lrkXKCFS6IEFLDIPgVIax13Htku63kiTGR3KEkZ3XJL8Iqzz2RTSsVTM3k27h6SrAw1bvDviW7POXgPffP/DN5vncotXxjxWtc5KGJI3k+jdoxLsVr7J2VPJqhWoVnClLVZ6rVqcgQpRE6gf2QDJK/QA+V5Uokf8D3MJCQsKwSJLHSmImtVe0YHcs9bB8oJJMT1bKvfzCUvuJZXSk7D3G7As6Gzkt/x3QnCr/B/LungE=

And if we analyze the code (Control Binding In Angular1) visually it looks something as shown below.

7Vjvb9o8EP5rkLYP70QwpPQjUNZOWrVq7dp3H93YJFZNjIz51b++5+RMnIS2rC2lSEUIxefz2X6ex2cuDTIYL081nSTninHZaDXZskFOGq1Wt9uEX2tY5Y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components are the main way we build and specify elements and logic on the page.

In Angular 1, we achieved this through directives, controllers, and scope. In Angular 2, all those concepts are combined into Components.

To build an Angular 2 application you define a set of components, for every UI element, screen, and route. An application will always have a root component that contains all other components. In other words, every Angular 2 application will have a component tree, which may look like this:

5VhPb6M+EP00HHcFGGhybLtp9/KTVuphd48OTMCqwcg4f+inrw3jEIemza9VmkabQ5R5NmP7vWePiUduy829pHXxn8iAe6GfbTzywwvDycTX3wZoeyD2dWSAXLKsh4IBeGBPgCA+ly9ZBo3TUQnBFatdMBVVBalyMCqlWLvdFoK7o9Y0tyMOwENK+Rj9zTJV4LLCZMB/AssLO3KQTPuWOU0fcymWFY7nhWTRffrmktpcuNCNjxkSBFoEYkxY08qZ0pMQpQNIaAb6cLnMZaSiKyfmrHp0CZoLmYHcmRmZaXWlEDqR+VVuboEbha16YeKHizidJHQaTefz4Fs//btju28JllDhZD+aEh22onyJdFzXNWcpZYqJqm9sVGsl7kQCkyzwyM26YAoeapqa1rX2tMYKVXJsbgqaiTUGOaeNoU8rdYNjglSA3j9mZV0fXNY9iBKUbI0ZsPsEc+DmsdZYD04MrH+KHRfafhS1zbeZBxr1D2TySFbJiNU7xhXI5oIIDRKX0MAeT2dhNBoxOitrLlrQB97lcBr5X4nT+CCnl7Tvp7YG9DGx1fAslGKpu2xKoy9F6dWI0hGVUGXX5v6io9Rww1KXPU2EbP8Yxr7HNvyLBMKGqZ0mHZkW81Q/DGSjS89bxOq5iaXslHyl5CoqcziUpysgY4F2BIhf4N9iEjhVbOXO+yVRcIRfgukVDVvKamtPKbKna788fGr3trGf6MpNZE87m6enYJSns8h21e9zzeRfdE1XJM/lGhLt1bb90+BY15AYxTtkvxPaBt8fPmSbT7fGWWW3tWHv2v3/RT9Qcz5BdDvUaVR/7Rg5qSPeOCy6q8q5XBNt39xxdtE7fbO9QWMiW3E+bBsdDm/yfffhTxsyewY=

LET US SEE A SIMPLE COMPONENT