Last active
December 19, 2018 15:01
-
-
Save mtherien/44acba21608398d392a1f468090de626 to your computer and use it in GitHub Desktop.
Typewriter TypeScript template for Angular service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ${ | |
| using Typewriter.Extensions.WebApi; | |
| string ReturnType(Method m) | |
| { | |
| if (m.Type.Name == "IHttpActionResult" || m.Type.Name == "IActionResult") | |
| { | |
| return "void"; | |
| } | |
| if (m.Type.Name.StartsWith("ActionResult<")) | |
| { | |
| return m.Type.Name.Replace("ActionResult<", "").TrimEnd('>'); | |
| } | |
| return m.Type.Name; | |
| } | |
| string ServiceName(Class c) => c.Name.Replace("Controller", "Service"); | |
| }import { Injectable } from '@angular/core'; | |
| import { Observable } from 'rxjs/internal/Observable'; | |
| import { HttpClient } from '@angular/common/http'; | |
| module ClientApp.Services { $Classes(:BaseController)[ | |
| @Injectable(({ | |
| providedIn: 'root' | |
| }) as any) | |
| export class $ServiceName { | |
| constructor(private http: HttpClient) { | |
| } $Methods[ | |
| public $name = ($Parameters[$name: $Type][, ]) : Observable<$ReturnType> => { | |
| return this.http.get<$ReturnType>(`$Url`); | |
| };] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment