<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ng-repeat</title>
<script src="jquery-1.11.1.js"></script>
<script src="angular-1.2.25.js"></script>
<script>
function wholeController($scope,$rootScope,$injector)
{
$scope.buttons = ["button1","button2","button3"];
$scope.btnFunc = function(value){
alert(value);
};
}
</script>
</head>
<body ng-app>
<div id="first" ng-controller="wholeController">
<div id="buttonDiv">
<input type="button" ng-repeat="button in buttons" id="btn{{$index}}" value="{{button}}" ng-click="btnFunc(button);"/>
</div>
<input type="button" value="test" ng-click="testFunc();">
</div>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ng-repeat</title>
<script src="jquery-1.11.1.js"></script>
<script src="angular-1.2.25.js"></script>
<script>
//$scope是ng-controller指令新建的作用域
function wholeController($scope,$rootScope,$injector)
{
alert($scope.$parent === $rootScope);//输出true
}
</script>
</head>
<body ng-app>
<div id="first" ng-controller="wholeController">
</div>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ng-repeat</title>
<script src="jquery-1.11.1.js"></script>
<script src="angular-1.2.25.js"></script>
<script>
function wholeController($scope,$rootScope,$injector)
{
$scope.buttons = ["button1","button2","button3"];
$scope.testFunc = function(){
//拿到dom元素上关联的作用域
var scope0 = angular.element($("#btn0")[0]).scope();
var scope1 = angular.element($("#btn1")[0]).scope();
alert(scope0 == scope1);//输出false
alert(scope0.$parent === $scope);//true
alert(scope1.$parent === $scope);//true
};
}
</script>
</head>
<body ng-app>
<div id="first" ng-controller="wholeController">
<div id="buttonDiv">
<input type="button" ng-repeat="button in buttons" id="btn{{$index}}" value="{{button}}" />
</div>
<input type="button" value="test" ng-click="testFunc();">
</div>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ng-repeat</title>
<script src="jquery-1.11.1.js"></script>
<script src="angular-1.2.25.js"></script>
<script>
function wholeController($scope,$rootScope,$injector)
{
$scope.buttons = ["button1","button2","button3"];
$scope.method1 = function(){
var scope0 = angular.element($("#btn0")[0]).scope();
scope0.buttons = ["a1","b1","c1"];
};
$scope.method2 = function(){
var scope0 = angular.element($("#btn0")[0]).scope();
scope0.$parent.buttons = ["a2","b2","c2"];
};
$scope.method3 = function(){
var scope0 = angular.element($("#btn0")[0]).scope();
scope0.buttons[0] = "a3";
scope0.buttons[1] = "b3";
scope0.buttons[2] = "c3";
};
}
</script>
</head>
<body ng-app>
<div id="first" ng-controller="wholeController">
<div id="buttonDiv">
<input type="button" ng-repeat="button in buttons" id="btn{{$index}}" value="{{button}}" />
</div>
<input type="button" value="method1" ng-click="method1();">
<input type="button" value="method2" ng-click="method2();">
<input type="button" value="method3" ng-click="method3();">
</div>
</body>
</html>
var obj = {"name":"aty"};
wrongChangeName(obj);
alert(obj.name);//仍然是aty
rightChangeName(obj);
alert(obj.name);//hehe
function rightChangeName(obj)
{
obj.name="hehe";
}
function wrongChangeName(obj)
{
obj = {"name":"hehe"};
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有