lundi 20 novembre 2017

Angular 2: Best way to declare and initialize variables

I am studing Angular Style Guide, but I have a doubt, what's the best way to initialize a variable in component?

For example, I declare a variable like this:

export class MyComponent implements OnInit {

  myModel: MyModel= new MyModel();

  //...
}

Or like this:

export class MyComponent implements OnInit {

  myModel = new MyModel();

  //...
}

Or this:

export class MyComponent implements OnInit {

  myModel: MyModel;

  constructor() {
    this.myModel = new MyModel();
  }

  //...
}

Or another best way? Here's the Style Guide I was reading.

Aucun commentaire:

Enregistrer un commentaire