Angular引导作用域改变屏幕大小
Angular bootstrap scope on screen size change
不同屏幕尺寸的角元素共享同一个控制器。为什么当我在小屏幕尺寸(SM
)上修改我的select
options
时,当收缩屏幕到特别小(XS
)时,所有更改都丢失了?
我有两个单独的HTML
文件,以保持每个文件更小,更结构化。因为我对平板电脑和手机的设计可能会非常不同。
在不同的屏幕尺寸之间切换时,我应该做些什么来保持我的更改?
谢谢你的帮助!
index . html
SM.html
<div ng-controller="PassengerController as pd">
<div class="col-sm-2">
<div class="form-group">
<label class="control-label" for="selectSMFrom12">12+ years</label>
<select ng-init="adults" ng-model="adults" ng-options="value as value for value in adultValues" class="form-control" id="selectSMFrom12"></select>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label class="control-label" for="selectSMUnder12">12+ years</label>
<select ng-init="childrenUnder12" ng-model="childrenUnder12" ng-options="value as value for value in childrenUnder12Values" class="form-control" id="selectSMUnder12"></select>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<label class="control-label" for="selectSMInfants">12+ years</label>
<select ng-init="infantsUnder2" ng-model="infantsUnder2" ng-options="value as value for value in infantsUnder2Values" class="form-control" id="selectSMInfants"></select>
</div>
</div>
</div>
XS.html
<div ng-controller="PassengerController as pd">
<div class="col-xs-4">
<div class="form-group">
<label class="control-label" for="selectXSFrom12">12+ years</label>
<select ng-init="adults" ng-model="adults" ng-options="value as value for value in adultValues" class="form-control" id="selectXSFrom12"></select>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<label class="control-label" for="selectXSUnder12">12+ years</label>
<select ng-init="childrenUnder12" ng-model="childrenUnder12" ng-options="value as value for value in childrenUnder12Values" class="form-control" id="selectXSUnder12"></select>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<label class="control-label" for="selectXSInfants">12+ years</label>
<select ng-init="infantsUnder2" ng-model="infantsUnder2" ng-options="value as value for value in infantsUnder2Values" class="form-control" id="selectXSInfants"></select>
</div>
</div>
</div>
app.js
var app = angular.module("myModule");
app.controller('PassengerController', ['$scope', function($scope) {
$scope.adults = 1;
$scope.childrenUnder12 = 0;
$scope.infantsUnder2 = 0;
$scope.adultValues = [1,2,3,4,5,6,7,8,9,10];
$scope.childrenUnder12Values = [0, 1,2,3,4,5,6,7,8,9,10];
$scope.infantsUnder2Values = [0, 1,2,3,4,5,6,7,8,9,10];
}]);
var app = angular.module("fridayFly", ['ui.bootstrap']);
app.directive('searchBarSm', function() {
return {
restrict: 'E',
templateUrl: 'templates/search-bar/SM.html'
};
});
app.directive('searchBarXs', function() {
return {
restrict: 'E',
templateUrl: 'templates/search-bar/XS.html'
};
});
你不应该在调整大小时改变视图,只是应用不同的类。您应该添加所需的类。你正在使用bootstrap,所以应该像这样:
<div class="col-sm-2 col-xs-4">
您只需要一个视图。现在,当你改变屏幕大小时,类&剩下的就交给样式表了。
所以在你的情况下,你只需要一个:
<div ng-controller="PassengerController as pd">
<div class="col-sm-2 col-xs-4">
<div class="form-group">
<label class="control-label" for="selectSMFrom12">12+ years</label>
<select ng-init="adults" ng-model="adults" ng-options="value as value for value in adultValues" class="form-control" id="selectSMFrom12"></select>
</div>
</div>
<div class="col-sm-2 col-xs-4">
<div class="form-group">
<label class="control-label" for="selectSMUnder12">12+ years</label>
<select ng-init="childrenUnder12" ng-model="childrenUnder12" ng-options="value as value for value in childrenUnder12Values" class="form-control" id="selectSMUnder12"></select>
</div>
</div>
<div class="col-sm-2 col-xs-4">
<div class="form-group">
<label class="control-label" for="selectSMInfants">12+ years</label>
<select ng-init="infantsUnder2" ng-model="infantsUnder2" ng-options="value as value for value in infantsUnder2Values" class="form-control" id="selectSMInfants"></select>
</div>
</div>
</div>
相关文章:
- jQuery:当屏幕大小改变时,如何更改默认图像和悬停图像
- 当屏幕方向改变时,重新运行javascript函数
- CSS:根据屏幕宽度改变样式
- 通过改变屏幕分辨率来调整按钮大小
- 如何根据屏幕分辨率改变transform:translate css规则?
- 我如何使我的图像在页面上移动,即使当屏幕的分辨率改变
- JS根据屏幕大小改变链接
- Textarea字体大小不改变屏幕上的jquery调整大小
- 如何在angular js中根据屏幕大小改变弹出窗口的位置?
- 根据屏幕宽度改变类选择器的边距设置
- Magento CE:如何根据屏幕分辨率改变php文件内块的位置
- 操纵/改变窗口.屏幕属性值
- 在开始改变屏幕方向之前如何检测实际位置
- Angular引导作用域改变屏幕大小
- JQuery根据位置显示元素——如果父元素不在屏幕上,工具提示应该改变位置
- 当屏幕方向改变时,window.screen.width值在iPad浏览器中不改变
- 当屏幕大小改变时,调整固定对象的大小
- 如何改变iframe src与改变屏幕大小
- 根据屏幕大小改变元素的宽度
- CSS属性不'屏幕宽度改变时不适用.同时使用css和jQuery