Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.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/3/html/81.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/image-processing/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
Javascript Typescript代码:如何计算Totale=Sum(Subtotale)和price*quantita=Subtotale角度5_Javascript_Html_Angular_Typescript - Fatal编程技术网

Javascript Typescript代码:如何计算Totale=Sum(Subtotale)和price*quantita=Subtotale角度5

Javascript Typescript代码:如何计算Totale=Sum(Subtotale)和price*quantita=Subtotale角度5,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,我这张桌子和照片上的一样。在这里,我想计算price*quantita=subtotale的函数,并求和Totale=sum(subtotale) 我的html代码: <table align="center" class="table table-bordered" > <thead> <tr> <th>Price</th> <th>Quantita</th>

我这张桌子和照片上的一样。在这里,我想计算
price*quantita=subtotale
的函数,并求和
Totale=sum(subtotale)

我的html代码:

<table align="center" class="table table-bordered" >
  <thead>
    <tr>
      <th>Price</th>
      <th>Quantita</th>
      <th>Note</th> 
      <th>Subtotale</th>
    </tr>
  </thead>
  <tbody>
    <tr*ngFor="let item of products">
      <td>1</td>
      <td>{{item.Quantity}} </td>
      <td>test</td>
      <td></td>
    </tr>
  </tbody>
</table>
<br>
<p style="text-align: right; width:95%;">Totale: ALL</p>

价格
数量
注
小故事
1.
{{item.Quantity}
测试

总计:全部

var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
var i=0;
$scope.total=0;
$scope.products=[
{
“名称”:“产品1”,
“数量”:2,
“价格”:10
},
{
“名称”:“产品2”,
“数量”:6,
“价格”:8
},
{
“名称”:“产品3”,
“数量”:5,
“价格”:26
},
{
“名称”:“产品4”,
“数量”:10,
“价格”:4
},
{
“名称”:“产品5”,
“数量”:11,
“价格”:7
}
];
$scope.updateTotal=函数(){
角度.forEach($scope.products,function(product){
$scope.total+=产品数量*产品价格;
});
};
$scope.updateTotal();
});

产品
价格
量
价格*数量
{{product.name}
{{product.price}}
{{product.price*product.quantity}
全部的
${{total}
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
var i=0;
$scope.total=0;
$scope.products=[
{
“名称”:“产品1”,
“数量”:2,
“价格”:10
},
{
“名称”:“产品2”,
“数量”:6,
“价格”:8
},
{
“名称”:“产品3”,
“数量”:5,
“价格”:26
},
{
“名称”:“产品4”,
“数量”:10,
“价格”:4
},
{
“名称”:“产品5”,
“数量”:11,
“价格”:7
}
];
$scope.updateTotal=函数(){
角度.forEach($scope.products,function(product){
$scope.total+=产品数量*产品价格;
});
};
$scope.updateTotal();
});

产品
价格
量
价格*数量
{{product.name}
{{product.price}}
{{product.price*product.quantity}
全部的
${{total}
它就像在视图中一样

  <td>{{item.Price}}</td>
  <td>{{item.Quantity}} </td>
  <td>test</td>
  <td>{{item.Price * item.Quantity}}</td>

 <div>Total : {{Total}}</div>  //this call the get method Total.
它就像在视野中

  <td>{{item.Price}}</td>
  <td>{{item.Quantity}} </td>
  <td>test</td>
  <td>{{item.Price * item.Quantity}}</td>

 <div>Total : {{Total}}</div>  //this call the get method Total.
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
var i=0;
$scope.total=0;
$scope.products=[
{
“名称”:“产品1”,
“数量”:2,
“价格”:10
},
{
“名称”:“产品2”,
“数量”:6,
“价格”:8
},
{
“名称”:“产品3”,
“数量”:5,
“价格”:26
},
{
“名称”:“产品4”,
“数量”:10,
“价格”:4
},
{
“名称”:“产品5”,
“数量”:11,
“价格”:7
}
];
$scope.updateTotal=函数(){
角度.forEach($scope.products,function(product){
$scope.total+=产品数量*产品价格;
});
};
$scope.updateTotal();
});

产品
价格
量
价格*数量
{{product.name}
{{product.price}}
{{product.price*product.quantity}
全部的
${{total}
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
var i=0;
$scope.total=0;
$scope.products=[
{
“名称”:“产品1”,
“数量”:2,
“价格”:10
},
{
“名称”:“产品2”,
“数量”:6,
“价格”:8
},
{
“名称”:“产品3”,
“数量”:5,
“价格”:26
},
{
“名称”:“产品4”,
“数量”:10,
“价格”:4
},
{
“名称”:“产品5”,
“数量”:11,
“价格”:7
}
];
$scope.updateTotal=函数(){
角度.forEach($scope.products,function(product){
$scope.total+=产品数量*产品价格;
});
};
$scope.updateTotal();
});

产品
价格
量
价格*数量
{{product.name}
{{product.price}}
{{product.price*product.quantity}
全部的
${{total}

您的总和(小计)总是为0。感谢您提供了最好的解决方案:)我编写了这个函数,total(){let total=0;let p:any;for(this.products的let p){total+=p.subtotal;}}和html{total(total)}但不起作用。您能帮助pelase吗?您不能这样做总和(小计)总是以0的形式出现。感谢您提供的最佳解决方案:)我编写了这个函数,Total(){let Total=0;let p:any;for(let p of this.products){Total+=p.Subtotal;}}并使用html{{Total(Total)}}但是函数你能帮pelase吗?你不能这样做为什么你复制并发布为答案为什么你复制并发布为答案为什么你删除了答案?为什么你删除了答案?我写了这个函数,Total(){let Total=0;let p:any;for(let p of this.products){Total+=p.Subtotal;}}和html{{Total(总数)}但是不起作用你能帮pelase吗?这对我来说是一个很好的解决方案,但是现在我想在我改变数量或价格时自动改变我的总数,你能建议我做些改变吗?Thnxwelcome Lonna,即使改变数量上述代码工作正常,你如何改变数量值?谢谢,所以我的价格和数量是输入v当我改变这个值时,我希望我的total自动改变,我写这个函数,total(){let total=0;let p:any;for(let p of this.products){total+=p.Subtotal;}}和html{{total(total)}但是doe