I have accessed my parent scope plenty of times via $scope.$parent, however i am trying to integrate the ui-router
within my project and no long have access to $scope.parent
Here's a plunker: http://plnkr.co/edit/hdoXBngnMatk6HKj4fMC?p=preview
Ive created 2 buttons, one with nested view and controller, and one without.. When you click on the button that is not nested:
- 1:
errorBanner
is set to true - 2:
{{myMessage}}
gets set a value
However, on click of the button that is nested, {{myMessage}}
no longer updates.
app.js
var app = angular.module('plunker', ['ui.router']);
app.config(["$stateProvider", "$urlRouterProvider", function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/index');
$stateProvider
.state('index', {
url: '/index',
templateUrl: 'view.html'
})
}]);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
app.controller('nestedController', function($scope) {
$scope.setValue = function () {
$scope.$parent.errorBanner = true;
$scope.$parent.myMessage = 'hey, it updated!';
}
});
app.controller('nonNestedController', function($scope) {
$scope.setValue = function () {
$scope.$parent.errorBanner = true;
$scope.$parent.myMessage = 'hey, it updated!';
}
});