Javascript 如何在page onclick中添加动态ng repeat
我想创建动态ng reapet并在单击事件时推送数组元素: 我的控制器代码是Javascript 如何在page onclick中添加动态ng repeat,javascript,jquery,angularjs,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Angularjs Ng Repeat,我想创建动态ng reapet并在单击事件时推送数组元素: 我的控制器代码是 $scope.AddlistItem = function (index) { $scope.selecttaglist($scope.tag); }; $scope.selecttaglist = function (tag) { //var i=$scope.selectedTags.length; angular.forEach($scope.selectedTags,function(tag,ind
$scope.AddlistItem = function (index) {
$scope.selecttaglist($scope.tag);
};
$scope.selecttaglist = function (tag) {
//var i=$scope.selectedTags.length;
angular.forEach($scope.selectedTags,function(tag,index){
console.log(tag.name);
$scope.selectedTagslist.push(tag);
})
和视图代码:
<ul id="boxElement" ><li ng-repeat="tag in selectedTagslist" ng-controller="ItemController" ng-bind="tag.name" ></li></ul>
Html代码
<div class="AddButtn" id="aDD{{item.name}}" ng-controller="ItemController" ng-click="AddlistItem()" ></div>
问题是当我点击链接时。数组元素正在推送所有ng reapet元素。我希望数组将只推送单击的元素容器。我不确定我这样做的方法是否正确。我是新来安格拉斯的。任何人都可以在这方面提供帮助。如果
ng repeat
的模型是相同的,那么您需要不同的方法,因为模型驱动视图,因此您将需要不止一个
<ul id="boxElement" ><li ng-repeat="tag in selectedTagslist" ng-controller="ItemController" ng-bind="tag.name" ></li></ul>
<ul id="boxElement" ><li ng-repeat="tag in selectedTagslist2" ng-controller="ItemController" ng-bind="tag.name" ></li></ul>
使用第一个元素的副本-angular.copy
,否则对象将通过引用连接,效果相同
希望这是有道理的