Skip to content

Instantly share code, notes, and snippets.

View sulco's full-sized avatar
💭
compiling or woodworking

Tomek Sulkowski sulco

💭
compiling or woodworking
View GitHub Profile
@sulco
sulco / button.module.ts
Created April 30, 2018 20:57
Sample module that defines an Angular custom element
import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements';
import { ButtonComponent } from './button.component';
@NgModule({
imports: [BrowserModule],
declarations: [ButtonComponent],
entryComponents: [ButtonComponent]
})
@sulco
sulco / one-file-component-native-encapsulation.ts
Created April 30, 2018 20:44
Simple one-file Angular component with `ViewEncapsulation.Native`
import { Input, Component, ViewEncapsulation, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'custom-button',
template: `<button (click)="handleClick()">{{label}}</button>`,
styles: [`
button {
border: solid 3px;
padding: 8px 10px;
background: #bada55;
@sulco
sulco / if-role.directive.ts
Last active November 28, 2017 20:57
tsIfRole structural directive
import { Directive, Input, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
import { UserService } from './user.service';
import { UserRole } from '../shared/models/user-role';
@Directive({
selector: '[tsIfRole]'
})
export class IfRoleDirective implements OnInit {
role: UserRole;
@sulco
sulco / .bashrc
Last active December 17, 2016 17:21
ngapp() {
ng new $1 --style=sass --skip-npm && cd $1 && yarn \
&& open http://localhost:4200 \
&& code . \
&& yarn start
}
@sulco
sulco / .bashrc
Last active December 17, 2016 17:17
ngapp() {
ng new $1 --style=sass --skip-npm && cd $1 && yarn \
&& open http://localhost:4200 \
&& code .
}
@sulco
sulco / .bashrc
Last active December 17, 2016 16:55
ngapp() {
ng new $1 --style=sass --skip-npm && cd $1 && yarn
}
ng new my-fancy-app --skip-npm && yarn
#
angular.module('myApp.formUtils')
.directive('submitIfValid', function () {
return {
restrict: 'A',
require: '^form',
link: function (scope, element, attrs, form) {
element.on('click', handleClick);
function handleClick() {
<form name="aForm" novalidate>
<label for="name">Your email</label>
<input type="email" id="name" ng-model="name" name="aField" required>
<ng-messages for="aForm.aField.$error"
ng-show="aForm.aField.$invalid && aForm.aField.$dirty">
<ng-message when="required">This field is required</ng-message>
<ng-message when="email">Please enter a valid email address</ng-message>
</ng-messages>
<button ng-click="save()" ng-disabled="aForm.$invalid">Send</button>
</form>
<div ng-app="app">
<form name="aForm" novalidate>
<label for="name">Your email</label>
<input type="email" id="name" ng-model="name" name="aField" required>
<ng-messages for="aForm.aField.$error">
<ng-message when="required">This field is required</ng-message>
<ng-message when="email">Please enter proper email address</ng-message>
</ng-messages>
<button ng-click="save()">Send</button>
</form>