angularjs - Access parent controller from the child state -


i have controller in angluarjs defined so:

'use strict';  var app = angular.module('app');  app.controller('appctrl', ['sth',     function (sth) {         this.inverse = false;     } ]); 

here routes deffinition:

$stateprovider. state('app', {     abstract: true,     templateurl: 'app/views/layout.html',     controller: 'appctrl',     controlleras: 'app',     resolve: {} }). state('app.settings', {     abstract: true,     url: '/settings',     template: '<ui-view/>',     onenter: function () {      } }); 

how access inverse variable appctrl in app.settings route?

if want share data between 2 controllers, service/factory best bet. below example of how it. have written free-hand, there may syntax errors, idea.

app.controller('appctrl', ['sth', 'shareddata',     function (sth, shareddata) {         shareddata.inverse = false;     } ]);  app.factory('shareddate', function() {   var data = {      inverse: true  // or whatever default value want set   };    return data; }) 

now, can inject shareddata factory in controller, want use data.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -