Nitin Chaurasia
Nitin Chaurasia

Reputation: 263

How to apply Angular.Copy

I have below code

var myctrl = function($scope) {
    $scope.items = [{value: 1, name:'Nitin'},{value: 2, name:'Vikas'},{value: 3, name:'xxx'}];
    $scope.itemEdit1 = $scope.items;
    $scope.itemEdit2 = $scope.items.name;
};

I want to copy only name to itemEdit2

Upvotes: 0

Views: 121

Answers (1)

Maxim Shoustin
Maxim Shoustin

Reputation: 77904

Use $scope.itemEdit2 = $scope.items[0].name;

If you interesting to copy all names, it should be like:

 $scope.itemEdit2 = [];

 $scope.items.forEach(function(v, i) { 
    $scope.itemEdit2.push({name: v.name});  // or just push(v.name);
 });

Upvotes: 1

Related Questions