Skip to content

Instantly share code, notes, and snippets.

@dahlsailrunner
Last active April 28, 2023 08:34
Show Gist options
  • Save dahlsailrunner/b4574db2d17280f573f2d78e372f589b to your computer and use it in GitHub Desktop.
Save dahlsailrunner/b4574db2d17280f573f2d78e372f589b to your computer and use it in GitHub Desktop.
TCCC 2019 Notes

Repos:

Notes from code are below.

Slides are here: https://github.com/dahlsailrunner/tccc2019-api-starter/blob/master/Tccc2019-EmpowerDevs.pptx

Demo notes

---------------- Sample model --------------------------
public class Sample
{
	public int Id { get; set; }
	public string Name { get; set; }
}

----------  SampleController ----------------------------
[HttpGet]
public List Get()
{
	return new List
	{
		new Models.Sample {Id = 1, Name = "Erik"},
		new Models.Sample {Id = 2, Name = "Dahl"},
	};
}
---------------------------------------------------
-- Angular ----------------------------------------
ng g c sample
ng g s sample/sample -f

---------- sample.service.ts  ------------
  apiRoot = environment.backendApiRoot;

  constructor(private http: HttpClient) { }  

  public getSamples(): any {
    let  apiUrl = `${this.apiRoot}/sample`;
    return this.http.get(apiUrl);
  }
---------- sample.component.ts ------------
sampleResponse: string;

constructor(private pageSvc: NewPageService, private alertSvc: AlertService, private smplApi: SampleService) { }

ngOnInit() {
	this.pageSvc.setNewPage("Sample Page - Here We Are!");

	this.alertSvc.createAlert({
	  alertClass :"alert-info",
	  alertMessage: "Wowzers!",
	  alertLink :"",
	  alertLinkText : ""
	})

	this.smplApi.getSamples().subscribe((results) => 
	{
	  this.sampleResponse = JSON.stringify(results);
	});
}  

-------- sample.component.html -------------

sample works!

{{sampleResponse}}
------- app-routing.module.ts --------------- { path: 'sample', component: SampleComponent, }, ------ app.component.html -------------------
  • Sample
  • Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment