How to create an abstract route with global controller for your children in Angularjs

Asked

Viewed 211 times

1

I am creating an application where I will create something similar to a "Wizzard" windows Forms and for this I am using a routing as follows:

.state("vendaOrcamento", {
  url: "/vendaOrcamento",
  abstract:true,
  templateUrl: "templates/comercial/vendaOrcamento.html"
})
.state('vendaOrcamento.cliente', {
  url: "/cliente",
  views: {
    'tab-cliente': {
      templateUrl: "templates/comercial/vendaOrcamento/1cliente.html"
    }
  }
})
.state('vendaOrcamento.produtos', {
  url: "/produtos",
    views: {
      'tab-produtos': {
        templateUrl: "templates/comercial/vendaOrcamento/2produtos.html"
      }
    }
  })

I need that both for the son client as for the son products there is an object vendaOrcamento global, so regardless of which child I am, I will always be working with the same object without losing the data already treated earlier, basically need this:

$scope.vendaOrcamento = {
  cliente : {},
  produtos : {}
}

My problem is that I don’t understand very well how I can work like this, I even tried to create a Controller directly on view Dad(Mark) But it didn’t go very well... can someone give me a light please?

2 answers

3

You can try using a Factory to share data between controllers.

There is plenty of content ready, just search something like "share data between controllers".

0


I gave a good read on what @Guilhermesantos said and was a very functional option, but I ended up opting for a value because even if the person starts editing but leaves this screen I have to go back to the same continue where you left off

Browser other questions tagged

You are not signed in. Login or sign up in order to post.