2013-10-10 82 views
0

我有下面的代碼如何申請Angular.Copy

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; 
}; 

我只想複製命名到itemEdit2

+0

所以基本上你想複製所有的名字值? – nXqd

回答

1

使用$scope.itemEdit2 = $scope.items[0].name;

如果您感興趣的複製所有的名字,它應該像:

$scope.itemEdit2 = []; 

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

謝謝,但它只複製第一個值,我想要所有的值 –

+0

看到我編輯我沒有 –