Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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 AngularJS检测已更改的输入_Javascript_Html_Angularjs - Fatal编程技术网

Javascript AngularJS检测已更改的输入

Javascript AngularJS检测已更改的输入,javascript,html,angularjs,Javascript,Html,Angularjs,数据通过$http.get在我的AngularJS应用程序中检索并呈现如下: # Angular app.controller('MainCtrl', function ($scope, $http) { $scope.cart = {}; $scope.cart.retrieve = function() { // make $http to retrieve data .success(function(results) {

数据通过$http.get在我的AngularJS应用程序中检索并呈现如下:

# Angular
app.controller('MainCtrl', function ($scope, $http) {
    $scope.cart = {};

    $scope.cart.retrieve = function() {
        // make $http to retrieve data
        .success(function(results) {
            $scope.cart.contents = results
        });
    };

    $scope.cart.update = function(itemId) {
        // make $http request to update cart
    }
});

# HTML
<table ng-init="cart.retrieve()">
        <tbody>
            <tr ng-repeat="item in cart.contents">
                <td>{{ item.price }}</td>
                // item quantity input field
                <td><input type="number" name="quantity" on-change="cart.update(item.id)"
                ng-model="item.qty"></td>
                <td>{{ item.price * item.qty }}</td>
            </tr>
        </tbody>
</table>
在输入字段中更改项目数量时,传递项目id的函数将激发:$scope.cart.update=functionitemId{…}。如何检索在更改事件中触发的此特定项的新数量值。我可以在函数中使用类似的东西吗?

您可以将物品传递到购物车。更新函数:

on-change="cart.update(item)"
然后使用此项目的数量

$scope.cart.update = function(item) {
    // do whatever you want with
    // item.qty
}