我一直在尋找一段時間,在谷歌,stackoverflow,但沒有,Angular2似乎是DIY,沒有完成..所以我有login.component.ts,包含物化模式的模板:Angular2從另一個組件調用一個功能組件
import { Directive, Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core';
import { MaterializeModule,MaterializeAction } from 'angular2-materialize';
declare var $: any
@Component({
selector: "dialogs",
template: '
<!-- Modal Structure -->
<div id="modal1" class="modal bottom-sheet" materialize="modal" [materializeParams]="[{dismissible: false}]" [materializeActions]="modalActions">
<div class="modal-content">Modal Content</div>
<div class="modal-footer">
<a class="waves-effect waves-green btn-flat" (click)="closeModal()">Close</a>
</div>
</div>
'
})
export class Dialogs implements OnInit {
@Output() modalActions = new EventEmitter<string|MaterializeAction>();
constructor() {
}
ngOnInit() {
}
openModal() {
this.modalActions.emit({action:"modal",params:['open']});
}
closeModal() {
this.modalActions.emit({action:"modal",params:['close']});
}
}
而且我header.component.ts
import {Component, OnInit, OnDestroy} from "@angular/core"
import { LoginComponent } from '../login/login.component';
import { Dialogs } from '../login/login.component';
@Component({
selector: 'headerCustom',
styleUrls: ['./header.component.css'],
template:
`
<nav class="navbar-material light-blue lighten-1" role="navigation">
<div class="nav-wrapper">
<a href="#!" class="brand-logo">
<img src="./images/logo.png" />
</a>
<a materialize="sideNav" href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
<li><a href="#">Subscribe</a></li>
<li>
<a class="waves-effect waves-light btn modal-trigger" (modalActions)="openModal()">Open Modal Login</a>
</li>
</ul>
<ul class="side-nav" id="mobile-demo">
<li><a href="#">Subscribe</a></li>
<li>
<a class="waves-effect waves-light btn modal-trigger" (modalActions)="openModal()">Open Modal Login</a>
</li>
</ul>
</div>
</nav>`
})
export class HeaderComponent implements OnInit, OnDestroy {
}
我只想簡單的動作,當我點擊上面的按鈕頭,那將打開模式?爲什麼我不能調用登錄組件的功能?
我試着像很多代碼:
<a class="waves-effect waves-light btn modal-trigger" (click)="modalActions.openModal()">Open Modal Login</a>
但一無所獲。
感謝您的幫助
Your'r GREAT :),這其實很簡單,那就是做工精良!!!!非常感謝你 !! – kaneda