AngularJS中的API(接口)简单实现
AngularJSAPI
API意为ApplicationProgrammingInterface(应用程序编程接口)。
AngularJS全局API
AngularJS全局API用于执行常见任务的JavaScript函数集合,如:
比较对象
迭代对象
转换对象
全局API函数使用angular对象进行访问。
以下列出了一些通用的API函数:
angular.lowercase()
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <divng-app="myApp"ng-controller="myCtrl"> <p>{{x1}}</p> <p>{{x2}}</p> </div> <script> varapp=angular.module('myApp',[]); app.controller('myCtrl',function($scope){ $scope.x1="JOHN"; $scope.x2=angular.lowercase($scope.x1); }); </script> </body> </html>
运行结果:
JOHN
john
angular.uppercase()
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <divng-app="myApp"ng-controller="myCtrl"> <p>{{x1}}</p> <p>{{x2}}</p> </div> <script> varapp=angular.module('myApp',[]); app.controller('myCtrl',function($scope){ $scope.x1="JOHN"; $scope.x2=angular.isString($scope.x1); }); </script> </body> </html>
运行结果:
JOHN
true
angular.isString()
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <divng-app="myApp"ng-controller="myCtrl"> <p>{{x1}}</p> <p>{{x2}}</p> </div> <script> varapp=angular.module('myApp',[]); app.controller('myCtrl',function($scope){ $scope.x1="JOHN"; $scope.x2=angular.isString($scope.x1); }); </script> </body> </html>
运行结果:
JOHN
true
angular.isNumber()
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <divng-app="myApp"ng-controller="myCtrl"> <p>{{x1}}</p> <p>{{x2}}</p> </div> <script> varapp=angular.module('myApp',[]); app.controller('myCtrl',function($scope){ $scope.x1="JOHN"; $scope.x2=angular.isNumber($scope.x1); }); </script> </body> </html>
运行结果:
JOHN
false
以上就是对AngularJSAPI(接口)资料的整理,后续继续补充,希望能帮助编程的同学。