title: How to access a variable declared in the controller from the view?
body: <p>I am pretty new to AngularJS. I have trouble understanding how to access variables declared in the controller from the view. For example, in the code below I am not able to access the variable <code>filePath</code></p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div ng-controller = "buttonViewCtrl as buttonCtrl"&gt;
        {{ buttonCtrl.filePath }}
  &lt;/div&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>.controller('buttonViewCtrl', ['$scope', '$location', function($scope, $location) {
      $scope.filePath =  '';
      $scope.nav = function() {
          $scope.filePath = "Logged In";
   };
  </code></pre>
  
  <p>I am providing my entire application below for context:</p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" ng-app="myApp" class="no-js"&gt; 
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;title&gt;My AngularJS App&lt;/title&gt;
      &lt;meta name="description" content=""&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
      &lt;link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css"&gt;
      &lt;link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css"&gt;
  
      &lt;link rel="stylesheet" href="app.css"&gt;
  
      &lt;script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"&gt;&lt;/script&gt;
  
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/&gt;
      &lt;link rel="shortcut icon" href="images/favicon.ico" /&gt;
      &lt;link rel="stylesheet" href="css/anchour/anchour.css"/&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;div ng-view&gt;&lt;/div&gt;
      &lt;div&gt;Angular seed app: v&lt;span app-version&gt;&lt;/span&gt;&lt;/div&gt;
  
      &lt;script src="bower_components/angular/angular.js"&gt;&lt;/script&gt;
      &lt;script src="bower_components/angular-route/angular-route.js"&gt;&lt;/script&gt;
      &lt;script src="app.js"&gt;&lt;/script&gt;
      &lt;script src="view1/view1.js"&gt;&lt;/script&gt;
      &lt;script src="view2/view2.js"&gt;&lt;/script&gt;
      &lt;script src="buttonView/buttonView.js"&gt;&lt;/script&gt;
      &lt;script src="components/version/version.js"&gt;&lt;/script&gt;
      &lt;script src="components/version/version-directive.js"&gt;&lt;/script&gt;
      &lt;script src="components/version/interpolate-filter.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>app.js:</p>
  
  <pre><code>'use strict';
  
   angular.module('myApp', [
    'ngRoute',
    'myApp.view1',
    'myApp.view2',
    'myApp.version'
  ]).
  config(['$routeProvider', function($routeProvider) {
    $routeProvider.otherwise({redirectTo: '/view1'});
  }]);
  </code></pre>
  
  <p>view1.html:</p>
  
  <pre><code>&lt;div class="squirrel"&gt; 
        &lt;div class="logo"&gt;&lt;/div&gt;
        &lt;cite&gt;Every brand has a story.&lt;/cite&gt;
        &lt;h2&gt; &lt;a&gt;Watch the video &lt;/a&gt;&lt;/h2&gt;
        &lt;aside&gt; &amp;#x2192; &lt;/aside&gt;
  
        &lt;button type="button" class="btn btn-default btn-lg navButton" aria-label="Center Align" ng-controller = "buttonViewCtrl" ng-click="go('/buttonView')"&gt;
          &lt;span class="glyphicon glyphicon-align-justify" aria-hidden="true"&gt;&lt;/span&gt;
        &lt;/button&gt;
  
        &lt;div id = "arrow"&gt;
          &lt;img src = "images/pointer.png" alt = "arrow"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class = "panda"&gt;
        &lt;button type="button" class="btn btn-default btn-lg work"&gt; SEE OUR WORK &lt;/button&gt;
      &lt;/div&gt;
  
      &lt;div class = "experience"&gt;
        &lt;h1&gt; Our team builds great brands and experiences. &lt;/h1&gt;
        &lt;button type="button" class="btn btn-default btn-lg team"&gt; MEET THE TEAM &lt;/button&gt;
      &lt;/div&gt;
  
      &lt;section class = "about"&gt;
        &lt;h5&gt; WHAT ARE WE? &lt;/h5&gt;
        &lt;h2&gt; Anchour is a branding agency based in Maine. &lt;/h3&gt;
  
        &lt;p&gt; We weave together creative solutions to build personal brands and experiences. We work closely with your brand to understand your needs and create solutions that produce real results. By integrating the power of identity, digital, and sensory design, we bring new life to brands everywhere.
        &lt;/p&gt;
      &lt;/section&gt;
  
      &lt;div class = "goodWork"&gt;
        &lt;div class = "spotlight"&gt; 
          &lt;h3&gt; &lt;a href = "#"&gt; Spotlight: Amanda Brill of Las Vegas &lt;/a&gt; &lt;/h3&gt;
          &lt;p&gt; Amanda Brill is a Designer at Anchour. Fueled by the purpose of helping others, she works to bring the identity of a brand to life through a creative and intensive design process. to help brands effectively communicate who they she works to bring the identity of a brand to life through a creative... &lt;/p&gt;
          &lt;footer&gt; &lt;a href = "#"&gt; Read More &lt;/a&gt; &lt;/footer&gt;
        &lt;/div&gt;
  
        &lt;div class = "spotlight"&gt; 
          &lt;h3&gt; &lt;a href = "#"&gt; Spotlight: Amanda Brill of California &lt;/a&gt; &lt;/h3&gt;
          &lt;p&gt; Amanda Brill is a Designer at Anchour. Fueled by the purpose of helping others, she works to bring the identity of a brand to life through a creative and intensive design process. Her goal is to use design as a way to help brands effectively communicate who they sponsor and supporter Fueled by the purpose of.. &lt;/p&gt;
          &lt;footer&gt; &lt;a href = "#"&gt; Read More &lt;/a&gt; &lt;/footer&gt;
        &lt;/div&gt;
  
        &lt;div class = "spotlight"&gt; 
          &lt;h3&gt; &lt;a href = "#"&gt; Varney Agency: Protecting What You &lt;/a&gt; &lt;/h3&gt;
          &lt;p&gt; Anchour produced Varney Agencys latest spot featuring Matt Albrecht, owner of River Drive. Working with companies from all around the world, River Drive buys, sells, reconditions and recycles reconditions and ecycles owner of used. River Drive buys, sells Varney Agencys latest spot featuring Matt Albrecht.&lt;/p&gt;
          &lt;footer&gt; &lt;a href = "#"&gt; Read More &lt;/a&gt; &lt;/footer&gt;
        &lt;/div&gt;
  
        &lt;div class = "spotlight"&gt; 
          &lt;h3&gt; &lt;a href = "#"&gt;Announcing support of Not Here &lt;/a&gt; &lt;/h3&gt;
          &lt;p&gt; This week is Human Trafficking Awareness Week, so it’s great timing to share how proud we are to be a sponsor and supporter of Not Here latest spot featuring Matt Albrecht, reconditions and recycles owner of River Drive. Working with companies from all around the,a River Drive buys, sells.... &lt;/p&gt;
          &lt;footer&gt; &lt;a href = "#"&gt; Read More &lt;/a&gt; &lt;/footer&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class = "start"&gt;
        &lt;h2 id = "startWork"&gt; Want to work with us? &lt;/h2&gt;
        &lt;button type="button" class="btn btn-default btn-lg"&gt; Get Started &amp;#x2192; &lt;/button&gt;
      &lt;/div&gt;
  
      &lt;div id = "end"&gt;
        &lt;footer&gt;
          &lt;a href = "#"&gt; Home &lt;/a&gt;
          &lt;a href = "#"&gt; About us &lt;/a&gt;
          &lt;a href = "#"&gt; Our Team &lt;/a&gt;
          &lt;a href = "#"&gt; Blog &lt;/a&gt;
          &lt;a href = "#"&gt; Services &lt;/a&gt;
          &lt;a href = "#"&gt; Portfolio &lt;/a&gt;
          &lt;a href = "#"&gt; Contact &lt;/a&gt;
          &lt;a href = "#"&gt; Sitemap &lt;/a&gt;
      &lt;/footer&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>view1.js:</p>
  
  <pre><code>'use strict';
  
  angular.module('myApp.view1', ['ngRoute'])
      .config(['$routeProvider', function($routeProvider) {
          $routeProvider.
              when('/view1', {
                  templateUrl: 'view1/view1.html',
                  controller: 'View1Ctrl'
          }).
              when('/buttonView', {
                  templateUrl: 'buttonView/buttonView.html',
                  controller: 'buttonViewCtrl'
          });
      }])
  
  .controller('View1Ctrl', [ '$scope', function($scope) {
      $scope.name = '';
      $scope.names = [{name:"Chris"}, {name:"Calvin"}];
      $scope.addName = function() {
      $scope.names.push( {'name':$scope.name} );
      $scope.name = '';
      };
      }])
  
  .controller('buttonViewCtrl', ['$scope', '$location', function($scope, $location) {
      $scope.go = function( path ) {
          $location.path( path );
   };
  }]);    
  </code></pre>
  
  <p>view2.html</p>
  
  <pre><code>&lt;p&gt; What is going on &lt;/p&gt;
  </code></pre>
  
  <p>view2.js:</p>
  
  <pre><code>'use strict';
  
  angular.module('myApp.view2', ['ngRoute'])
  
  .config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/view2', {
      templateUrl: 'view2/view2.html',
      controller: 'View2Ctrl'
    });
  }])
  
  .controller('View2Ctrl', [function() {
  
  }]);
  </code></pre>
  
  <p>buttonView.html</p>
  
  <pre><code>&lt;a href = "#"&gt; Home &lt;/a&gt; 
  &lt;a href = "#"&gt; About us &lt;/a&gt; 
  &lt;a href = "#"&gt; Why &lt;/a&gt;
  </code></pre>
  
  <p>buttonView.js</p>
  
  <pre><code>'use strict';
  
  angular.module('myApp.buttonView', ['ngRoute'])
      .config(['$routeProvider', function($routeProvider) {
          $routeProvider.when('/buttonView', {
              templateUrl: 'buttonView/buttonView.html'
          });
      }])
  </code></pre>