Last active
December 26, 2022 05:00
-
-
Save krtek/d74d9157b7bc9b4a21b3 to your computer and use it in GitHub Desktop.
AngularJS modular application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app', ['ngRoute', 'app.core', 'app.user', 'app.settings']) | |
.config(function($routeProvider, $locationProvider) { | |
$routeProvider.when('/home', { | |
templateUrl: 'partials/home.html', | |
controller: 'HomeCtrl' | |
}); | |
//Handle all exceptions | |
$routeProvider.otherwise({ | |
redirectTo: '/home' | |
}); | |
}) | |
.config(function(MenuProvider) { | |
MenuProvider.add({ | |
url: '/home', | |
title: 'Home' | |
}); | |
}); | |
//HomeCtrl should be defined here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app.core', []).provider('Menu', function() { | |
var _menu = []; | |
this.$get = function() { | |
return { | |
getItems: function() { | |
return _menu; | |
} | |
}; | |
}; | |
this.add = function(item) { | |
_menu.push(item); | |
}; | |
}) | |
.controller('MenuCtrl', function($scope, Menu) { | |
$scope.menu = Menu.getItems(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app.settings', ['app.core']).config(function($routeProvider, $locationProvider) { | |
$routeProvider.when('/settings', { | |
templateUrl: 'partials/settings.html', | |
controller: 'SettingsCtrl' | |
}); | |
}) | |
.config(function(MenuProvider) { | |
MenuProvider.add({ | |
url: '/settings', | |
title: 'Settings' | |
}); | |
}); | |
//SettingsCtrl should be defined here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app.user', ['app.core']).config(function($routeProvider, $locationProvider) { | |
$routeProvider.when('/profile', { | |
templateUrl: 'partials/profile.html', | |
controller: 'ProfileCtrl' | |
}); | |
$routeProvider.when('/account', { | |
templateUrl: 'partials/account.html', | |
controller: 'AccountCtrl' | |
}); | |
}) | |
.config(function(MenuProvider) { | |
MenuProvider.add({ | |
url: '/profile', | |
title: 'Profile' | |
}); | |
MenuProvider.add({ | |
url: '/account', | |
title: 'Account' | |
}); | |
}); | |
//ProfileCtrl, AccountCtrl should be defined here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment