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
Post a Comment