AngularJS中ng-include随屏幕宽度改变实例
2014-08-13 00:31
555 查看
用到了matchmedia-ng这个插件(https://github.com/AnalogJ/matchmedia-ng),参考了http://analogj.github.io/matchmedia-ng/的源代码。
html文件:
controller中:
定义$scope.location = {} 是参考了这个http://stackoverflow.com/questions/19045125/angularjs-nginclude-dynamically-changing-its-location
上面那个地址里提供了解释为什么要这么做,大意就是没有点,就是纯复制变量,后续的变化不会反映在拷贝上;有了点,就是引用object,就可以反映后续变化。
I think this needs a short
explanation. This has actually to do with how JavaScript will copy things. Without the dot, we are referencing a scalar variable. If JavaScript makes a copy of that, it is just that, a copy. Any changes made to the copy will not reflect on the original. On
the other hand: If there is a dot, then the "copy" is not of a scalar variable but an object (tpl in the answer). And a object is "copied" by reference, thus the copied tpl will still point to the original object, thus tpl.whatever will change tpl.whatever
on the "original" as well.
html文件:
<div> <div id="locationdiv" ng-include="location.url"> </div> </div>
controller中:
$scope.location = {} matchmedia.onLandscape(function(mediaQueryList){ if(mediaQueryList.matches){ $scope.location.url = "templates/WidePriview.html"; } }); matchmedia.onPortrait(function(mediaQueryList){ if(mediaQueryList.matches){ $scope.location.url = "templates/NarrowPriview.html"; } });
定义$scope.location = {} 是参考了这个http://stackoverflow.com/questions/19045125/angularjs-nginclude-dynamically-changing-its-location
上面那个地址里提供了解释为什么要这么做,大意就是没有点,就是纯复制变量,后续的变化不会反映在拷贝上;有了点,就是引用object,就可以反映后续变化。
I think this needs a short
explanation. This has actually to do with how JavaScript will copy things. Without the dot, we are referencing a scalar variable. If JavaScript makes a copy of that, it is just that, a copy. Any changes made to the copy will not reflect on the original. On
the other hand: If there is a dot, then the "copy" is not of a scalar variable but an object (tpl in the answer). And a object is "copied" by reference, thus the copied tpl will still point to the original object, thus tpl.whatever will change tpl.whatever
on the "original" as well.
相关文章推荐
- angularjs中使用ng-bind-html和ng-include的实例
- angularjs使用ng-messages-include实例
- AngularJs通过ng-class动态改变样式类实例操作
- angularjs中ng-include使用被注释或者报错解决方法
- angularjs,ng-include引入html代码片段
- AngularJS基础 ng-copy 指令实例代码
- 根据屏幕转向方向和屏幕宽度变化改变UITableView显示效果 屏幕旋转
- angularjs位于ng-switch中的ng-option 当select option改变了在IE上不会重新渲染 issue解决方案
- angularjs中ng-repeat-start与ng-repeat-end用法实例
- [Angularjs]ng-include 包含
- AngularJS进阶(三十九)基于项目实例解析ng启动加载过程
- Android界面控件遍历代码 改变宽度 高度 字体大小适应屏幕
- js小实例(改变宽度)
- 利用AngularJS中ng-include实现静态HTML头文件和尾文件导入
- angularjs使用ng-messages的注册表单实例
- AngularJS基础 ng-include 指令简单示例
- Jquery 使div永久居中_屏幕改变大小仍然居中实例
- 屏幕方向改变实例
- angularJs利用ng-include搭建最基本的一个包含过滤器、控制器的页面
- angularJS中include的页面的ng-model不能实时存取