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>
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