Skip to content

Instantly share code, notes, and snippets.

<form #myForm="ngForm" (ngSubmit)="onSubmit()">
<div ngModelGroup="user">
<label>
Name:
<input type="text" name="name" [(ngModel)]="name" required>
</label>
<div *ngIf="myForm.controls['user']?.controls['name'].invalid && myForm.controls['user']?.controls['name'].touched">
<div *ngIf="myForm.controls['user']?.controls['name'].errors.required">Name is required</div>
</div>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
})
export class FormComponent {
name: string;
onSubmit() {
<form #myForm="ngForm">
<div ngModelGroup="user">
<label>
Name:
<input type="text" name="name" [(ngModel)]="name" required>
</label>
<div *ngIf="myForm.controls['user']?.controls['name'].invalid && myForm.controls['user']?.controls['name'].touched">
<div *ngIf="myForm.controls['user']?.controls['name'].errors.required">Name is required</div>
</div>
</div>
<form #myForm="ngForm">
<label>
Name:
<input type="text" name="name" [(ngModel)]="name" required>
</label>
<button type="submit">Submit</button>
</form>
<form>
<label>
Name:
<input type="text" name="name" required>
</label>
<button type="submit">Submit</button>
</form>
// create a binary search function that takes in a non-sorted array and a target value
const binarySearch = (arr: number[], target: number) => {
// sort the array
arr.sort((a, b) => a - b);
// create a left and right pointer
let left = 0;
let right = arr.length - 1;
// loop while left is less than or equal to right
import { Store } from '@ngxs/store';
import { AppModule } from 'src/app/app.module';
import { AnalyticsActions } from 'src/app/state/analytics/analytics.actions';
import { isFunction } from 'util';
import { captureBreadcrumb } from '../utils';
/**
* ***************************** WARNING **********************************
* To use this decorator you must ensure that your component implements *
* both OnInit and OnDestroy. If it does not this will not work. *
@shadow1349
shadow1349 / app-routing.module.ts
Created October 31, 2021 16:13
Non-lazy-loaded
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MainComponent } from './main/main.module';
const routes: Routes = [
{ path: '', redirectTo: '/main', pathMatch: 'full' },
{
path: 'main',
component: MainComponent
},
<script>
import Thing from './Thing.svelte';
let user = { loggedIn: false };
let things = [
{ id: 1, name: 'apple' },
{ id: 2, name: 'banana' },
{ id: 3, name: 'carrot' },
{ id: 4, name: 'doughnut' },
{ id: 5, name: 'egg' },
@shadow1349
shadow1349 / landing-route-routing.module.ts
Created June 2, 2021 18:41
sub-route for app-routing module
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LandingRouteComponent } from './landing-route.component';
/**
* Since this route is lazy loaded in the app-routing.module.ts we will declare a blank
* path here and give it the component we wish to load at the current route.
*/
const routes: Routes = [{ path: '', component: LandingRouteComponent, children: [
{ path: 'variation1', loadChildren: () => import('./variation-1/variation-1.module.ts').then((mod) => mod.Variation1Module) }