I have a controller like this:
CheckoutController = function() { $scope.Profile = { firstname : 'Ruchir', middlename : 'Shakun', lastname : 'Gupta', email : ' ruchir@example.com ', cellphone : '9876543210' } $scope.BillingDetails = { firstname : undefined, middlename : undefined, lastname : undefined, addressline : undefined, city : undefined, zipcode : undefined } $scope.update = function() {
Now in the function $scope.update ; I want to write something that should copy " only " firstname , middlename and lastname from $scope.Profile to $scope.BillingDetails .
I tried angular.copy and angular.extend , but
angular.extend combines $scope.BillingDetails and $scope.Profile . So I get the email and cellphone properties in $scope.BillingDetails as well, which I don't want.
angular.copy overwrites $scope.BillingDetails , and I lose addressline , city and zipcode from $scope.BillingDetails - which I don't want.
What I need is for my update function to make $scope.BillingDetails equal to below the object:
{ firstname : 'Ruchir', middlename : 'Shakun', lastname : 'Gupta', addressline : undefined, city : undefined, zipcode : undefined }
This scenario is just an example. To shorten the length of my question, I mentioned only 5-6 properties. In fact, I have to deal with more than 20 properties, and they are all dynamic. Therefore, for me this will not work by copying the firstname , middlename and lastname from Profile to BillingDetails . What can I do?
javascript angularjs angularjs-service angularjs-scope angularjs-directive
Ruchir gupta
source share