Trying to implement modular loading using requirejs into angularjs. Having a hard time to understand requirejs and its config options. Here's what i have so far. My questions are below
index.html
<!DOCTYPE HTML>
<html>
<head>
<link href="app/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="app/css/style.css" rel="stylesheet">
<script data-main="app/main.js" src="app/vendor/require/require-2.1.11.min.js"></script>
</head>
<body>
<div id="wrapper">
<div ng-include="flexyLayout('header')"></div>
<div ng-view id="content"></div>
<div ng-include="flexyLayout('footer')"></div>
</div>
</body>
</html>
main.js
require.config({
paths: {
'angular': 'vendor/angular/angular.min',
'angular-route': 'vendor/angular/angular-route.min',
'angular-cookies': 'vendor/angular/angular-cookies.min'
},
shim: {
angular: {
exports: 'angular'
},
'angular-route' : {
exports : 'angular',
deps : ['angular']
},
'angular-cookies' : {
deps : ['angular']
}
}
});
require(
[
'angular',
'app',
'module/login/login',
'services/services'
],
function(angular, app) {
'use strict';
angular.bootstrap(document, ['myApp']);
});
app.js
define(['angular', 'angular-route'], function(angular) {
var app = angular.module("myApp", ['ngRoute']);
app.config(function ($routeProvider,$httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/module/public/index.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html'
})
.when('/login', {
templateUrl: 'app/module/login/login.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html'
})
.when('/home', {
templateUrl: 'app/module/home/home.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html'
})
.when('/register', {
templateUrl: 'app/module/register/register.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html'
})
.when('/admin', {
templateUrl: 'app/module/admin/admin.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html',
permission: 'admin'
})
.when('/unauthorized', {
templateUrl: 'app/partials/unauthorized.html',
header: 'app/partials/header.html',
footer: 'app/partials/footer.html'
})
.otherwise({redirectTo: '/'});
});
return app;
});
login.js
define(['app','services/services'], function (app) {
app.controller('LoginCtrl', function($scope,AuthenticatorService,CookieService,$window,$location) {
$scope.user = {};
$scope.login = function() {
AuthenticatorService.authenticate($scope.user).then(function(response){
if(response.authentication) {
CookieService.saveLoginData(response.user);
$window.location.href = $location.absUrl()+'home';
}else {
$scope.error = response.message;
$scope.user = {};
}
});
}
});
});
Questions:
The angularjs cookies file isn't loading up due to which i am getting unknown provider error. When i inspect the element, i can see angularjs and angular-route js files loaded but not angularjs cookies file. Is the setting in
shimoption incorrect forangular-cookies?How to load services and directives? My
services.jsfile is inside theservicesfolder. Am i loading it the correct way by calling it inrequire? Can i load services.js file in thepathsoption of therequire.config?I read through some of the posts here but did not clearly understand how to use requirejs to load modular file. Example, i have different modules like login , admin, register etc. How do i load the individual module js files using requirejs. Below is my root folder structure

I would appreciate if anyone could explain me with code. If you need any other detail plz let me know and sorry for such a long post. Couldn't explain it in brief