Update ng-repeat out of ng-view?

2

I have a fixed menu at the top, where pages are opened via routes in ng-view.

In an X view I add a new element to my database, and in the drop-down menu I use ng-repeat to list these elements.

When I add something new to the database this ng-repeat from the fixed menu is not updated, only if you use F5.

Is there any way to update this ng-repeat that is in the fixed menu (outside ng-view) without using F5?

    
asked by anonymous 16.12.2015 / 21:05

2 answers

2

I agree 100% with the colleague above, follow a simple example below:

 var servico1 = function() { 
      var servico = this; 
      servico.listaInserido = [];

      servico.add = function(item) { servico.listaInserido.push(item) }
 }
 var controllerfixo = function($scope, servico1) { $scope.servico = servico1; }
 var controllerrelativo = function($scope, servico1) { $scope.servico = servico1; }

 var app = angular.module('app');
 app.service('servico1', servico1);
 app.controller('controlerfixo', controllerfixo);
 app.controller('controllerrelativo', controllerrelativo);

HTML

<ul class="fixo" ng-controller="controllerfixo">
   <li ng-repeat="item in servico.listaInserido">{{item}}</li>
<ul> 

<div ng-controller="controllerrelativo">
     <button ng-click="servico.add({ a: 1})">add</button>
</div>
    
23.12.2015 / 20:38
2

A possible template can implement a service that is responsible for containing the collection, exposed via a member.

Inject this service into the controller that feeds your view , and bind this member to $scope of your view containing ng-repeat .

Use a service method to force the list to update whenever necessary.

    
16.12.2015 / 22:03