简体   繁体   English

如何为每个angularjs更改类似的ng-repeat值

[英]how to change similar ng-repeat values for each angularjs

i want to change ng-repeat values separately, from shown single input text box, i'm trying to bind inputbox to label, but all values binding together, can u please tell me how to change only selected div values.. Working DEMO 我想单独改变NG-重复值,从显示单个输入文本框,我试图绑定输入框标记,但所有值结合在一起,u能请告诉我如何改变只选择DIV值.. 工作演示

 var app = angular.module('myapp', ['ngSanitize']); app.controller('AddCtrl', function ($scope, $compile) { $scope.items = []; $scope.add_New = function (index) { var itemhtml = '<div ng-click="select()" class="content">//click here first// <div ng-repeat="item in items">{{$index + 1}}. {{item.name}}</div></div>'; var item = $compile(itemhtml)($scope); angular.element(document.getElementById('drop')).append(item); }; $scope.add = function () { $scope.items.push({ name: "hi" }); }; $scope.select = function(){ $scope.showItem = true; } }); 
 /* Styles go here */ body{ width:1000; } .add{ width:300; } .show{ width:400; float:right; } .content{ border:1px solid blue; } 
 <!DOCTYPE html> <html ng-app="myapp"> <head> <link href="style.css" rel="stylesheet" type="text/css"/> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.2/angular.min.js"></script> <script src="https://code.angularjs.org/1.5.0-rc.0/angular-sanitize.min.js"></script> </head> <body ng-controller="AddCtrl"> <button ng-click="add_New($index)">add Again</button> <div id="drop" class="add"> </div> <div ng-show="showItem" class="show"> <div ng-repeat="item in items"> {{$index + 1}}.<input type="text" ng-model="item.name"> </div> <button ng-click="add()">Add</button> </div> </body> </html> 

I gave it a shot, tried my best to understand what you wanted, got to this point. 我给它一个镜头,尽我所能理解你想要的东西,得到了一点。

var app = angular.module('myapp', ['ngSanitize']);

app.controller('AddCtrl', function ($scope, $compile) {

    var id = 0;

    $scope.sections = [];

    $scope.addItem = function(section) {
      section.items.push('hi');
    }

    $scope.select = function(){
      $scope.showItem = true;
    }

    $scope.addNewSection = function(){
      id++;

      var newSection = {text: 'Section '+id, id: id, items: []};
      $scope.sections.push(newSection);
    }

});

And the html. 和HTML。

<body ng-controller="AddCtrl">
    <button ng-click="addNewSection()">Add Section</button>


    <div ng-repeat="section in sections" class="content">

        {{section.text}} 

        <button ng-click="addItem(section)">Add</button>

        <div ng-repeat="item in section.items track by $index">
            {{$index}}. <input type="text" ng-model="item.name">  
        </div>
    </div>

</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM