search

Home  >  Q&A  >  body text

angular.js - angularjs click bind data below

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>
世界只因有你世界只因有你2868 days ago681

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:56:38

    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

    reply
    0
  • Cancelreply