如何从儿童组件打开MdSidenav?

时间:2017-01-05 14:42:17

标签: angular typescript angular-material2

我正在使用 angular-material2 库中的 MdSidenav 组件,我想从另一个组件中打开 MdSidenav 。所以我想使用来自另一个组件(即子组件)的局部变量 #sidenav (在父组件中)的函数。

父组件: 的 的src /应用程序/ app.component.html

<md-sidenav-container>
 <md-sidenav #sidenav>
  <h1>Hello</h1>
 </md-sidenav>

 <div class="my-content">
  <router-outlet></router-outlet>
 </div>
</md-sidenav-container>

子组件: src / app / menu / menu.component.html

<div class="menu">
 <button (click)="sidenav.open()"></button>
</div>

1 个答案:

答案 0 :(得分:-2)

我有类似的情况。你可以这样做:

String pattern = "(?m)^\\s*\\r?\\n|\\r?\\n\\s*(?!.*\\r?\\n)";
String replacement = "";
String inputString =
        "\n" +
        "Line  2 - above line is empty without spaces\n" +
        "Line  3 - next is empty without whitespaces\n" +
        "\n" +
        "Line  5 - next line is with whitespaces\n" +
        "        \n" +
        "Line  7 - next 2 lines are \"empty\". First one with whitespaces.\n" +
        "        \r\n" +
        "\n" +
        "Line 10 - 3 empty lines follow. The 2nd one with whitespaces in it. One whitespace at the end of this line " +
        "\n" +
        "          \n" +
        "\n";

String ajdustedString = inputString.replaceAll(pattern, replacement);
System.out.println("inputString:");
System.out.println("+----");
System.out.println(inputString);
System.out.println("----+");
System.out.println("ajdustedString:");
System.out.println("+----");
System.out.print(ajdustedString); //MIND the "print" instead of "println"
System.out.println("|EOS"); //String to clearly mark the _E_nd _O_f the adjusted_S_tring
System.out.println("----+");

然后在菜单组件中:

string homeFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", @"Data\DefaultContents\Home.html");