angular.equals()

时间:2023-01-22 09:53:32
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>angular.equals</title>
</head> <body ng-app="equalsExample">
<h1>angular.equals</h1>
<p>
<span>描述:</span><br />
<span>比较两个值或者两个对象是不是相等。</span>
</p>
<p>
<span>使用方法:</span><br />
<span>angular.equals(o1, o2)</span>
</p>
<p>
<span>参数:</span><br />
<span>o1: 值或者对象</span><br />
<span>o2: 值或者对象</span><br />
</p>
<p>
<span>返回值:</span><br />
<span>布尔值, 如果相等则返回true</span>
</p>
<hr />
<div ng-controller="equalscon">
<div id="test"></div>
<div>
<span>{{but1}}</span>
<input type="button" ng-click="button1()" value="比较值" />
</div>
<div>
<span>{{but3}}</span>
<input type="button" ng-click="button3()" value="比较值" /><br />
<span>{{but4}}</span>
<input type="button" ng-click="button4()" value="比较值" />
<div>
<div>
<label>
var obj1 = {name:"tom", password:"123456"};<br />
var obj2 = {name:"tom", password:"123456"};
</label><br />
<span>{{but2}}</span>
<input type="button" ng-click="button2()" value="比较对象" />
</div>
</div>
</div>
</div>
</body>
<script src="../../js/angular.1.3.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var ang = angular.module('equalsExample', []).controller('equalscon', ['$scope', function($scope){
$scope.but1 = 'angular.equals("a", "a")';
$scope.but2 = 'angular.equals(obj1, obj2)';
$scope.but3 = '1 === true';
$scope.but4 = 'angular.equals(1, true)';
$scope.button1 = function(){
console.log(angular.equals("a", "a"));
}
var obj1 = {
name: '张三',
age: '123'
};
var obj2 = {
name: '张三',
age: "123"
};
$scope.button2 = function(){
console.log(angular.equals(obj1, obj2));
};
$scope.button3 = function(){
console.log(1 == true)
};
$scope.button4 = function(){
console.log(angular.equals(1, true))
};
}])
</script> </html>

相关文章