简体   繁体   English

Angular控制器/服务中的引导程序大小变量?

[英]Bootstrap size variable in Angular controllers/services?

I'd like to use a variable which stores what Bootstrap3 breakpoint(xs,sm,md,lg) the webpage currently is at to do things in Angular services/controllers (like on desktop I'd open a Kendo-UI window but on mobile I'd use a simple 100% width window). 我想使用一个变量来存储当前页面的Bootstrap3断点(xs,sm,md,lg),以便在Angular服务/控制器中执行操作(例如在台式机上,我会打开Kendo-UI窗口,但在移动设备,我将使用一个简单的100%宽度的窗口)。

Is there a way to set something like this up? 有没有办法设置像这样的东西?

I just set a variable to bootstraps specific breakpoints and change the value of that variable to 'xs', 'sm', 'md', 'lg' with a 'watch' on the window resize. 我只是设置了一个变量以引导特定的断点,并在窗口调整大小时将该变量的值更改为“ xs”,“ sm”,“ md”,“ lg”,并且带有“监视”功能。

angular.element($window).on('resize', function () {
  //set a $scope variable or a service variable that reused
  $scope.bootstrap_size = 'xs';
  $scope.is_mobile = true;
  if($window.innerWidth >=1200) {    
    $scope.bootstrap_size = 'lg';
    $scope.is_mobile = false;  
  } else if($window.innerWidth >= 992) {
    $scope.bootstrap_size = 'md';
    $scope.is_mobile = false;  
  } else if($window.innerWidth >= 768) {
    $scope.bootstrap_size = 'sm';
    $scope.is_mobile = false;  
  }
});

If dont need to have those values in angular, and if just need to see the breakpoint values in a debug toolbar can also just use default bootstrap classes to achieve this: 如果不需要这些值成角度,并且只需要在调试工具栏中查看断点值,也可以使用默认的引导程序类来实现:

<div class="visible-xs"><strong>sz:</strong>xs</div>
<div class="visible-sm"><strong>sz:</strong>sm</div>
<div class="visible-md"><strong>sz:</strong>md</div>
<div class="visible-lg"><strong>sz:</strong>lg</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM