css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  body(ng-controller="InputTestController as ctrl")
        //- legend 输入范围测试
          input(name="budget", ng-model="ctrl.totalBudget", num-range-validate,  min="ctrl.sum")
          i.fa.fa-exclamation.error(ng-show="ctrl.form.budget.$invalid", title="您的预算不得低于已选物品总金额{{ctrl.sum}}")
          li(ng-repeat="item in ctrl.list") 
            span.fa-stack.check(ng-click="ctrl.selectItem(item)", ng-class="{'selected': item.select, 'disable': ctrl.form.$invalid}")
            | {{item.name}} 价格:{{item.cost}}   
        button(type="button", ng-click="ctrl.submit()", ng-disabled="ctrl.form.$invalid") 确认
              $blueColor = #87CEEB
$whiteColor = #fff
$errorColor = #CD5555
$greyColor = #F5F5F5
  outline none
  width 250px
  margin 20vh auto
  text-align center
    border 1px solid $blueColor
    height 30px
    border-radius 10px
    padding 0px 30px
    position relative
      width 100%
      height 100%
      border none
      box-sizing border-box
        color $errorColor
      position absolute
      right 10px
      cursor pointer
      top 5px
      color $errorColor
     text-align left
     list-style none
       cursor pointer
         color $greyColor
         color $blueColor
         visibility hidden
       &.selected > .fa-check-square
          visibility visible
          opacity 0.5
          pointer-events none
    background $blueColor
    color $whiteColor
    width 80px
    border none
    height 30px
      opacity 0.5
              // custome validate directive
function numRangeValidateDirective() {
   return {
        require: 'ngModel',
        scope: {
            min: '=',
            max: '='
        link: (scope, elem, attr, ngModel) => {
            //For DOM -> model validation
            ngModel.$parsers.push((value) => {
                let valid = ((/^-?(0|([1-9]\d*))$/).test(`${value}`));
                const res = _.toNumber(value);
                valid = _.isUndefined(scope.min) ? valid : (valid && (res >= scope.min));
                valid = _.isUndefined(scope.max) ? valid : (valid && (res <= scope.max));
                ngModel.$setValidity('numRange', valid);
                return valid ? res : undefined; // eslint-disable-line no-undefined

            //For model -> DOM validation
            // ngModel.$formatters.unshift((value) => {
            //     // ngModel.$setValidity('budget', blacklist.indexOf(value) === -1);
            //     return value;
            // });

class InputTestController {
  constructor() {
    this.list = [
      {name: '羽绒服', cost: 8000},
      {name: '雪地靴', cost: 600},
      {name: 'iPad Pro', cost: 6540},
      {name: '玩具', cost: 100},
      {name: '茶杯', cost: 80}
    this.totalBudget = 0;
    this.sum = 0;
  _getTotalSum() {
    return _.sumBy(_.filter(this.list, ['select', true]), (item) => {return item.cost});
  selectItem(item) {
      item.select = !item.select;
      if (item.select) {
        this.totalBudget += item.cost;
      } else {
        this.totalBudget -= item.cost;
     this.sum = this._getTotalSum();
  _setStatus() {
    const index = _.findIndex(this.list, ['select', true]);
    if (index == -1) {
      this.totalBudget = 0;
      this.sum =0;
  submit() {
InputTestController.$inject = [];

angular.module('myApp', [])
  .directive('numRangeValidate', numRangeValidateDirective)
  .controller('InputTestController', InputTestController)
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................