Skip to content

Instantly share code, notes, and snippets.

@mfdj
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfdj/8588ad4c9390ed957b1c to your computer and use it in GitHub Desktop.
Save mfdj/8588ad4c9390ed957b1c to your computer and use it in GitHub Desktop.
angular.js naming conflicts
<!DOCTYPE html>
<html lang="en" ng-app="fightApp">
<head>
<meta charset="UTF-8">
<title>angular module fights</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h3>Module Eh vs. Module Bee</h3>
<div my-directive>{{ winner }} won the Directive fight!</div>
<div ng-controller="MyController">
<p>{{ winner }} won the Controller fight!</p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.js"></script>
<script>
/**
* eh
*/
angular.module('eh', [])
.controller('MyController', function($scope) {
$scope.winner = 'Module Eh';
})
.directive('myDirective', function() {
return {
link: function(scope) { scope.winner = 'Module Eh' }
}
})
;
/**
* bee
*/
angular.module('bee', [])
.controller('MyController', function($scope) {
$scope.winner = 'Module Bee';
})
.directive('myDirective', function() {
return {
link: function(scope) { scope.winner = 'Module Bee' }
}
})
;
/**
* SET 'fightApp' with two arugments: angular.module(name:string, dependencies:array)
*/
angular.module('fightApp', ['eh', 'bee']);
/**
* GET 'fightApp' with one arugment: angular.module(name:string)
*/
angular.module('fightApp')
.controller('SomeOtherController', function($scope) {
$scope.someOtherVar = '¡hola!';
})
;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment