Angularjs 在angular中从ng repeat中删除元素后,如何更新作用域?

Angularjs 在angular中从ng repeat中删除元素后,如何更新作用域?,angularjs,Angularjs,我试图实现的是,当我双击网格中的项目时,我在其中遍历,根据它,我的面包屑正在更新。但当我在面包屑中单击后退时,面包屑先前的值将被删除,但当我通过双击再次向内移动时,它也会显示先前删除的值。我附上我的代码和一个图像,以便更好地理解 <div id="breadCrumb"><div ng-click="breadCrumbFilter('^/xyz/$')" style="float:left;">xyz</div> <div ng-repeat="bC

我试图实现的是,当我双击网格中的项目时,我在其中遍历,根据它,我的面包屑正在更新。但当我在面包屑中单击后退时,面包屑先前的值将被删除,但当我通过双击再次向内移动时,它也会显示先前删除的值。我附上我的代码和一个图像,以便更好地理解

 <div id="breadCrumb"><div ng-click="breadCrumbFilter('^/xyz/$')" style="float:left;">xyz</div>
<div ng-repeat="bCrumb in bCrumbs" id="{{bCrumb.name}}" style="float:left;
" ng-click="breadCrumbFilter(bCrumb)">{{ bCrumb.name }}</div></div> 
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
  $scope.filterOptions = {
    filterText: '^/xyz/$'
  };

   $scope.breadCrumbFilter = function(bCrumb) {
        var filterText = bCrumb.path;
        if(filterText == null){
             filterText = bCrumb;
    }
       var active = $scope.filterOptions.filterText;
         if ($scope.filterOptions.filterText === filterText) {

          $scope.filterOptions.filterText = filterText;
        }
        else if ($scope.filterOptions.filterText !== '' ) {

          $scope.filterOptions.filterText = filterText;
        }

        $scope.resetBreadcrumbs(filterText,active);
      };
      $scope.resetBreadcrumbs = function(fText,rActive){

          var reset = fText;

          var activeBreadcrumbs = rActive;

          activeBreadcrumbs = activeBreadcrumbs.substring(reset.length -1,     activeBreadcrumbs.lastIndexOf("/"));

          var myEl =  angular.element(document.getElementById('/ '+activeBreadcrumbs));

          myEl.remove();


      };
    $scope.filterFpath = function(row) {

     var fileName  = row.entity.name;
      var folderPath = row.entity.Full_Path;
      var newPath = folderPath+fileName+'/';
        var filterText = '^'+newPath+'$';
    if ($scope.filterOptions.filterText ==='^'+folderPath+'$') {
  $scope.filterOptions.filterText = filterText;
     }
else if ($scope.filterOptions.filterText === filterText) {
      $scope.filterOptions.filterText = '';
}
    $scope.addname('/ '+fileName,filterText);
   };
   $scope.bCrumbs = [] ;
          $scope.addname=function(name,path)
            {

            obj={};
            obj['name'] = name;
            obj['path'] = path;
              $scope.bCrumbs.push(obj);

            };
    var rowTempl = '<div ng-dblClick="filterFpath(row)" ng-style="{ \'cursor\': row.cursor   }" ng-repeat="col in renderedColumns" '+'ng-class="col.colIndex()" class="ngCell{{col.cellClass}}"><div ng-cell></div></div>';
  $scope.myData = [{name: "Moroni", Full_Path: "/xyz/"},
               {name: "Tiancum", Full_Path: "/xyz/Moroni/"},
               {name: "Jacob", Full_Path: "/xyz/"},
               {name: "Nephi", Full_Path: "/xyz/Moroni/Tiancum/"},
               {name: "Nephiss", Full_Path: "/xyz/"}];

  $scope.gridOptions = {
    data: 'myData',
    filterOptions: $scope.filterOptions,
 rowTemplate: rowTempl,
  };
});
xyz
{{bCrumb.name}
var-app=angular.module('myApp',['ngGrid']);
应用程序控制器('MyCtrl',函数($scope){
$scope.filterOptions={
filterText:“^/xyz/$”
};
$scope.breadCrumbFilter=函数(bCrumb){
var filterText=bCrumb.path;
if(filterText==null){
filterText=bCrumb;
}
var active=$scope.filterOptions.filterText;
如果($scope.filterOptions.filterText===filterText){
$scope.filterOptions.filterText=filterText;
}
else if($scope.filterOptions.filterText!=''){
$scope.filterOptions.filterText=filterText;
}
$scope.resetBreadcrumbs(filterText,活动);
};
$scope.resetBreadcrumbs=函数(fText,rActive){
var重置=fText;
var activeBreadcrumbs=rActive;
activeBreadcrumbs=activeBreadcrumbs.substring(reset.length-1,activeBreadcrumbs.lastIndexOf(“/”);
var myEl=angular.element(document.getElementById('/'+activeBreadcrumbs));
myEl.remove();
};
$scope.filterPath=函数(行){
var fileName=row.entity.name;
var folderPath=row.entity.Full_路径;
var newPath=folderPath+fileName+'/';
变量filterText='^'+newPath+'$';
如果($scope.filterOptions.filterText=='^'+folderPath+'$')){
$scope.filterOptions.filterText=filterText;
}
else if($scope.filterOptions.filterText===filterText){
$scope.filterOptions.filterText='';
}
$scope.addname(“/”+文件名,filterText);
};
$scope.bCrumbs=[];
$scope.addname=函数(名称、路径)
{
obj={};
obj['name']=名称;
obj['path']=路径;
$scope.bCrumbs.push(obj);
};
var rowTempl='';
$scope.myData=[{name:“Moroni”,完整路径:“/xyz/”},
{name:“Tiancum”,完整路径:“/xyz/Moroni/”},
{name:“Jacob”,完整路径:“/xyz/”},
{name:“Nephi”,完整路径:“/xyz/Moroni/Tiancum/”,
{name:“Nephiss”,完整路径:“/xyz/”}];
$scope.gridOptions={
数据:“myData”,
filterOptions:$scope.filterOptions,
rowTemplate:rowTemplate,
};
});
现在发生了什么: 默认情况下,在面包屑“xyz”中加载数据时显示第一个图像

  • 当双击moroni时,它在内部被遍历,面包屑被更新
  • 当我单击xyz时,请再次返回:
  • 再次,如果我在莫罗尼内部遍历,其显示如下:

  • 有什么问题我想不出来

    通过查看您的代码,我发现您正在删除dom元素,但并没有从数组中删除它,所以请尝试查找所需删除文件的索引,然后在其中使用“切片”

    试着这样做:

    <div id="breadCrumb"><div ng-click="breadCrumbFilter('^/xyz/$')" style="float:left;">xyz</div>
    <div ng-repeat="bCrumb in bCrumbs" id="{{bCrumb.name}}" style="float:left;
    " ng-click="breadCrumbFilter(bCrumb,$index)">{{ bCrumb.name }}</div></div> 
    
       $scope.breadCrumbFilter = function(bCrumbs,$index) {
         $scope.bCrumbs.splice($index+1);
         var d = $scope.bCrumbs.length -1;
         path = bCrumbs[d].path;
        var filterText = path;
        if(filterText == null){
             filterText = bCrumb;
    }
       var active = $scope.filterOptions.filterText;
         if ($scope.filterOptions.filterText === filterText) {
    
          $scope.filterOptions.filterText = filterText;
        }
        else if ($scope.filterOptions.filterText !== '' ) {
    
          $scope.filterOptions.filterText = filterText;
        }
    
      };
    
    xyz
    {{bCrumb.name}
    $scope.breadCrumbFilter=函数(bCrumbs,$index){
    $scope.bCrumbs.splice($index+1);
    var d=$scope.bCrumbs.length-1;
    path=bCrumbs[d]。路径;
    var filterText=路径;
    if(filterText==null){
    filterText=bCrumb;
    }
    var active=$scope.filterOptions.filterText;
    如果($scope.filterOptions.filterText===filterText){
    $scope.filterOptions.filterText=filterText;
    }
    else if($scope.filterOptions.filterText!=''){
    $scope.filterOptions.filterText=filterText;
    }
    };
    

    试试这个。

    您能在JSFIDLE/plnrk上发布代码作为工作示例吗?plunker link在删除面包屑后,此plnkr没有更新好,在查看plnkr后,我不知道它应该如何工作以及有什么问题。@Rasalon在从ng中删除某些元素后,请告诉我重复如何更新范围,好吗