使用Zurb Foundation Interchange和AngularJS

前端之家收集整理的这篇文章主要介绍了使用Zurb Foundation Interchange和AngularJS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个使用Zurb Foundation作为其CSS框架的AngularJS项目.我试图找出如何在AngularJS视图的上下文中使用Foundation的 data interchange.这甚至可能,我似乎无法让它工作.这就是我目前拥有的:

的index.html

  1. <!DOCTYPE html>
  2. <html ng-app='app' xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Test</title>
  5. <Meta charset="utf-8">
  6. <Meta name="viewport" content="width=device-width,initial-scale=1.0">
  7.  
  8. <link rel="stylesheet" href="foundation/normalize.css" />
  9. <link rel="stylesheet" href="foundation/foundation.min.css" />
  10. <link rel="stylesheet" href="app.css" />
  11. </head>
  12. <body>
  13. <div id="view" ng-view></div>
  14.  
  15. <script type="text/javascript" src="jquery/2.0.3/jquery.min.js"></script>
  16. <script type="text/javascript" src="foundation/foundation.min.js"></script>
  17.  
  18. <script type="text/javascript" src="angularjs/1.2.7/angular.min.js"></script>
  19. <script type="text/javascript" src="angularjs/1.2.7/angular-route.min.js"></script>
  20.  
  21. <script type="text/javascript" src="app.js"></script>
  22. </body>
  23. </html>

app.js

  1. angular.module('app',['ngRoute'])
  2. .config(function ($routeProvider,$locationProvider) {
  3. $locationProvider.html5Mode(true);
  4.  
  5. $routeProvider
  6. .otherwise({ templateUrl: '/views/interchange.html',controller: myCtrl });
  7. })
  8. .run(function ($rootScope,$location) {
  9. $rootScope.$on('$viewContentLoaded',function () {
  10. $(document).foundation();
  11. });
  12. })
  13. ;
  14.  
  15. function myCtrl() {
  16. console.log('loading controller');
  17. }

interchange.html

  1. <article>
  2. testing interchange
  3. <div data-interchange="[phone.html,(small)],[portrait.html,(medium)],[landscape.html,(large)]"></div>
  4. </article>

当我加载我的应用程序时,我可以看到“测试交换”.但是,未显示基于屏幕大小的内容(phone.html,portrait.html,landscape.html). Phone.html,Portrait.html和landscape.html只在DIV元素中包含有效说明“手机”,“肖像”和“风景”的文字.

有没有办法在AngularJS ng-view中利用Foundation的数据交换内容?如果是这样,怎么样?谢谢

这里的要点是Zurb的数据交换功能在DOMContentLoad事件上运行,而AngularJS视图的加载是异步的.所以,事件已经发生了.

要克服这个问题,你需要使用$(document).foundation(‘interchange’,’reflow’)手动触发数据交换;或$(document).foundation(‘reflow’);回流所有组件.

要在正确的位置触发此操作,您需要在AngularJS路由系统上侦听名为$routeChangeSuccess的特殊事件.像这样的东西:

  1. module.run(function ($rootScope) {
  2. $rootScope.$on('$routeChangeSuccess',function () {
  3. $(document).foundation('reflow');
  4. });
  5. });

希望这对你有所帮助.

猜你在找的Angularjs相关文章