0

I have the next code:

<ol class="breadcrumb"> <li ng-repeat="ruta in rutas" > <a ng-click="seleccionarDirectorioRuta(ruta)" >{{ruta.nombre}}</a> </li> </ol> 

the method seleccionarDirectorioRuta:

$scope.seleccionarDirectorioRuta = function(directorio){ alert($scope.rutas.length); $scope.directoriosActuales = []; $scope.rutas.push(directorio); alert($scope.rutas.length); }; 

In the alerts show 1 and 2 (or n and n+1), but the breadcrumb don't updated.

Any idea?

2 Answers 2

2

I was getting an error that ngRepeat doesn't accept duplicates, but after I used angular.copy to make a copy of directorio when pushing into $scope.rutas it all worked.

http://plnkr.co/edit/dkIoiql1snvY7oauDNrW?p=preview

$scope.seleccionarDirectorioRuta = function(directorio){ $scope.rutas.push(angular.copy(directorio)); }; 
Sign up to request clarification or add additional context in comments.

Comments

0

Its not a bug in Angular. Its because when you run the function, you set the array to be empty for every single run. Without pulling up the code, I'd assume you would want something along these lines:

$scope.directoriosActuales = []; $scope.seleccionarDirectorioRuta = function(directorio){ alert($scope.rutas.length); $scope.rutas.push(directorio); alert($scope.rutas.length); }; 

But since that will likely run wrong, I think the forEach will help.

Can you let me know if setting the array to none is the reason?

1 Comment

ng-repeat="ruta in rutas", in this case $scope.directoriosActuales has nothing to do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.