Created
July 22, 2016 07:59
-
-
Save iplus26/59bc37cf45deeae78ce8ba19a1037813 to your computer and use it in GitHub Desktop.
Angular Dependency 在调用“后”申明
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
<!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