Skip to content

Instantly share code, notes, and snippets.

View NishuGoel's full-sized avatar

Nishu Goel NishuGoel

View GitHub Profile
export function equalArraysOrString(a: string | string[], b: string | string[]) {
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length != b.length) return false;
return a.every(aItem => b.indexOf(aItem) > -1);
} else {
return a === b;
}
}
setUpLocationSync(ngUpgrade: UpgradeModule, urlType: "path" | "hash" = 'path')
constructor(private router: Router) {
this.router.events.subscribe( (event: RouterEvent) => console.log(event))
}
private applyRedirectCreatreUrlTree(
redirectTo: string, urlTree: UrlTree, segments: UrlSegment[],
posParams: {[k: string]: UrlSegment}): UrlTree {
const newRoot = this.createSegmentGroup(redirectTo, urlTree.root, segments, posParams);
return new UrlTree(
newRoot, this.createQueryParams(urlTree.queryParams, this.urlTree.queryParams),
urlTree.fragment);
}
//Inside index.html
<script src="https://unpkg.com/@nishugoel/prod-card@0.0.5/main.js"></script>
//Use the custom element in the App.js file
<prod-card username='Enter your name' password='Enter new password' btnname='Sign in'></prod-card>
{
"name" : "@nishugoel/prod-card",
"version": "0.0.5"
}
constructor(private injector: Injector) {
const customElement = createCustomElement(CustomElementDemoComponent, { injector });
customElements.define('custom-element', customElement);
}
//Inside NgModule
entryComponents: [CustomElementDemoComponent],
})
export class FeatureModule {
constructor(private injector: Injector) {
}
@Component({
templateUrl: './custom-elements.component.html',
styleUrls: ['./custom-elements.component.scss']
})
export class ComponentName {
title = 'custom-elements-demo';
}
<section>
<div>
<slot></slot> //Content of the custom element gets placed here
</div>
</section>
// Custom Element
<my-element>
<button>Custom button</button>