angularjs点击在下面绑定数据

我现在用ng-reapeat动态添加了一个列表 ul li,但是我想点击某个li,就把他的值附在下面的input中,然后我就可以修改,上面的数据就跟着变。
这是我在codepen上写的一小半代码地址 codepen地址

expanderModule.directive('items',function(){
  var str='<li ng-repeat="p in todos">{{p.todotext}}<div>{{title}},<button ng-click="addlt($index)">del</button></div></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

<div ng-controller='SomeController'> 
           <ul >
               <items></items>
             </li>
            </ul>  
             <button ng-click='addd()'>dian</button>
      <div>想显示点击的值,并且能编辑可以相互绑定
        <input type="text" />
      </div>
阅读 2.5k
1 个回答

你可以设他们分别都有一个ngmodel的属性 然后你controller 中点击li的时候再去让他们互绑就好了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进