Skip to content

Commit

Permalink
Put space between # and headline to aligh with github md specs
Browse files Browse the repository at this point in the history
  • Loading branch information
David Losert committed Nov 2, 2017
1 parent f12e60f commit 8d8ddcb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions class.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Class


##Class Definition
## Class Definition
Class is a special programmatic structure. It is defined with **members** which can be **properties** (variables) and **methods** (functions). Then instances of the class are created, usually by calling the ```new``` operator on the class: ```let myInstance = new myClass();```. The instance created is an object on which you can call the class methods and get and set its properties' values. Multiple copies can be created from one class.

###In Angular...
### In Angular...
Angular takes care of creating instances of the classes you define - if they are recognized as Angular building blocks. The decorators make that connection with Angular.

Each time you use a component in a template, a new instance of it is created. For example, here three instances of the inputComponent class will be created:
Expand All @@ -18,7 +18,7 @@ template: `

Let's take a look at the class ```inputComponent```.

###implements OnInit
### implements OnInit

First, you see something was added to the class declaration:
```ts
Expand All @@ -38,12 +38,12 @@ ngOnInit() {

You can use this method without explicitly indicating that the class implements the OnInit interface. But it's useful to use the implementation statement. To see how, delete the `ngOnInit` method. The IDE will tell you there's an error - you must implement `ngOnInit`. How does it know that? Because of `implementing OnInit`.

###constructor
### constructor

Another method we haven't seen in the `todo-root` component is the constructor. It is a method that is called by JavaScript when an instance of the class is created. Whatever is inside this method is used to create the instance. So it is called before `ngOnInit`.
> A strong feature in Angular that uses the constructor is dependency injection. We'll get to that later on, when we'll start using services.
###Properties
### Properties
The property `title` we added is used to store a value, in our case of type string. Each instance of the class will have its own `title` variable, meaning you can change the value of `title` in one instance, but it will remain the same in the other instances.

In TypeScript we must declare members of the class either in the class body outside any method, or pass it to the constructor - as we will see when we will use services.
Expand All @@ -66,7 +66,7 @@ constructor() {

Try changing the value of `title` inside the method `ngOnInit`. Which value will be displayed on the screen?

###Methods
### Methods

Let's add a method that changes the value of `title` according to the argument we will pass. The method will have one parameter of type `string`. Add inside the class body (but not inside another method):

Expand Down Expand Up @@ -95,7 +95,7 @@ constructor() {

You can try calling the method with different arguments (the string passed inside the brackets) from ngOnInit. Try calling it before or after assigning a value directly to `title`. Try calling it a few times from the same method. See the result in the browser.

###Debugging Tip
### Debugging Tip
You can always use `console.log(someValue)` inside class methods. Then the value you passed as an argument will be printed in the browser's console. This way you can see the order of the execution of the methods and the value of the argument you pass (if it's a variable). For example:

```ts
Expand Down

0 comments on commit 8d8ddcb

Please sign in to comment.