I am fairly new to using AngularJS and am trying to create a simple proof of concept with a static navigation bar to choose what action you would like to do. Currently I am using my index.html file as a "template" which includes the HTML for the nav bar then the ng-view via the $routeProvider.
<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html lang="en" ng-app="myApp" class="no-js">
<!--<![endif]-->
<head>
</head>
<body class="container">
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-fixed-top" ng-controller="NavController">
<!-- navbar buttons, links, etc. -->
</nav>
<div ng-view>
</div>
<!-- all the javascript imports down here . . . -->
</html>
What I am attempting to do is use a controller(NavController) to control the visibility of different links depending on whether the user is logged in or not. Things seem fine when I originally hit the landing page, but as soon as I route things to a different view it seems like the NavController loses scope or something.
For instance if I go to another link in my app and look at the scope in the debugger I see { This scope has no models }
. If I hit refresh and look at the scope again I see the data as I would expect and things look correct.
I've done a little testing trying to figure things out and noticed that if I reference the NavController inside the ng-view then everything works fine, so I assume I am going about things the wrong way. Is there a certain way to go about getting this functionality?