如何更改相同的 ng 重复值并仅显示选择值 angularjs
how to change same ng-repeat values and show only select values angularjs
>更新我想从显示的单个输入文本框中分别更改 ng 重复值,我正在尝试将输入框绑定到标签,但是所有值都绑定在一起,您能否告诉我如何仅更改选定的div 值,我不想使用 ng-repeat 来添加值,请告诉我在开始使用 ng-repeat 的情况下再次添加您可以使用 ng-repeat 进一步的功能,表单应显示在某个位置以更改输入框中的值以标记, 你能给我解决这个问题吗..??工作演示
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;
}
});
.add{
position: absolute; height: auto; width: 200px; left: 0; right: auto; top: 0; bottom: 0;
}
.show{
position: absolute; width: auto; left: 200px; right: 0; top: 0; bottom: 0;
border:1px solid red;
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">
<div class="add"><button ng-click="add_New($index)">add Again</button>
<div id="drop">
</div>
</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>
你需要改变你对html元素的思考方式。忘掉jQuery,专注于角度方式。
首先,你不需要处理新的html元素。我们需要摆脱这种var itemhtml
和$compile(itemhtml)
.其次,您需要更改数据模型。
. * 在下面更新 这里 * .
有关详细信息,请参阅更新的 Plunker。
您的控制器将是这样的:
app.controller('AddCtrl', function ($scope, $compile) {
$scope.itemGroups = [];
$scope.addGroup = function () {
$scope.itemGroups.push({
items: []
});
};
$scope.addItem = function (itemGroup) {
itemGroup.items.push({
name: "hi"
});
};
$scope.editItemGroup = function (itemGroup) {
$scope.selectedItemGroup = itemGroup;
};
});
你的html应该像这样使用ng-repeat:
<div ng-repeat="itemGroup in itemGroups" class="add">
<button ng-if="itemGroup != selectedItemGroup"
ng-click="editItemGroup(itemGroup)">Edit</button>
<div ng-repeat="item in itemGroup.items">
{{$index + 1}}.<label ng-bind="item.name"></label>
</div>
<button ng-click="addItem(itemGroup)">Add</button>
</div>
<div ng-repeat="item in selectedItemGroup.items">
{{$index + 1}}.<input type="text" ng-model="item.name">
</div>
<button ng-click="editItemGroup(null)" ng-if="selectedItemGroup">Done editing</button>
相关文章:
- angularjs+rails应用程序中未显示模板
- 如何通过所选索引(AngularJS)在模态弹出窗口中显示数据
- 显示&作为&在jsp中使用angularjs而不使用ng-bind-html
- Angularjs显示给定ISO格式的日期
- 在angularjs/google地图中显示分支最近的路线
- 使用angularjs ng Show/ng hide显示和隐藏不同的内容
- AngularJs的动态模板显示具有相同的路线
- 在$http之前调用时不显示 Angularjs 变量
- 用户离开字段后立即显示AngularJS引导工具提示以进行客户端验证
- 显示AngularJs中响应的Div
- 当使用jekyll和liquid时显示angularjs模型数据
- 如何用json对象显示angularjs ng repeat
- Post Author不显示(AngularJS, $http, MongoDB) - Thinkster MEAN S
- 没有显示Angularjs的路由模板
- 输入值不显示(AngularJS)
- 显示AngularJs表单的客户端和服务器端错误信息
- 在视图中显示AngularJS内容
- 嵌套指令未显示.AngularJS.
- HTML没有显示angularjs的变量值
- 没有显示Angularjs指令