Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Ionic1增值税计算_Angularjs_Ionic Framework - Fatal编程技术网

Angularjs Ionic1增值税计算

Angularjs Ionic1增值税计算,angularjs,ionic-framework,Angularjs,Ionic Framework,我有一个ionic1应用程序和三个输入 <label class="item item-input item-stacked-label"> <div class="input-label"> Total (Inc VAT) £ </div> <input type="number" ng-model="form.gross" placeholder="Total Including V

我有一个ionic1应用程序和三个输入

<label class="item item-input item-stacked-label">
        <div class="input-label">
          Total (Inc VAT) £
        </div>
        <input type="number" ng-model="form.gross" placeholder="Total Including VAT">
      </label> 
      <label class="item item-input item-select">
        <div class="input-label">
          VAT Value
        </div>
        <select ng-model="form.vat">
          <option value="20" selected="">20%</option>
          <option value="0">0%</option>
          <option value="5">5%</option>
        </select>
      </label> 
      <label class="item item-input item-stacked-label">
        <div class="input-label">
          Amount (Ex VAT) £
        </div>
        <input type="number" ng-model="form.net" placeholder="Total Including VAT">
      </label>

我认为由于双向绑定,应用程序将根据dom中更新的值进行更改?

对于第一个问题:只需使用ng选项,并拥有一个包含select值和标签的对象数组。如果您不想使用它&只想使用常规的select,而不是在options上使用selected=attribute,只需在控制器内部初始化该字段的值,如

$scope.form.vat=20

使用数字作为值,因为您正在对它们执行算术运算

对于第二个问题,只需在总值和增值税字段上设置ng change指令,并调用其中的函数来执行查找增值税和净值的操作。所以每次你们改变输入时,它都会被计算出来,因为在初始条件下,目前它只发生一次。因此,您的功能应该是:

$scope.changed = function(){
    $scope.form.vatValue = $scope.form.gross / 100 * $scope.form.vat;
    $scope.form.net = $scope.form.gross - $scope.form.vatValue;
}
ng change=已更改,在两个输入字段中都有此项:总额、增值税

下面是一个工作代码笔示例:。 现在,由于您已经为“net”输入了字段,所以您可能希望对其进行操作,同样,您必须编写另一个函数,根据恒定增值税值和不断变化的净值计算总值,并在净字段发生ng变化时调用它

$scope.changed = function(){
    $scope.form.vatValue = $scope.form.gross / 100 * $scope.form.vat;
    $scope.form.net = $scope.form.gross - $scope.form.vatValue;
}