lundi 29 décembre 2014

How do I share $scope data between states in angularjs ui-router?


Without using a service or constructing watchers in the parent controller, how would one give children states access to the main controller's $scope.



.state("main", {
controller:'mainController',
url:"/main",
templateUrl: "main_init.html"
})
.state("main.1", {
controller:'mainController',
parent: 'main',
url:"/1",
templateUrl: 'form_1.html'
})
.state("main.2", {
controller:'mainController',
parent: 'main',
url: "/2",
templateUrl: 'form_2.html'
})


I'm not able to access the mainController scope in child state--or rather I'm getting another instance of that scope--not what I want. I feel I'm missing something simple. There is a shared data config option in the state object but I'm not sure if this should be used for something like this.





Aucun commentaire:

Enregistrer un commentaire