Home > Web Front-end > JS Tutorial > body text

AngularJS Dependency Injection (Example 1)

黄舟
Release: 2017-02-18 13:33:11
Original
995 people have browsed it

1. Problem background

A dependency injection unique to AngularJS. When an object is created, it needs to depend on another object.


2. Implementation source code

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>AngularJS之依赖注入(实例一)</title>
		<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
		<style>
			body,html{
				font-family: "微软雅黑";
				font-size: 12px;
				font-feature-settings: on;
			}
			.showContent{
				width: 200px;
				padding: 10px;
				margin: 10px;
				border: 1px dashed #2AABD2;
			}
		</style>
		<script>
			var app = angular.module("reApp",[]);
			app.config(function($controllerProvider){
				$controllerProvider.register("reCon",["$scope",function($scope){
					$scope.content = "";
					$scope.clickShow = function(){
						$scope.content = "showContent";
						$scope.showContent = "依赖注入";
					};
				}]);
			});
		</script>
	</head>
	<body ng-app="reApp">
		<p ng-controller="reCon">
			<button type="button" ng-click="clickShow();">依赖注入</button><br><br>
			<label class="{{content}}">{{showContent}}</label>
		</p>
	</body>
</html>
Copy after login


3. Implementation results

(1) Initialization

AngularJS Dependency Injection (Example 1)

(2) When the button is clicked

AngularJS Dependency Injection (Example 1)

## The above is the dependency injection of AngularJS (example 1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!




##

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!