Sunday, May 28, 2017

some stuff I learned from an Angular 4 training this weekend

  1. The selector property for a Component decorator does not have to be tag-named-based. '.whatever' will allow for <div class="whatever">swap me out</div> and '[whatever]' for <div whatever>swap me out</div>.
  2. btn btn-primary are some Bootstrap styles.
  3. FormsModule from @angular/forms may be required for: [(ngModel)]
  4. (input) is an event for an input fill-in-the-blank field.
  5. @Directive({
       selector:'[whatever]'
    })
    export class DoSomething {

    may be called out to like: <div whatever>swap me out</div>
  6. <p *ngIf="hasCondition; else myHashtag">foo<p>
    <ng-template #myHashtag>
       <p>bar</p>
    </ng-template>

    ...shows off an if/else at an *ngIf for the bar paragraph will show if not hasCondition.
  7. Math.random() in JavaScript gives a decimal between zero and one that is... random.
  8. <p [ngStyle]="{backgroundColor: giveColorForBackground(), 'margin-left':'10px'}"> shows off ngStyle. Note that you are handing in a JSON object full of properties and each property is a style. If the property name has a hyphen you either have to give the name in camel case without the hyphen or wrap the name in quotes.
  9. <p [ngClass]="{whatever: myThing==='foo'}"> shows off ngClass. Here, again, a JSON object. Each property name is a class name and the value for each property is a conditional for whether or not to apply the class defined in the class name.
  10. <p *ngFor="let mouse of mice; let i = index"> shows off having an index variable at an *ngFor and this is actually not something that I learned from the training. I already knew this, but I found myself wondering if I had every included it at this blog. If not, here it is now.

No comments:

Post a Comment