Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Created May 16, 2013 15:10
Show Gist options
  • Save leocavalcante/5592449 to your computer and use it in GitHub Desktop.
Save leocavalcante/5592449 to your computer and use it in GitHub Desktop.
AngularJS + require.js example
define([
'angular',
'bar_controller',
'router'
],
function(angular, barCtrl, router)
{
var app,
appName = 'foo';
app = angular.module(appName, []);
app.controller('BarController', barCtrl);
app.config(router);
return {
name: appName
};
});
define(function()
{
return function($scope)
{
$scope.baz = 'qux';
}
})
require.config({
paths: {
'angular': '<cdn> or <project vendors path>'
},
shim: {
'angular': {
exports: 'angular'
}
}
});
require(['angular', 'app'], function(angular, app)
{
angular.bootstrap(document, [app.name]);
});
define([
'text!views/bar.html'
],
function(barView)
{
return function($routeProvider)
{
$routeProvider
.when('/',
{
controller: 'BarController'
template: barView
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment