TypeScript : Colon vs Equal To ( Angular Tutorial )

后端 未结 6 1807
Happy的楠姐
Happy的楠姐 2020-12-06 10:35

I am learning Angular4 and going through the tutorial examples.

https://angular.io/docs/ts/latest/tutorial/toh-pt1.html

I have the below code in the tutoria

6条回答
  •  感情败类
    2020-12-06 11:15

    export class AppComponent { 
        title = 'Tour of Heroes'; // here you assign a value to var.  
          hero: Hero = {
          id: 1,
          name: 'Windstorm'
        };
      }
    
    export class Hero {
      id: number; // <= here you are declaring a var to be a string but without value
      name: string;
    }
    

    you don't need to declare primitives if you assign there value immediately (number, string, boolean).

提交回复
热议问题