ホームページ  >  記事  >  ウェブフロントエンド  >  AngularJS 依存関係の注入 (例 1)

AngularJS 依存関係の注入 (例 1)

黄舟
黄舟オリジナル
2017-02-18 13:33:11946ブラウズ

1. 問題の背景

AngularJS に特有の依存関係の注入 オブジェクトが作成されると、別のオブジェクトに依存する必要があります。


2. 実装ソースコード

<!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>


(1) 初期化

AngularJS 依存関係の注入 (例 1) (2) ボタンがクリックされました

AngularJS 依存関係の注入 (例 1)

上記は AngularJS の依存関係の挿入 (例 1) の内容です。さらに関連するコンテンツについては、PHP 中国語 Web サイト (www.php.cn) に注目してください。



声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。