简体   繁体   English

Material Design Lite 和 ng-include

[英]Material Design Lite and ng-include

I am starting an app and I am adding some navigation provided from getmdl website (header and drawer) it works fine if it is in the index.html file but when I try to ng-include, when testing the hamburger is not showing hence the drawer and when I resize the screen it vanishes totally.我正在启动一个应用程序,我正在添加一些从 getmdl 网站(标题和抽屉)提供的导航,如果它在 index.html 文件中,它就可以正常工作,但是当我尝试 ng-include 时,测试汉堡包时没有显示,因此抽屉,当我调整屏幕大小时,它完全消失了。

For what I think is that some of the mdl classes are not working when used tru ng include, but why?我认为某些 mdl 类在使用 tru ng include 时不起作用,但为什么呢?

<div ng-include="'tmpl/navigation.html'"></div>

<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
  <!-- Title -->
  <span class="mdl-layout-title">Title</span>
  <!-- Add spacer, to align navigation to the right -->
  <div class="mdl-layout-spacer"></div>
  <!-- Navigation. We hide it in small screens. -->
  <nav class="mdl-navigation mdl-layout--large-screen-only">
    <a class="mdl-navigation__link" href="">Link</a>
    <a class="mdl-navigation__link" href="">Link</a>
    <a class="mdl-navigation__link" href="">Link</a>
    <a class="mdl-navigation__link" href="">Link</a>
  </nav>
</div>
</header>
<div class="mdl-layout__drawer">
 <span class="mdl-layout-title">Title</span>
<nav class="mdl-navigation">
  <a class="mdl-navigation__link" href="">Link</a>
  <a class="mdl-navigation__link" href="">Link</a>
  <a class="mdl-navigation__link" href="">Link</a>
  <a class="mdl-navigation__link" href="">Link</a>
</nav>
</div>
</div>

If the problem is the ng-include, you can use the includeReplace directive, that swap the div with ng-include with the html in the file.如果问题是 ng-include,您可以使用 includeReplace 指令,将带有 ng-include 的 div 与文件中的 html 交换。

  .directive('includeReplace', function () {
         return {
            require: 'ngInclude',
            restrict: 'A',
            /* optional */
            link: function (scope, el, attrs) {
               el.replaceWith(el.children());
            }
         };
      })

And you use it like this:你像这样使用它:

<div include-replace ng-include="'tmpl/navigation.html'"></div>

I just run into the same problem.我只是遇到了同样的问题。 I tried a lot of different combinations of <div ng-include> , <ng-include> , <span ng-include> ... with no success.我尝试了许多不同的<div ng-include><ng-include><span ng-include> ……但都没有成功。 At last, I found this workaround that is working: just code the "outer" div in the main html-file and then only include the content of the drawer in the externen html file.最后,我发现这个解决方法有效:只需在主 html 文件中编写“外部”div,然后只在外部 html 文件中包含抽屉的内容。

So the html would look like所以html看起来像

<div class="mdl-layout__drawer">
   <ng-include src="'./../templates/mdl_drawer.html'"></ng-include>
</div> 

I hope, this will work for you.我希望,这对你有用。

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

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