在HTML中,ng-value根据控制器的更新没有更新。同时根据控制器更新表达式

时间:2016-05-18 04:27:13

标签: javascript html angularjs

在HTML ng-value="itemdetails[0].Title"中根据控制器update.bt不会同时更新{{itemdetails[0].Title}}此表达式已更新。我无法理解问题所在。

HTML

 <div id="lineitemmodal" class="modal fade" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">

                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label >Title</label>
                            <input type="text" ng-model="item.Title" class="form-control" ng-value="itemdetails[0].Title" placeholder="Title">
                            {{itemdetails[0].Title}}
                        </div>
                        <div class="form-group">
                            <label >SKU</label>
                            <input type="text" ng-model="item.SKU" class="form-control" ng-value="itemdetails[0].SKU" placeholder="SKU">
                            {{itemdetails[0].SKU}}
                        </div>
                        <div class="form-group">
                            <label >Description</label>
                            <input type="textarea" ng-model="item.Description" class="form-control" ng-value="itemdetails[0].Description" placeholder="Description">
                        </div>
                        <div class="form-group">
                            <label >Unit type</label>
                            <input type="text" ng-model="item.UnitType" class="form-control" ng-value="itemdetails[0].UnitType" placeholder="Unit type">
                        </div>
                        <div class="form-group">
                            <label >Unit price</label>
                            <input type="text" ng-model="item.Unitprice" class="form-control" ng-value="itemdetails[0].Unitprice" placeholder="Unit price">
                        </div>
                        <button type="submit" class="btn btn-success" style="margin-right: 75%" ng-click="saveitem(item)" data-dismiss="modal">Save</button>
                        <button type="submit" class="btn btn-danger" data-dismiss="modal">Delete</button>
                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>
    </div>

控制器

app.angular.controller('lineItemController', function ($scope, rest, $window) {
$scope.lineitems = [];
$scope.itemdetails = [];
var currentitem;

$scope.addnewitem = function () {
    $scope.lineitems.push({Title:'Title',SKU:'SKU',Description:'Description',UnitType:'Unit type',UnitPrice:'Unit price'});


};

$scope.getitems = function () {
    rest.get('lineitem').then(function (results) {
        $scope.lineitems = [];
        $scope.itemdetails = [];
        $scope.lineitems = results;
        console.log(results);

    });
};

$scope.getitems();

$scope.showitem = function (item) {
    $scope.itemdetails.push(item);
    console.log($scope.itemdetails);

    $("#lineitemmodal").modal('show');
};

$scope.saveitem = function (newitem) {
    console.log($scope.itemdetails[0]);

    //item.ID = $scope.itemdetails.ID;
    $scope.itemdetails[0].Title = newitem.Title;
    $scope.itemdetails[0].SKU = newitem.SKU;
    $scope.itemdetails[0].Description = newitem.Description;
    $scope.itemdetails[0].UnitType = newitem.UnitType;
    $scope.itemdetails[0].Unitprice = newitem.Unitprice;

    rest.post('lineitem', {
        LineItem: $scope.itemdetails[0]
    }).then(function (results) {
        console.log(results);
        $scope.getitems();
    });

};

});

0 个答案:

没有答案