时间:2021-07-01 10:21:17 帮助过:11人阅读
<!DOCTYPE html><html ng-app="myApp"><head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="js/angular.js"></script>
<script src="js/demo13.min.js"></script></head><body><p ng-controller="myCtrl">
<button ng-click="handleClick()">
clickMe </button></p></body></html>js代码
:
var app = angular.module('myApp', ['ng']);
app.factory('$student', function () { return {
checkScore: function () { return 80;
}
}
})
//推断式依赖注入
/*app.controller('myCtrl', function ($scope, $student) {
$scope.handleClick = function () {
$student.checkScore();
}
});*/
//行内式依赖注入
app.controller('myCtrl',
["$scope", "$student", function ($scope, $student) {
$scope.handleClick = function () {
console.log($student.checkScore());
}
}]);以上就是angularjs依赖注入 的详细内容,更多请关注Gxl网其它相关文章!