I have a directive declared inside another directive, which should use a single variable from parent scope. This is what the structure looks like:
MAIN CONTROLLER:
angular.module('app')
.controller('MainCtrl', function ($scope, Settings){
$scope.userName = "";
$scope.init = function(){
Settings.getUser()
.then(function (res) {
$scope.userName = res.data.userName;
console.dir(res);
}).catch(function (err) {
//showError(err.data)
});
};
}
main.html
<div id="wrapper">
<!-- Navigation -->
<header></header>
<!-- /.navbar-top-links -->
<!-- /.navbar-static-side -->
<div id="page-wrapper" style="min-height: 561px;">
<div ui-view></div>
</div>
<!-- /#page-wrapper -->
</div>
header.html
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<header-notification user-name="{{userName}}"></header-notification>
</nav>
header-notification.js
angular.module('app')
.directive('headerNotification', function (Settings, $ngBootbox) {
return {
templateUrl: 'scripts/directives/header/header-notification/header-notification.html',
restrict: 'E',
scope: {
'userName': '='
},
controller: ['$scope', function ($scope) {
console.log($scope.userName);
}],
link: function (scope, element, attrs) {
console.log(scope.userName);
}
}
});
I am not able to access the value, I have also tried scope.$watch but still getting undefined in value..