accessing scope data outside ng-view in AngularJs -
i have spa , body of index.html below:
<body> <div id="wrapper"> <div data-ng-include src="'partials/header.html'"></div> <div data-ng-view=""></div> <div data-ng-include src="'partials/footer.html'"></div> </div> <script src="js/jquery.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="js/jquery.datatables.js"></script> </body>
the header partials has many links mapped controllers , ng-view populated corresponding partial file. have display logged in username in header.html file not able access scope data inside header.html file. populating username inside controllers , putting same inside scope.
please let me know how access scope data inside header.html can display username.
code snipper inside controller:
controllers.bagsctrl= function($scope, $location, $route){ console.log('inside leather bags controller..'); $scope.username = 'pradeep'; }
regards, pradeep
you can either create controller wraps application (on <div id="wrapper">
example) , declare username on $scope
or put username on $rootscope
, use directly in templates.
the first way seems cleaner.
Comments
Post a Comment