AngularJS编写然后编辑数组

时间:2014-01-19 12:29:45

标签: angularjs angularjs-scope angularjs-ng-repeat

我有一篇文章,当您点击Add按钮时出现modal并有3个方框,您可以填写详细信息,保存后会在主页上显示{{1}的列表你新写的项目。

当您点击title时,它会打开标题为title的另一个modal,并且输入字段的2/3似乎正确填充,当您更改值并点击时Edit它不会更新。

我希望有人可以帮我改变阵列中项目的值来改变我的AngularJS。

提前致谢。

Plunker code

Save Changes

1 个答案:

答案 0 :(得分:2)

请参阅updated plunk

$scope.editlocation = function (locations) {
        var locationToEdit = locations;
        console.log(locationToEdit);
        var modalInstance = $modal.open({
            templateUrl: 'edit.html',
            controller: ModalInstanceCtrl2,
            resolve: {
                locations: function () {
                    return locationToEdit;//Use locationToEdit instead.
                }
            },
            scope: $scope.$new()
        });

modalInstance.result.then(function (selectedItem) {

            //Update locationToEdit when user saves changes.
            locationToEdit.title = selectedItem.title; //Fix typo with titley
            locationToEdit.gps = selectedItem.gps;
            locationToEdit.desc = selectedItem.desc;

        }, function () {
                console.log('Modal dismissed at: ' + new Date());
        });

ModalInstanceCtrl2 = function ($scope, $modalInstance, locations) {
        $scope.input = angular.copy(locations);//create a copy of the editing location so that when the user cancels on the dialog, the object is not updated.
        console.log(locations);
        $scope.ok = function () {
            $modalInstance.close($scope.input);//pass the edited location as a result.
            $scope.gps = "";
            $scope.title = "";
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    };