Two-way binding with range and number input in AngularJS

前端 未结 3 468
梦毁少年i
梦毁少年i 2021-02-07 06:39

I\'m just starting to play around with AngularJS and trying to understand the binding technique. For starters, I tried to make a simple conversion calculator (dozens to pieces,

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 07:32

    You can solve it using ng-model-options. I changed jsfiddle and here is the code:

    html:


    js:

    var myApp = angular.module('myApp', []);
    
    myApp.controller('CalcCtrl', function ($scope) {
        var num = 1.0;
        $scope.qty = {
        qty:function (val) {
            return arguments.length ? (num = parseFloat(val)) : num;
         }, 
         dozens: function (val) {
                return arguments.length ? (num = val*12) : num/12;
            }
         };
    });
    

提交回复
热议问题