Question: Although I've been using python for a while, and a common pattern you see is these two statements:

```
def main():
    # Fancy code here 
if __name__ == "__main__":
    main()

```

My question is, why wouldn't you use this pattern instead?

```
if __name__ == "__main__":
    # Fancy code here

```

Is this just in case you want to import main from another place? Or is there some other reason you might want to do this?

Answer: 
If you want to share a value between components, you should do a [Service](https://angular.io/tutorial/toh-pt4) that will be injected in each component where you need it.

```
@Injectable({
 providedIn: 'root',
})
export class ResultListService {
  public myResultList: string;
}

```

*(With the `providedIn: 'root'`, it will be injected at the root of your app so it will be instancied only one time and the same instance will be shared among components)*

Then you pass it in the constructor parameters of your componenents:

```
export class SidebarComponent   {

  constructor(public resultListService: ResultListService){}

  // this.resultListService.myResultList
}

```
Component A- HTML

```
<button (click) = "changeFoo()">Change Value</button>

```

Component A- Typpescript

```
    import { SharedService } from './../../shared.service';
constructor(private sharedService: SharedService) {}

```

Component B-Html

```
<div style="margin:0; padding:0">
            {{xIsANumberVal == null? '' : "Value Passed From A Component 
            Comp(Parent): "+xIsANumberVal }}
</div>

```

Component B- Typescript

```
import { SharedService } from './../../shared.service';
 xIsANumberVal!: number;
constructor(
    private sharedService: SharedService
  ) {}

ngOnInit() {
    this.receiveValueFromService();
  }

    receiveValueFromService() {
        this.sharedService.valueSource.subscribe(value => {
          this.xIsANumberVal = value;
        });
      }

```

Shared Service

```
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class SharedService {

  xIsANumberVal: number = 5;
  valueSource: Subject<number> = new Subject();

  get abc(): Subject<number> {
    return this.valueSource;
  }

  constructor() { }

  changeFoo(xIsANumberVal: number) {
    this.valueSource.next(xIsANumberVal);
  }
}

```

Working Example: <https://stackblitz.com/edit/github-u6xvad?file=src%2Fapp%2Fsecond%2Fsecond.component.ts>