2.1 Home controller

/**
 * Controller example
 * @constructor
 * @function
 * @name HomeController
 *
 * @description
 * Define controller, assign action and inject your services.
 * Each request create new instance of controller, your Injected type is injected by top level injector if is not defined
 * as local instance as providers to this controllers.
 *
 * Controllers can be Inherited by thy don't necessary need's to be inherited
 */
@Controller({
  name: "home"
})
export class HomeController {

  @Inject(Assets) assetLoader: Assets;

  @Inject(Request) request: Request;

  @Inject(Router) router: Router;

  @Inject(TemplateEngine) engine: TemplateEngine;

   /**
   * @function
   * @name fileLoadAction
   *
   * @description
   * This action loads file from disk
   * \@Produces("image/x-icon") -> content type header
   */
  @Produces("image/x-icon")
  @Action("favicon")
  faviconLoader(): Promise<Buffer> {
    return this.assetLoader.fileLoadAction("favicon.ico");
  }

   /**
   * @function
   * @name beforeIndex
   *
   * @description
   * Index action chain
   */
  @Action("index")
  myActionIndex(@Chain data: string): Promise<string> {
    return this.engine.compileAndRender("home", {
      data,
      name: "this is home page",
      title: "Home page example"
    });
  }


}

results matching ""

    No results matching ""