Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular JS - loading a controller from a JS file
    text
    copied!<p>This controller works just fine:</p> <pre><code>function airlineRouter($routeProvider) { $routeProvider .when('/', { templateUrl:"partials/destinations.html", controller: function($scope) { $scope.setActive('destinations'); } //end controller }); } //end airlineRouter </code></pre> <p>When I make the controller it's own JS file, it doesn't work anymore. Like this:</p> <pre><code>function airlineRouter($routeProvider) { $routeProvider when('/', { templateUrl:"partials/destinations.html", controller: "DestinationsCtrl" }); } //end airlineRouter </code></pre> <p>My Controller file resides in 'root/js/controllers/destinations.js', which is the same folder my 'app.js' file resides. The complete 'app.js' file looks like this:</p> <pre><code> angular .module('airline', ['ngRoute']) .config(airlineRouter); function airlineRouter($routeProvider) { $routeProvider .when('/', { templateUrl:"partials/destinations.html", controller: "DestinationsCtrl" } ); } //end airlineRouter </code></pre> <p>My complete controller JS file looks like this:</p> <pre><code>function DestinationsCtrl($scope) { $scope.setActive('destinations'); } //end DestinationsCtrl </code></pre> <p>Why won't my controller load by the function name as this tut I'm doing says? The tut's file seems to work. Mine isn't.</p> <p>Edit: console log shows this: Error: [ng:areq] Argument 'DestinationsCtrl' is not a function, got undefined</p> <p>Edit 2: The tut I was working on was called 'Nesting Scopes', if that gives anyone a better idea of what I'm trying to do.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload