Skip to content

Instantly share code, notes, and snippets.

View emolr's full-sized avatar

Emil Møller emolr

  • Hi, freelance designer/programmer
  • Denmark
View GitHub Profile
@emolr
emolr / bashplate-1635408019055.sh
Created October 28, 2021 08:00
Script Description
#!/usr/bin/env bash
# Like this script?
# Generate boilerplate for similar ones at https://bashplate.wolfgang-werner.net.
set -o errexit # exit on error
set -o nounset # don't allow unset variables
# set -o xtrace # enable for debugging
usage() {
printf "Script Description\n"
// Create a new instance
let myWebComponent = document.createElement('my-element');
// Append it to body
document.body.appendChild(myWebComponent);
<html>
<head>
<title>My Element</title>
</head>
<body>
// Prints: Hello, I'm a web component
<my-element></my-element>
<script src="my-element.js"></script>
</body>
class MyElement extends HTMLElement {
constructor() {
super();
// We create a shadowDOM
this.attachShadow({mode: 'open'});
// Then we inject a html template into the created ShadowDOM
this.shadowRoot.innerHTML = `
Hello, I'm a web component
`;
}
const data = {
title: 'hello world',
endTime: 123456,
foo: [1, 2, 3]
};
const properties = {
title: 'string',
endTime: 'number',
foo: 'array'
<div>
<form [formGroup]="articleFormService.articleFormModel.form" novalidate (ngSubmit)="create()">
<label>
Title
<input type="text" formControlName="title" placeholder="Title">
<span class="error" *ngIf="articleFormService?.articleFormModel?.form.get('title').touched && !articleFormService?.articleFormModel?.form.get('title').valid">
A title is required
</span>
</label>
<label>
// app.component.ts
import {Component} from '@angular/core'
import {ArticleFormService} from 'src/models/app-forms/article-form/article-form.service.ts'
@Component({
selector: 'my-app',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
// app.module.ts
import {NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {FormsModule, ReactiveFormsModule} from '@angular/forms'
import {ArticleFormModule} from 'src/models/app-forms/article-form/article-form.module.ts'
import {AppComponent} from 'src/app.component.ts'
@NgModule({
// article-form.module.ts
import {NgModule} from '@angular/core';
import {CommonModule} from "@angular/common";
import {ArticleFormBackend} from "./article-form.backend";
import {ArticleFormService} from "./article-form.service";
@NgModule({
imports: [
CommonModule
// article-form.service.ts
import {Injectable} from "@angular/core";
import {AppFormsBase} from "../app-forms-base.class";
import {ArticleFormBackend} from "./article-form.backend";
import {ArticleFormModel} from "./article-form.model";
import {IArticle} from "./article-form.interface";
@Injectable()
export class ArticleFormService extends AppFormsBase {