Angular2

  1. How do you listen to an event?
    • enclose the event type in brackets, then call it's method name
    • eg.
    • (click) = "changeName()"
  2. How to construct a function that returns an Object in Typescript
    • function getTypes<t>(value: T): string {
    • }
  3. 2 kinds of Directives
    • Structural (*ngIf)
    • Attribute (*ngClass)
  4. Structural directives is indicated by __?
    • *
    • eg. *ngFor, *ngIf
  5. What's the syntax for 2-way data  binding
    [(ngModel)]
  6. Where do you add the selectors?
    html
  7. how to assign a type variable
    let name: string = "Orly"
  8. How to construct a void function in typescript
    • function setName(name: string): void {
    • }
  9. this keyword is used to indicate that variable can be assigned to any data type
    • var
    • eg. 
    • let anything: any = 'sicat'
  10. How to register services with Injector and DI
    • @NgModule({
    • providers: [EventService, ToastrService]

    • -=-=-
    • constructor(private eventService: EventService)

    • -=-=-
    • ngOnInit() {
    • this.events = this.eventService.getEvents()
    • }
  11. How do you import components? And use destructuring at the same time
    import { Vehicle, VehicleService } from './vehicle.service';
  12. The 4 types of Databinding
    • String interpolation eg. {{data}}
    • Property binding eg. [property] = "data"
    • Event binding eg. (event) = "expression"
    • two-way binding eg. [(ngModel)] = "data"
  13. We use ___ to organize our application into cohesive blocks of related functionality
    • NgModule
    • eg:
    • @NgModule({
    • imports: [
    • BrowserModule
    • ],
    • declarations: [
    • EventsAppComponent,
    • EventsListComponent,
    • EventThumbnailComponent,
    • NavBarComponent
    • ],
    • providers: [EventService, ToastrService],
    • bootstrap: [EventsAppComponent]
    • })
  14. Roles of Angular Modules
    • Import other Angular Modules  eg: imports: []
    • Identify Components, Pipes, and Directives eg. declarations: []
    • Export it’s features 
    • Provide services to injectors eg. providers: []
    • Can be eagerly or lazily loaded
  15. The purpose of a ___ is to declare each thing you create in Angular, and group them together (like Java packages)
    NgModule
  16. A ___ is used to identify each component uniquely into the component tree, and it also defines how the current component is represented in the HTML DOM
    • selector
    • eg.
    • @Component({
    • selector: 'events-app'
    • ...
    • })

    • -=-=-
    • <!-- in html -->
    • <body class="container">
    • <events-app></events-app>
    • </body>
  17. __ indicates property binding
    • []
    • eg.
    • <button type="button" [disabled]="allowNewServer" ../>

    • -=-=-
    • export class ServersComponent implements onInit {
    •   allowNewServer = false;
    • }
  18. What do you call this symbols {{ }}?
    eg. {{ character.name }}
    interpolation
  19. ____ are used to display the information from the model and controller that a user sees in his browser
    Templates
  20. Components have ___ which may use other components
    templates
  21. Event is indicated by ___
    • ()
    • eg.
    • <button .. (click)="cancel()" />
  22. We use ___ to tell Angular about the objects we build. It links the template to the Component
    • Metadata
    • eg:
    • @NgModule({
    • declarations: [
    • EventsAppComponent
    • ],
    • imports: [
    • BrowserModule
    • ],
    • providers: [],
    • bootstrap: [EventsAppComponent]
    • })
  23. The ___ is a decorator that provides metadata describing the Component
    • @
    • eg.
    • @Component({
    • selector: 'events-list',
    • template:
    • ..
    • }
  24. A component can emit an event using ___ and ___
    • @Output, EventEmitter
    • eg.


    @Output() changed = new EventEmitter<Character>();

    • ...
    • this.changed.emit(selectedCharacter);

    • -=-=-
    • <story-characters ... (changed)=changed($event) />
  25. Use an ___ decorator to make an instance variable available to parent components to pass data down
    • @Input
    • eg.
    • @Input() storyId: number;

    • -=-=-
    • <story-characters [storyId]="7"  />
  26. The __ operator is used to avoid error when an object is undefined
    • ? (elvis operator)
    • eg.
    • <!-- html -->
    • Here is {{ vehicle?.name }}
  27. This sysmbol is useful when debugging, say you want to see the entire data of an object displayed in browser
    • | (pipe)
    • eg.
    • {{ character | json }}
    • This will display the character in json
  28. We set properties and events of __ ___, not attributes.
    DOM elements
  29. Using the ___ to send values from the Component to the Template
    • [ ]
    • eg.
    • in html
    • <vehicle-detail [vehicle]="currentVehicle" />
  30. What are the 3 ways to style your html?
    • Attribute binding eg. <button [attr.aria-label]="ok">ok</button>
    • Class property binding eg. <div [class.isStopped]="isStopped">Stopped</div>
    • Style property binding eg. <button [style.color]="isStopped ? 'red' : 'blue'">
    • eg.
  31. Angular includes ___ that contains the information about an event. Its type depends on the target event, e.g., if the target event is a native DOM element event, then it is an object.
    • $event
    • eg.
    • (input)="vehicle.name=$event.target.value">
  32. ___ defines a new event. Fires its __ method to raise event with data. Usually used when defining customer events.
    • EventEmitter, emit()
    • eg.
    • @Input() vehicle: Vehicle;
    • @Output() onChanged = new EventEmitter<Vehicle>();
    • changed(){ this.onChanged.emit(this.vehicle); }
  33. ___ sends a value from Component to Template, and 
    sends value changes in the Template to the Component.
    [( )] or two-way binding
  34. To create a service class, we inject the class with ___.
    • @Injectable()
    • eg.
    • @Injectable()
    • export class VehicleService {
  35. How do you inject a service in another class?
    • Through constructor
    • eg.
    • vehicles = this.vehicleService.getVehicles();
    • ...
    • constructor(private vehicleService: VehicleService) { }
  36. ___ allow you to format data in html
    • pipes
    • eg.
    • <td>{{entriesSvc.sortedEntries[0].date | date}}</td>
  37. What do you clone an object in Javascript?
    • Object.assign(target, ..sources)
    • eg.
    • createEntry() {
    • let newEntry = Object.assign({}, this.model(
    • {
    •   bodyfat: this.model.bodyfat / 100,
    •   date: new Date(this.model.date)
    • })
    •   this.create.emit(newEntry);
    • }
  38. __ is used to create a top-level form group Instance, and it binds the form to the given form value.
    • ngForm
    • eg.
    • <form #entryForm="ngForm" ..>
    • ...
    • <button [disabled]="entryForm.form.invalid ../>
  39. The ___ directive binds the value of HTML controls (input, select, text-area) to application data. If it's 2-way-bound, the value in the UI always syncs back to the domain model in your class
    • ngModel
    • eg.
    • <input ... [(ngModel)]="model.weight" />
  40. if the child only needs to receive data from the parent, you'd only need ___ decorator.
    @Input()
  41. To watch for changes on an @Input() property, use ___.
    OnChanges
  42. Use the __ decorator in a child component or directive to let Angular know that a property in that component can receive its value from its parent component.
    @Input()
  43. Before you can use [(ngModel)] in html, you have to import this in app.module.ts
    • FormsModule
    • e.g.
    • import { FormsModule } from '@angular/forms'

    • import:[
    • FormsModule
    • ]
  44. ___ are instructions in the DOM
    Directives
Author
oreilly
ID
356825
Card Set
Angular2
Description
Updated