Skip to content

Instantly share code, notes, and snippets.

@Kevinwkd
Kevinwkd / sharedServiceForRoot.module.ts
Created May 5, 2019 05:19
Shared module with forRoot
import { NgModule,ModuleWithProviders } from '@angular/core';
import { CounterService } from './counter.service';
@NgModule({
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
@Kevinwkd
Kevinwkd / app.module.ts
Created May 5, 2019 05:22
import module with forRoot
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { SharedModule } from './shared/shared.module';
import { AppComponent } from './app.component';
import { EagerComponent } from './eager.component';
import { routing } from './app.routing';
@NgModule({
imports: [
BrowserModule,
@Kevinwkd
Kevinwkd / asObservable.ts
Created May 16, 2019 12:27
asObservable
const mySubject = new Rx.Subject();
const myObs = mySubject.asObservable();
mySubject.next('Hello');
myObs.next('World!'); // TypeError: myObs.next is not a function
<p>
Choose your favorite transuranic element (actinide or transactinide).
</p>
<div class="listbox-area">
<div class="left-area">
<span id="exp_elem">
Choose an element:
</span>
<div id="exp_wrapper">
<button aria-haspopup="listbox"
<div> // div A
<app-my-component>
<div>
this is some content for the component app-my-component
</div>
</app-my-component>
</div> // div B
@Component({
selector: 'app-my-component',
template: `
<div> // div C
here is the View HTML but below we receive content html
<ng-content></ng-content>
</div> // div D
`
})
import {Component, OnChanges, SimpleChanges, Input} from '@angular/core';
import { Employee } from './employee';
@Component({
selector: 'app-emp',
templateUrl: './employee.component.html'
})
export class EmployeeComponent implements OnChanges {
@Input() employee: Employee;
const user = {
name: 'John Due',
birthdate: '1988-08-15',
}
const changeName = (user, newName) => {
const newUser = user
newUser.name = newName
return newUser
}
// very simplified version of actual source
class ApplicationRef {
changeDetectorRefs:ChangeDetectorRef[] = [];
constructor(private zone: NgZone) {
this.zone.onTurnDone
.subscribe(() => this.zone.run(() => this.tick());
}
function doSomething() {
console.log('Async task');
}
// start timer
start = timer();
foo();
setTimeout(doSomething, 2000);
bar();
baz();