0
要素のグループを階層的に追加するAngularJsコードがあります。また、それぞれのボタンクリックでグループ要素を削除します。(AngularJsの)階層から動的に追加された要素/テンプレートを削除します。
問題は、子がない場合ノードを削除/削除できないことです。
削除機能で、ノードをまだ空にしようとしましたが、ノードは削除されません。
Script.js:
var myapp = angular.module('myApp', [])
.controller('nestedController', function($scope){
$scope.delete = function(data) {
if(data.nodes.length == 0)
{
data = {};
}
// Removes all the children nodes.
data.nodes = [];
};
...
});
HTML:
<html ng-app="myApp" ng-controller="nestedController">
<head>
<script type="text/ng-template" id="my-tmpl">
{{data.name}}
...
<button class="btn" ng-click="delete(data)" >Delete nodes</button>
<ul>
<li ng-repeat="data in data.nodes" ng-include="'my-tmpl'"></li>
</ul>
</script>
</head>
<body>
<ul >
<li ng-repeat="data in tree" ng-include="'my-tmpl'"></li>
</ul>
</body>
</html>
完全に機能コードがあなたのコードでPlunker