Skip to content

Instantly share code, notes, and snippets.

@xthecapx
Created July 8, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xthecapx/bbdd919bec12a1d74645dc203a92da91 to your computer and use it in GitHub Desktop.
Save xthecapx/bbdd919bec12a1d74645dc203a92da91 to your computer and use it in GitHub Desktop.
// New instance of the service with new instance of the component
@Component({
selector: 'app-component',
templateUrl: './app-component.component.html',
providers: [ MyService ]
})
export class Component {
constructor(private serive: MyService) {}
}
// Same intance of the service available to all components
@NgModule({
imports: [ Component ],
declarations: [ AppComponent, Component ],
bootstrap: [ AppComponent ],
providers: [ MyService ]
})
export class AppModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment