随笔分类 - Angular
摘要:Using factory provider: Here we create 'DrinkFactory' as a named funciton, this is good for AOT, so recommended doing this way.
阅读全文
摘要:Previously we have 'OpaqueToken', but it is DEPRECATED. The new one is called 'InjectionToken'. The difference between OpaqueToken is for InjectionTok
阅读全文
摘要:directive: test:
阅读全文
摘要:For example, when testing container component we might import lots of children components, but we didn't actually testing those children components. S
阅读全文
摘要:The main idea for testing contianer component is to make sure it setup everythings correctlly. Call the onInit() lifecycle first, then the variables h
阅读全文
摘要:Component: Test:
阅读全文
摘要:Component: Test @Input & @Output:
阅读全文
摘要:component:
阅读全文
摘要:import { Http, Response, ResponseOptions } from '@angular/http'; import { TestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/...
阅读全文
摘要:import { TestBed, ComponentFixture } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; import { Fil...
阅读全文
摘要:import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filesize' }) export class FileSizePipe implements PipeTransform { transform(size: number, extension: string = 'MB') { retu...
阅读全文
摘要:Define a auxilliary router: HTML: Routing by routerLink: Clean auxiliary router: Routing by JS: RouterLink's advantage: Angular will convert routerLin
阅读全文
摘要:export class MailFolderComponent implements OnInit{ title: Observable; messages: Observable; constructor( private route: ActivatedRoute ){ } ngOnInit() { this.messages = thi...
阅读全文
摘要:For example, we have a component which just simply render router-outlet: We can add events to router-outlet: When we log out the, we see the actual co
阅读全文
摘要:In our root component, one thing we can do is subscribe to Router events, and do something related to router events. So how can we get router event? T
阅读全文
摘要:To enable router tracing is really simple: When we define the root RouterModule, we can pass the option "enableTracing". What we you get is when we na
阅读全文
摘要:Creating custom validators is easy, just create a class inject AbstractControl. Here is the form we want to validate it: We put two custom validators
阅读全文
摘要:One of the most important thing when building custom form component is adding accessbility support. The component should be focusable. we can achieve
阅读全文
摘要:So when you need to create a ControlValueAccessor? When you want to use a custom component as form control. For example a counter component, you can c
阅读全文
摘要:Create an app with routing config: If you want to generate a new module with routing , you can also do: Define env variable: You can create a custom e
阅读全文