Last active
August 29, 2015 14:14
-
-
Save mfdj/8588ad4c9390ed957b1c to your computer and use it in GitHub Desktop.
angular.js naming conflicts
This file contains 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
<!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