Skip to content

Instantly share code, notes, and snippets.

@CodySchaaf
Created October 2, 2015 04:55
Show Gist options
  • Save CodySchaaf/6cd2de43defac010ea07 to your computer and use it in GitHub Desktop.
Save CodySchaaf/6cd2de43defac010ea07 to your computer and use it in GitHub Desktop.
Angular Currency Input
<div ng-app="myApp">
<div ng-controller="Main as MainCtrl" class="container">
<h5>Enter an amount below</h5>
<input type="text" cs-currency-input ng-model="MainCtrl.amount" allow-negatives="true" class="input-s form-control money" placeholder="$"/>
User facing value is formatted, while bound model is stored as a number: {{MainCtrl.amount}}
</div>
</div>
declare var angular;
var myApp = angular.module("myApp",["csCurrencyInput"])
class Ctrl {
public amount = "";
constructor() {
}
}
myApp.controller('Main', Ctrl)
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="https://rawgit.com/CodySchaaf/CsCurrencyInput/master/app/build/index.js"></script>
.money {
max-width: 300px;
&.ng-invalid:not(.ng-pristine) {
border-color: red;
}
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment