its my first time asking here and i would like to know if there is any way to separate files in AngularJS.
I have UI Route but everytime i want to create an external controller i have to declare it on the head of the page.
My code looks like this:
app.js:
'use strict';
// Declare app level module which depends on views, and core components
angular.module('mainApp.controllers', [
"ui.router"
]).config(function($stateProvider, $locationProvider, $urlRouterProvider) {
// creating routes or states
$stateProvider
.state('dashboard', {
url : '/dashboard',
templateUrl : 'templates/home.html',
controller: "HomeController"
})
.state('apartments', {
url : '/apartments',
templateUrl : "templates/Apartments/apartments.html",
controller : "ApartmentsController"
}).state('longstay', {
url : '/longstay',
templateUrl : 'templates/Longstay/longstay.html',
controller: 'LongstayController'
}).state('logout', {
url : '/home'
}).state('login', {
url : '/login',
templateUrl : 'templates/Authentication/authentication.html',
controller: 'AuthenticationController'
});
// Redirect to home page if url does not
// matches any of the three mentioned above
$urlRouterProvider.otherwise("/dashboard");
})
// create empty controllers for the states as we are
// not doing anything but just displaying message
.controller('MainCtrl', function () {});
index.html:
<script src="app.js"></script>
<!-- Controller includes -->
<script src="templates/HomeController.js"></script>
<script src="templates/Apartments/ApartmentsController.js"></script>
<script src="templates/Authentication/AuthenticationController.js"></script>
<script src="templates/Longstay/LongstayController.js"></script>
I want to find a way to import this controllers but have them in external folders with their templates or views in there without anything in the index.html just import them inside app.js.
"Would love" folder structure:
app/|
|-Apartments/|
| |-apartments.tpl.html
| |-ApartmentsController.js
| |-ApartmentsFactory.js
|
|
|-app.js
|-index.html
If anyone could help i would be very grateful!