2014-10-04 58 views
-2
<html ng-app=""> 
<body ng-controller="controller"> 
    <button class="btn" ng-click="create('new') >Click</button> 
</body> 
</html> 

<script> 
function controller($scope) { 
    $scope.create = function(id) { 
     // What will be the code to create a new array 
     // having name contained in variable? 
    }; 
} 
<script> 

回答

4

要創建名稱存儲在變量中的對象屬性,您應該使用括號表示法。在你的情況下:

function controller($scope) { 
    $scope.create = function(id) { 
     $scope[id] = []; 
     // do something with new array 
    }; 
} 
相關問題