Skip to content

Instantly share code, notes, and snippets.

View kobvel's full-sized avatar

Mikki Kobvel kobvel

View GitHub Profile
var container = document.getElementById("container");
function loadApp(app) {
container.innerHTML = '';
var element = document.createElement(app);
element.onload = function (load) {
console.log('loaded', load);
};
initProfileData(): void {
this.store.take(1).subscribe(store => {
if (!store.profile.profileData) {
this.apiService.getProfileData().toPromise()
.then(data => {
this.store.dispatch(new profileActions.UpdateAction(data));
})
.catch(err => {
this.router.navigate(['/404'])
});
import { ApiService } from './api.service';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [
ApiService
],
bootstrap: [AppComponent]
})
import { ApiService } from 'app/api.service';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [
{ provide: ApiService, useClass: ApiService }
],
bootstrap: [AppComponent]
})
import { Injectable } from '@angular/core';
@Injectable()
export class ApiService {
constructor() { }
serviceCall() {
console.log('I am api service instance call!');
}
import { Component } from '@angular/core';
import { ApiService } from './api.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'app';
import { Injectable } from '@angular/core';
import { ApiService } from 'app/api.service';
@Injectable()
export class FakeApiService implements ApiService {
// Using implements to be sure FakeApiService has the same
// methods as original ApiService
constructor() { }
serviceCall() {
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ApiService } from 'app/api.service';
import { FakeApiService } from './fake-api.service';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [
import { Component, Inject } from '@angular/core';
import { ApiService } from './api.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
import { InjectionToken, ValueProvider } from '@angular/core';
interface IHashwords {
hash: (hash: string) => string[];
hashStr: (hash: string) => string;
random: () => string[];
randomStr: () => string;
}
const Hashwords: InjectionToken<IHashwords> = new InjectionToken<IHashwords>('hashwords');