Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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
Php 如何使用angularjs查找多行合计_Php_Angularjs - Fatal编程技术网

Php 如何使用angularjs查找多行合计

Php 如何使用angularjs查找多行合计,php,angularjs,Php,Angularjs,我正在尝试查找总数,但它显示为0。我正在本地主机xamp服务器上进行尝试 <div data-ng-app="myapp" data-ng-controller="CartForm"> <table> <tr ng-repeat="x in names"> <td>{{ x.price }}</td> <td><input type="number" ng:model="x.qty"

我正在尝试查找总数,但它显示为0。我正在本地主机xamp服务器上进行尝试

<div data-ng-app="myapp" data-ng-controller="CartForm">
  <table>
    <tr ng-repeat="x in names">
      <td>{{ x.price }}</td>
      <td><input type="number" ng:model="x.qty" /></td>
      <td>{{ x.qty * x.price | currency: "Rs " }}</td>
    </tr>
    <tr>
      <td>Total:</td>
      <td>{{ total() }}</td>
    </tr>
  </table>
</div>

{{x.price}}
{{x.qty*x.price}货币:“卢比”}
总数:
{{total()}}

ng模型的语法约定不太好,但它会起作用

使用ng model=“x.qty”

但是,为了克服所有的total,您必须在JS文件中编写total()函数。

更新1:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});
HTML文件:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});

{{x.price}}
{{x.qty*x.price}货币:“卢比”}
总数:
{{total()}}
角度JS文件:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});
var myApp=angular.module('myApp',[]);
myApp.controller(“CartForm”,函数($scope){
$scope.names=[
{价格:2000,数量:3},
{价格:7000,数量:6},
{价格:3000,数量:5}
];
//用于执行全部合计的函数。
$scope.total=函数(){
var合计=0;
对于(变量i=0;i<$scope.names.length;i++){
var name=$scope.names[i];
总计=总计+(名称.价格*名称.数量);
}
返回总数;
};
});

ng模型的语法约定不太好,但它会起作用

使用ng model=“x.qty”

但是,为了克服所有的total,您必须在JS文件中编写total()函数。

更新1:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});
HTML文件:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});

{{x.price}}
{{x.qty*x.price}货币:“卢比”}
总数:
{{total()}}
角度JS文件:

<body>  
    <div data-ng-app = "myapp" data-ng-controller = "CartForm">
        <table>
            <tr ng-repeat = "x in names">
                <td>{{ x.price }}</td>
                <td><input type = "number" ng-model = "x.qty" /></td>
                <td>{{ x.qty * x.price | currency: "Rs " }}</td>
            </tr>
            <tr>
                <td>Total:</td>
                <td>{{ total() }}</td>
            </tr>
        </table>
    </div>
</body>
var myApp = angular.module('myApp', []);
myApp.controller("CartForm", function ($scope) {
    $scope.names = [
        {price:2000, qty:3},
        {price:7000, qty:6},
        {price:3000, qty:5}
        ];

    // Function for performing total of all.
    $scope.total = function() {
        var total = 0;
        for(var i = 0; i < $scope.names.length; i++){
            var name = $scope.names[i];
            total = total + (name.price * name.qty);
    }
    return total;
    };
});
var myApp=angular.module('myApp',[]);
myApp.controller(“CartForm”,函数($scope){
$scope.names=[
{价格:2000,数量:3},
{价格:7000,数量:6},
{价格:3000,数量:5}
];
//用于执行全部合计的函数。
$scope.total=函数(){
var合计=0;
对于(变量i=0;i<$scope.names.length;i++){
var name=$scope.names[i];
总计=总计+(名称.价格*名称.数量);
}
返回总数;
};
});

试试这样的方法

$scope.getTotal = function(){
    var total = 0;
    for(var i = 0; i < $scope.cart.products.length; i++){
        var product = $scope.cart.products[i];
        total += (product.price * product.quantity);
    }
    return total;
}
$scope.getTotal=function(){
var合计=0;
对于(变量i=0;i<$scope.cart.products.length;i++){
var product=$scope.cart.products[i];
合计+=(产品.价格*产品.数量);
}
返回总数;
}

试试这样的方法

$scope.getTotal = function(){
    var total = 0;
    for(var i = 0; i < $scope.cart.products.length; i++){
        var product = $scope.cart.products[i];
        total += (product.price * product.quantity);
    }
    return total;
}
$scope.getTotal=function(){
var合计=0;
对于(变量i=0;i<$scope.cart.products.length;i++){
var product=$scope.cart.products[i];
合计+=(产品.价格*产品.数量);
}
返回总数;
}

@Iram Haware如果此答案对您有效,请单击我的答案前面的勾号和向上箭头按钮接受此答案…谢谢…@Iram Haware如果此答案对您有效,请友好,通过单击我的答案前面的勾号和向上箭头按钮接受此答案…谢谢你…如果此答案对你有效,请友好地单击我的答案前面的勾号和向上箭头按钮接受此答案…谢谢你…如果此答案对你有效,请友好地,通过单击我的答案前面的勾号和向上箭头按钮接受此答案…谢谢。。。