angular.js - angularjs click bind data below
世界只因有你
世界只因有你 2017-05-15 16:54:38
0
1
654

I now use ng-reapeat to dynamically add a list ul li, but I want to click on a certain li and attach its value to the input below, and then I can modify the above The data changes accordingly.
This is a small half of the code address I wrote on codepen codepen address

expanderModule.directive('items',function(){
  var str='<li ng-repeat="p in todos">{{p.todotext}}<p>{{title}},<button ng-click="addlt($index)">del</button></p></li>';
  return {
        restrict : 'EA',
        replace : true,
        transclude : true,
        template : str,
        link : function(scope, element, attrs) {
            }
        }
    }
});
expanderModule.controller('SomeController',function($scope) {
    $scope.currentItem=0;
    $scope.todos=[{id:'0',todotext:'第一个item',done:false}, ];
  $scope.addd=function(){
    $scope.currentItem++;
    $scope.todos.push({id:$scope.currentItem,todotext:'第'+$scope.currentItem+'个item',done:false})
  }...

html

<p ng-controller='SomeController'> 
           <ul >
               <items></items>
             </li>
            </ul>  
             <button ng-click='addd()'>dian</button>
      <p>想显示点击的值,并且能编辑可以相互绑定
        <input type="text" />
      </p>
世界只因有你
世界只因有你

reply all(1)
淡淡烟草味

You can set each of them to have an ngmodel attribute, and then when you click li in the controller, you can bind them to each other

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template