Skip to content

Instantly share code, notes, and snippets.

@openopen114
Created May 9, 2017 09:18
Show Gist options
  • Save openopen114/9ea9379304fb569671bce3ed74b2542e to your computer and use it in GitHub Desktop.
Save openopen114/9ea9379304fb569671bce3ed74b2542e to your computer and use it in GitHub Desktop.
// cli
ng g service myData
//my-data.service.ts
constructor() { }
obj = {
id:"1",
name:"open",
rollno:"2233"
}
success(){return "Successful" ;}
//app.module.ts
import { MyDataService } from './my-data.service';
providers: [MyDataService],
//app.component.ts
import { MyDataService } from './my-data.service';
constructor(private newServices: MyDataService){}
ngOnInit(){
console.log(this.newServices.success());
console.log(this.newServices.obj);
}
//cli
ng g c product
//product.component.ts
import { MyDataService } from './../my-data.service';
constructor(private newServices: MyDataService){}
ngOnInit(){
console.log(this.newServices.success());
console.log(this.newServices.obj.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment