Wednesday, May 24, 2017

Put a ViewChild wireup for an Angular 2 component just inside of the class curly braces.

...and not in a method, constructor, or lifecycle hook. This should be just like making a component-wide public variable.

How may I tell where NuGet is putting stuff?

In Visual Studio 2015, go to: Tools > NuGet Package Manager > Package Manager Settings ...and then click the "Projects and Solutions" option at the upper left.

.toPromise() off a or this.http.put Observable implementation is legit.

You may then chain .then() onto .toPromise() to use the Promise API. There is also .catch() which seems to only manage the right half of .then() if you will, the second parameter.

Keep an a tag from redirecting in Angular 2.

<a href="#" (click)="go($event); false">whatever</a>

This can be advantageous. This in lieu of not having the href parameter and forcing the a tag to behave as if the href were there with a different styling that does cursor:pointer; and whatever else you need to hack a sick a tag into behaving as if unsick. What is more ghetto?

Tuesday, May 23, 2017

Use a pipe inside of TypeScript and not just Angular 2!

We could revise this module such that the @NgModule decorator had a "providers" property like so:



...and give the module a constructor like this:

constructor(pipe: SimpleDatePipe){
   let whatever = new Date(1974,8,24);
   let revamp = pipe.transform(whatever);


This would work! If the pipe's transform method took more than one parameter at its signature, that too is easy to accomodate.

constructor(pipe: SimpleDatePipe){
   let whatever = new Date(1974,8,24);
   let revamp = pipe.transform(whatever,"hey");


...and yet, you probably do not want to use pipes beyond the templates like this. This is gross.

Force a refresh with a zone?

Assuming zone: NgZone at component's constructor (in TypeScript in Angular 2), this can be a hacky way to force a component to refresh if the watchers aren't doing their job for some reason. => {


Addendum 5/24/2017: public zone: NgZone or private zone: NgZone would be needed at the constructor to make this work somewhere beyond the constructor. Also note NgZone is kept in '@angular/core'

You can't use super outside of a constructor in TypeScript.

If you just call super(); there (the constructor) it should call the parent's constructor. You may call a parent's constructor with parameters too. But you cannot have Anaconda inherit from Animal and have its own Eat method which calls the Animal Eat method and then does some regurgitate mechanics.