Posts

Showing posts from December, 2019

Web Api Create method with multiple parameters

Also, how to overload a method, say GET or PUT?

Well, lets start that with simple settings, you can't. Too many resources with partial examples makes you sometimes believe that it should be that simple (and maybe it should?), while its not.

It's also not that complicated...


Part 1 - understanding default design

When you create a new Web Api project (in vs 2017 Web Application -> empty, mark web api) you get basically nothing but the "WebApiConfig.cs" withing the "interesting" line is
routeTemplate: "api/{controller}/{id}",

And that means that whatever controller you create by default can only have it's 1st parameter, as in the url part, as "id". You cant create a method sending something like "string name".

Next step will be creating a controller class (with the (v2.1) in the end) and you will always get the suggestion of "ValuesController1". You cannot have the end of the controller name other than "Control…

How to access ngFor variable from child component or directive

the answer is ViewContainerRef

when you inject it into your constructor it has so much data in it. the ngFor data is in
this.vc['_view']['context']['$implicit']
directive full example

@Directive({
    selector:'td'
}) exportclassAddInvAmountBtnDirectiveimplementsAfterViewInit {
  el:HTMLElement constructor(ref:ElementRef, privatevc: ViewContainerRef) { this.el = ref.nativeElement   }

  @HostListener('click', ['$event']) tdClick(ev: Event){ console.log('vc._view.context.$implicit',
         this.vc['_view']['context']['$implicit']); ev.stopPropagation()   }
}