Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

My app runs all fine as long as I have controllers.js as a sibling of app.js but when I move it to controllers folder and allow webStorm to do its magic by changing its reference from

script src="controllers.js"></script>

to

script src="js/controllers/controllers.js"></script>

the app loses the functionalities in that file.
What am I doing wrong? Thanks

enter image description here

//---app.js---

(function () {                                           
    'use strict';

    angular
        .module('angApp', ['ngRoute'])                 
        .config(['$routeProvider', routeProvider]);     
})();

function routeProvider ($routeProvider) {
    $routeProvider.when('/list', {
        templateUrl: 'partials/mainMenu.html',
        controller: 'MainMenuCtrl'
    }).otherwise({      //home page
        redirectTo: '/list'
    });
}

//better do manual bootstrap and better done last
angular.element(document).ready(function () {
    angular.bootstrap(document, ['angApp']);
});


//---controllers.js---

angular
    .module('angApp')                                                   
    .controller('MainMenuCtrl', ['$scope', '$http', MainMenuCtrl]);     

function MainMenuCtrl ($scope, $http) {
    $http.get('js/mainMenu.json').then(
        function (response) {
            $scope.menuItems = response.data;
        },
        function (error) {
            alert("http error");
        }
    )
}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="angular.js"></script>
    <script src="angular-route.js"></script>
    <script src="js/app.js"></script>
    <script src="js/controllers/controllers.js"></script>
    <meta name="viewport" content="width=device-width" />
</head>

<body>
<header>
    <button class="menuLeft" type="button" ng-click="mainMenuToggle()">&#9776;</button>
    <label class="pageTitle">Title of Page</label>
    <button class="menuRight" type="button">&#8942;</button>
</header>

<main ng-view></main>

<footer>
    <ul class="horizontal-style">
        <li><button type="button">NO</button></li>
        <!--<li><button type="button">EXTRA</button></li>-->
        <li><button type="button">YES</button></li>
    </ul>
</footer>

</body>
</html>

share|improve this question
    
I had a similar problem and I solved it by adding <base href="/"> into the document head tag (You might need to change the path to the root URL of your website) – Alon 21 hours ago
    
I tried that for no avail. '<base href="Users/empl1/Documents/an1/">' which is where index.html lives. – Fred J. 21 hours ago
    
It should be the URL (Example http://localhost/myAngularProject/) – Alon 21 hours ago
    
Yes. that worked. Thank you :) – Fred J. 21 hours ago
    
You're welcome :) – Alon 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.