Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

<table>
<tr>
<td>Topic: </td>
<td><input [(ngModel)]="topicname" type="text" /></td>
<td><button type="button" (click)="subscribeNewTopic()">Subscribe Topic</button></td>
</tr>
<tr>
<td>Message: </td>
<td><input [(ngModel)]="msg" type="text" /></td>
<td><button type="button" (click)="sendmsg()">Send</button></td>
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from "@angular/forms";
import { AppComponent } from './app.component';
import { MqttModule, IMqttServiceOptions } from "ngx-mqtt";
export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
hostname: 'localhost',
port: 9001,
path: '/mqtt'
}
import { Component, OnInit, ViewChild, ElementRef, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { IMqttMessage, MqttService } from 'ngx-mqtt';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
private subscription: Subscription;
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { equalPassValidator } from './shared/equal.validator.directive';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
import { Validator, AbstractControl, NG_VALIDATORS, ValidatorFn } from '@angular/forms';
import { Directive, Input } from "@angular/core";
export function equalPassValidator(appEqualValidator: string): ValidatorFn {
return (c: AbstractControl): { [key: string]: any | null } => {
console.log("control object: ", c, appEqualValidator)
const controlToCompare = c.root.get(appEqualValidator);
console.log('control to compare: ', controlToCompare);
if (controlToCompare && controlToCompare.value === c.value) return { "equal": true };
return { "equal": false }
<form [formGroup]="signUpForm">
<table>
<tr>
<td>
<label>Username:</label>
</td>
<td>
<input name="username" type="text" formControlName="username">
</td>
</tr>
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
import { EqualValidatorDirective } from './shared/equal.validator.directive';
@NgModule({
imports: [ BrowserModule, FormsModule, ReactiveFormsModule ],
this.state = {
scrollPosition: 0
}
componentWillReceiveProps () {
const element = ReactDOM.findDOMNode(this);
if (element != null) {
this.setState({
scrollPosition: window.scrollY
})
//Pass the orderItems array that you get
getDataArray(arr) {
const uniqByArr = uniqBy(arr, 'item_id');
let finalArr = [];
uniqByArr.map((item,idx) => {
const item_id = item.item_id;
let qty = 0;
arr.map((actualItem) => {
if (item_id === actualItem.item_id) {
qty += 1;