Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. I need help in defining and calling Static variable in Typescript.

I need help in defining and calling Static variable in Typescript.

Scheduled Pinned Locked Moved JavaScript
javascripthelpquestion
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Afi_sh
    wrote on last edited by
    #1

    export class myClass implements OnInit {

    counter=0;
    static counter:any;

    onListItemClick(PackDef: PackDefinition): void {
    this.itemClicked.emit(PackDef);
    this.counter++;
    console.log(this.counter);

    and

    import { myClass } from '../../../';
    dialogRef.afterClosed().subscribe((result: any) => {
    this.saveMyMethod();
    console.log("Final1"),
    console.log(myClass.counter);
    });

    saveMyMethod(): void {
    console.log("Final2"),
    console.log(myClass.counter);

    Do you know why I cant have correct counter after "Final1" or "Final2"? but I have a correct counter in myClass.

    J 1 Reply Last reply
    0
    • A Afi_sh

      export class myClass implements OnInit {

      counter=0;
      static counter:any;

      onListItemClick(PackDef: PackDefinition): void {
      this.itemClicked.emit(PackDef);
      this.counter++;
      console.log(this.counter);

      and

      import { myClass } from '../../../';
      dialogRef.afterClosed().subscribe((result: any) => {
      this.saveMyMethod();
      console.log("Final1"),
      console.log(myClass.counter);
      });

      saveMyMethod(): void {
      console.log("Final2"),
      console.log(myClass.counter);

      Do you know why I cant have correct counter after "Final1" or "Final2"? but I have a correct counter in myClass.

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #2

      Afi_sh wrote:

      counter=0; static counter:any;

      Took a look at that part real closely.

      Jeremy Falcon

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups