简体   繁体   中英

How to update the elements of array in angularjs?

I want to replace the Item of an array to the newly created item here is the function

 $scope.getPageDetails = function () {
        $http.get('/api/privilege/getpagedetails/')
            .success(function (data, status) {
                $scope.Pages = data;
                angular.forEach($scope.Pages, function (value, key) {
                    var url = "//" + (value.pageUrl);

                    console.log(url);
                    $scope.Pages.pageUrl = url;
                });
                $scope.$applyAsync();

            }).error(function () {
            });
    }

I got the value of pageUrl from array $scope.Pages[] which is recoveryguidance.com then I added // on the pageUrl var url = "//" + (value.pageUrl); then it becomes //recoveryguidance.com then how can I push the updated value on array $scope.pages[] in the place of pageUrl. In short I want to update value from recoveryguidance.com to //recoveryguidance.com of pageUrl column in $scope.pages array.

I am attaching the data also I want to update pageUrl recoveryguidance.com to //recoveryguidance.com.

在此处输入图片说明 ageUrl

Please guide me I will be very thankful to you all.

Try this:

angular.forEach($scope.Pages, function (value, key) {
    value.pageUrl = "//" + (value.pageUrl);
});

JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM