Gaurav_0093
Gaurav_0093

Reputation: 1030

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.

enter image description hereageUrl

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

Upvotes: 0

Views: 71

Answers (1)

Nitish Kumar
Nitish Kumar

Reputation: 4870

Try this:

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

JSFiddle

Upvotes: 3

Related Questions