Delegates are one of the most used features of C#. It allows you to pass a function as of function pointer. It is kind of same as function pointer of C++.
Put simply, delegates are the same as a function pointer of C ++. It refers to another function.
As noted in Microsoft official documentation:
“A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.”
Before get deeper into technical jargon about delegates, let us create first a delegate.
Let us talk through the above code.
On running above, you should get output as shown in the below image:
One important thing you need to keep in mind is that the signature of delegates must match with the signature of the function pointed by the delegate. Not only signature, but also return type should match.
In Angular, it is essential to know how components communicate with each other. If you use a component inside another component, they create a parent child relationship. In such a scenario, parent and child components communicate to each other in following ways:
To understand this using an example, create a service. In the service, create a variable called count. Service will share value of count variable across the components. Before we create count variable, let us talk about requirement again. We want all components to access last updated value of the data shared using the service.
For this, we have to wrap the count variable in RxJS subjects. To be precise let us use BehaviorSubject.
We are using BehaviorSubject for the following reasons:
Each variable with assigned value has a type. Let us consider the code listed below:
As you can see in the above snippet, if there is no value assigned then type of variable is undefined.
So far so good, we saw that variable with no assigned value is undefined. Let us consider the next code snippet:
We have created a variable koo and have not assigned any value to it. Now both value and type of koo are set to undefined.
So you want to write your first Angular application, however setting up even a ‘Hello World’ Angular application is not easy. It requires many steps such as:
You can perform all these tasks manually, but this will require a strong understanding of all these concepts and will make starting a new project very time consuming. To solve this problem, Angular comes with the Angular Command Line Interface (CLI).
Learn more about it here: https://cli.angular.io/
All these tasks are taken care of by Angular CLI, which is a command line tool for creating, testing, and deploying Angular apps. It is recommended to use Angular CLI for creating Angular apps, as you do not need to spend time installing and configuring all the required dependencies and wiring everything together. It provides you with many boilerplates and saves your time.
I am very excited to share that today I completed 11 years working in the industry. It has been a learning and good challenging journey for me. During last 11 years, I have lived in three different cities and worked on six different technologies. I started my career as Software Engineer and currently working as a Developer Advocate for Infragistics.
Below in tabular form you can find my work experiences:
Besides working for various organization, since very beginning of my career, I have been writing articles. So far, in last 11 years I have authored more than 900 articles. You can read them on my blog: https://debugmode.net/.
I also authored a book on Angular called Angular Essentials.
Outside India, you can get it here : https://www.amazon.com/Angular-Essentials-Dhananjay-Kumar-ebook/dp/B07NL5RSDF/ref=sr_1_1?keywords=angular+essentials&qid=1553590883&s=gateway&sr=8-1
Due to my contributions, Microsoft awarded me prestigious Microsoft MVP Award on 1 April 2010. Since then, I have been getting Microsoft MVP Award each year. So far, I have been awarded 9 times. You can find my MVP profile here: https://mvp.microsoft.com/en-us/PublicProfile/4028360?fullName=Dhananjay%20Kumar
After getting Microsoft MVP Award, I started participating as speakers. I got chance to speak in various Microsoft User Group meets and conferences. So far, in last 11 years, I have delivered 77 free talks or workshops. You can find details about them here: https://debugmode.net/speaking/.
In 2016, I founded offline community geek97 , thorough that we hosted free workshops in various Indian cities. We also mentor young talent to become speaker and community contributor.
Winner of 9 Microsoft MVP Awards
I also did welcome note for the conference, which can be find here:
You can find all talks from ng-India 2019, on geek97 YouTube channel
Thanks for watching my talk. Let me know your feedback.
Arrow function was introduced in ECMA 6. It is different than function statement or expression , as it does not have its own ‘this’ , and can also not be used as constructor. Some important points about Arrow function are:
I have written a detailed article on Arrow function here :
Watch this video to learn more about Arrow function
Please do not forget to subscribe geek97 YouTube channel geek97 YouTube channel for update about future videos.
THANK YOU, for being with me in 2018. It was another good year due to your Support, Trust, and Love. Besides, you, I would like to thank my employer Infragistics and my boss Jason Beres that they gave me opportunities to contribute to developer community.
If you are an Angular developer, you may want to check fastest native Angular component library Ignite UI for Angular.
In 2018, I wrote articles, delivered talks in small meetups or big conferences, organized conference of 400 developers.
Organizing ng-India was a kind of learning yet motivating experience. Since this was first ever-Angular specific conference in India, I had my doubts. However, everything went as planned. We sold all 300 tickets in less than one month and was joined by speakers from all across India. From printing goodies, printing T-Shirts, doing social media, to receiving speakers at AirPort, to delivering two talks, I had fun in almost everything in ng-India.
I must thank all sponsors, volunteers, and speakers of ng-India. Without them, it was never possible. A special thanks to Shivprasad Koirala and Questpond for their trust in ng-India. Yes, finally yet importantly a big thank to vibrant Angular community for all motivation.
I delivered 11 talks in 2018. To deliver these talks, I travelled to six Indian cities and a country Nepal. Out of 11 talks, five talks were in big conferences such as ng-India, ng-Nepal, Pune Developer Conference and five talks were kind of workshops hosted by me in various cities. I also did one webinar for ng-Frankfurt.
Also in 2018, I got Microsoft MVP Award, which was ninth MVP Award for me since 2010. I have been getting it every year since 2010. I also had opportunity to attend MVP Summit in Seattle.
If you are reading my blog since 2010 and wondering, how I look on 31 December 2018, below photo is taken today
With all happiness, I wish you Happy New Year 2019. Keep learning, writing, teaching, and implementing. I am very excited for 2019. Happy Coding.
Thanks with Regards
There are two important keywords in the above sentence:
Before we go ahead and understand purpose of Object.assign, it is essential that we really understand these two words, enumerable properties and own properties. Let us see them one by one:
There are two properties in babycat object. By default both are enumerable, hence as the output of for..in loop, you will get both age and name printed.
Now let us change default enumerable behavior of age property using Object.defineProperty method.
We have changed enumerable of age property to false, so as output, you will get only color printed. Hence, age is no longer an enumerable property of babycat object.
In above code snippet, there are two objects cat and babycat. In addition, [[Prototype]] property of babycat object is set to cat object. When you print properties of the babycat object using for..in loop, you will find as output age, color, name printed as shown in below image:
You should able to infer what exactly above sentence implies. Consider code below :
Using Object.assign() method , we are copying cat object own enumerable properties to babycat object. Here, cat object is source and babycat object is target. You will get output printed as below:
The Object.assign() method uses [[Get]] on the source object and [[set]] on the target object and invokes setter and getter to perform the task. Essentially, it assigns properties values from source to target object. It does not create new property in the target object.
As of now you know purpose of the Object.assign() method. Let us examine some variations while copying properties from source object to a target object.
If target object has same properties as of source object, then Object.assign() method will override target object properties. To understand it consider code listing below:
There is age property in both target object and source object. While copying properties in target object the Object.assign() method will override target object age property, hence you will get output as shown in the below image :