如何在$ rootscope中设置变量以显示浏览器是否在iPad上运行?(How can I set a variable in $rootscope to show if a browser is running on an iPad?)
我知道有一些库可以做到这一点,但我想做一些尽可能简单的事情,我没有看到任何针对AngularJS应用程序的示例。 问题是我不知道从哪里开始。
有人可以给我一些建议或指出我正确的方向。
I know there are some libraries that can do this but I would like to do something as simple as possible and I didn't see any examples that were for an AngularJS app. The problem is I do not know where to start.
Can someone give me some advice or point me in the right direction.
最满意答案
angular .module('test', []) .run(function($rootScope) { $rootScope.isIpad = /ipad/i.test(navigator.userAgent); }) ;<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <section ng-app="test"> <h1>is iPad? <span ng-bind="isIpad | json"></span></h1> </section>
如果您想拥有更强大的解决方案,请查看此处使用jQuery检测iPad用户?
angular .module('test', []) .run(function($rootScope) { $rootScope.isIpad = /ipad/i.test(navigator.userAgent); }) ;<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <section ng-app="test"> <h1>is iPad? <span ng-bind="isIpad | json"></span></h1> </section>
if you want to have a more robust solution, have a look here Detect iPad users using jQuery?
更多推荐
发布评论