Skip to content

Instantly share code, notes, and snippets.

@iplus26
Created July 22, 2016 07:59
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 iplus26/59bc37cf45deeae78ce8ba19a1037813 to your computer and use it in GitHub Desktop.
Save iplus26/59bc37cf45deeae78ce8ba19a1037813 to your computer and use it in GitHub Desktop.
Angular Dependency 在调用“后”申明
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div ng-app="app">
<div sample-di>
{{ sampleData }}
</div>
</div>
<script>
var mod = angular.module('app', []);
(function(app) {
// Dependency after
app
.service('dep1', function() { this.name = 'dep1'; })
.directive('sampleDi', ['dep1', 'dep2', function(dep1, dep2) {
return {
restrict: 'EA',
link: function(scope) {
scope.sampleData =
'Depends on ' + dep1.name + ' and ' + dep2.name;
}
}
}])
.service('dep2', function() { this.name = 'dep2'; });
})(mod);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment