AngularJS API实例

作者 : 慕源网 本文共2018个字,预计阅读时间需要6分钟 发布时间: 2022-05-1 共143人阅读

AngularJS API实例,AngularJS API用于比较、迭代和转换对象。基本AngularJS API包括

  • angular.isString()
  • angular.lowercase()
  • angular.uppercase()
  • angular.isNumber()

1. angular.isString()

用于检查对象是否为字符串,如果对象为字符串则返回true,否则返回false。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body>

	<div ng-app="gfg" ng-controller="gfgCntrl">
	<p>{{ object }}</p>
	<p>{{ apiRes }}</p>
	</div>

	<script>
	var app = angular.module('gfg', []);
	app.controller('gfgCntrl', function($scope) {
		$scope.object = "GeeksForGeeks";
		$scope.apiRes = angular.isString($scope.object);
	});
	</script>

</body>
</html>

输出:

AngularJS API实例

2. angular.lowercase()

用于将字符串转小写

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body>

	<div ng-app="gfg" ng-controller="gfgCntrl">
	<p>{{ object }}</p>
	<p>{{ apiRes }}</p>
	</div>

	<script>
	var app = angular.module('gfg', []);
	app.controller('gfgCntrl', function($scope) {
		$scope.object = "GeeksForGeeks";
		$scope.apiRes = angular.lowercase($scope.object);
	});
	</script>

</body>
</html>

输出:

AngularJS API实例

3. angular.uppercase()

用于将字符串转大写。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body>

	<div ng-app="gfg" ng-controller="gfgCntrl">
	<p>{{ object }}</p>
	<p>{{ apiRes }}</p>
	</div>

	<script>
	var app = angular.module('gfg', []);
	app.controller('gfgCntrl', function($scope) {
		$scope.object = "GeeksForGeeks";
		$scope.apiRes = angular.uppercase($scope.object);
	});
	</script>

</body>
</html>

输出:

AngularJS API实例

4. angular.isNumber()

用于检查对象是否为数字。如果 object 是数字,则返回 true,否则返回 false。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body>

	<div ng-app="gfg" ng-controller="gfgCntrl">
	<p>{{ object }}</p>
	<p>{{ apiRes }}</p>
	</div>

	<script>
	var app = angular.module('gfg', []);
	app.controller('gfgCntrl', function($scope) {
		$scope.object = "GeeksForGeeks";
		$scope.apiRes = angular.isNumber($scope.object);
	});
	</script>

</body>
</html>

输出:

AngularJS API实例


慕源网 » AngularJS API实例

常见问题FAQ

程序仅供学习研究,请勿用于非法用途,不得违反国家法律,否则后果自负,一切法律责任与本站无关。
请仔细阅读以上条款再购买,拍下即代表同意条款并遵守约定,谢谢大家支持理解!

发表评论

开通VIP 享更多特权,建议使用QQ登录