Multiplication using Angular

Multiply with Angular

by Amy Ruddy

HTML

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<div class='mainContent'>
  <div class='container py-5' ng-app="multiplierApp" ng-controller="multiplierController">
    <div class='bg-white rounded shadow p-3 mx-auto'>

      <h1>Angular Multiplier</h1>

      <p>This is a simple example of an Angular multiplier.</p>

      <div class='mb-3'><input type="number" ng-model="val1" ng-keyup="myResult = true;">
        <span> X </span><input type="number" ng-model="val2" ng-keyup="myResult = true;">
      </div>

      <p ng-show="myResult">
        <strong>{{ val1 | number }}</strong><span> X </span><strong>{{ val2 | number }}</strong>
        <span> =</span><strong> {{ result | number}}</strong>
      </p>

      <div class='mt-3'>
        <button ng-click="result=val1*val2;" class='btn btn-dark'>Multiply Me!</button>
        <button ng-click="val1 = ''; val2 = ''; result=0;" class='btn btn-outline-dark'>Reset</button>
      </div>

    </div>
  </div>
</div>

CSS

.mainContent,
html,
body {
  background-color: #e62a39;
}

.bg-white {
  max-width: 415px;
}

input {
  max-width: 100px;
  height: calc(2.25rem + 2px);
  padding: .375rem .75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid #ced4da;
  border-radius: .25rem;
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  /* display: none; <- Crashes Chrome on hover */
  -webkit-appearance: none;
  margin: 0;
  /* <-- Apparently some margin are still there even though it's hidden */
}

input[type=number] {
  -moz-appearance: textfield;
  /* Firefox */
}

p {
  font-size: 1.1rem;
}

strong,
span {
  font-weight: bold;
  font-size: 2rem;
}

strong {
  color: #e62a39;
}

TypeScript

var app = angular.module('multiplierApp', []);
  app.controller('multiplierController', function($scope) {
    $scope.val1;
    $scope.val2;
    $scope.result;
    $scope.myResult = false;
  });