Ananya
Ananya

Reputation: 211

Can we extend multiple objects at once using angularjs?

angular.extend($scope.postConfig, $scope.channelConfig, {
        scrollTop: 0
    });

Is it correct way to extend 2 objects at once?

Upvotes: 0

Views: 582

Answers (2)

Alex Romanov
Alex Romanov

Reputation: 11963

As it said in AngularJS docs :

angular.extend

Extends the destination object dst by copying own enumerable properties from the src object(s) to dst. You CAN SPECIFY MULTIPLE SRC OBJECTS.

Usage: angular.extend(dst, src1, src2, ...);

Your syntax is correct.

Upvotes: 0

tanmay
tanmay

Reputation: 7911

Yes, as mentioned in the angular.extend docs,

Extends the destination object dst by copying own enumerable properties from the src object(s) to dst. You can specify multiple src objects.

So, what you have in the question is correct syntax:

angular.extend($scope.postConfig, $scope.channelConfig, {
    scrollTop: 0
});

Just make sure that first argument is the destination object which will get extended by the (multiple) source object(s) provided as next arguments.

Upvotes: 2

Related Questions