当前位置:Gxlcms > JavaScript > AngularJS之对话框

AngularJS之对话框

时间:2021-07-01 10:21:17 帮助过:11人阅读

1、问题背景

AngularJS创建对话框,利用$window实现对话框


2、实现源码

<!DOCTYPE html>
<html ng-app="winApp">
	<head>
		<meta charset="UTF-8">
		<title>AngularJS之对话框</title>
		<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
		<script>
			var app = angular.module("winApp",[]);
			app.factory("$show",function($window){
				return{
					show:function(content){
						$window.alert(content);
					}
				};
			});
			
			var control = function($scope,$show){
				$scope.tanClick = function(message){
					$show.show(message);
				}
			}
			
			app.controller("winCon",control);
		</script>
	</head>
	<body>
		<p ng-controller="winCon">
			<button ng-click="tanClick('对话框!')">对话框</button>
		</p>
	</body>
</html>


3、实现结果

1172.png


以上就是AngularJS之对话框的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行