继承组件时未定义ViewChild

时间:2018-08-15 09:04:10

标签: angular

我想基于ngx-bootstrap模态组件创建基本模态组件。 我有22:40:06 DEBUG irc.client FROM SERVER: :NickServ!NickServ@services. NOTICE botka :This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <passw ord>. 22:40:06 DEBUG irc.client _dispatcher: all_raw_messages 22:40:06 DEBUG irc.client command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['This nickname is registered. Please choose a different nickname, or identify via \x02/msg NickServ identify <password>\x02.'], tags: None 22:40:06 DEBUG irc.client _dispatcher: privnotice 22:40:06 DEBUG errbot.core *** frm = NickServ!NickServ@services. 22:40:06 DEBUG errbot.core *** username = NickServ 22:40:06 DEBUG errbot.core *** text = This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>. 22:40:06 DEBUG errbot.core Assuming 'This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>.' to be a command because BOT_PREFIX_OPTIO NAL_ON_CHAT is True 22:40:06 DEBUG errbot.core Command not found 22:40:06 DEBUG errbot.utils Elapsed 0.005545 since last call 22:40:06 DEBUG errbot.utils Wait 0.994455 due to rate limiting... 22:40:07 DEBUG irc.client TO SERVER: PRIVMSG NickServ :Command "This" / "This nickname" not found. 22:40:07 DEBUG errbot.core Triggering callback_message on Flows ............................skipped 22:40:07 DEBUG irc.client FROM SERVER: :NickServ!NickServ@services. NOTICE botka :You are now identified for botka. 22:40:07 DEBUG irc.client _dispatcher: all_raw_messages 22:40:07 DEBUG irc.client command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['You are now identified for \x02botka\x02.'], tags: None 22:40:07 DEBUG irc.client _dispatcher: privnotice 22:40:07 DEBUG errbot.core *** frm = NickServ!NickServ@services. 22:40:07 DEBUG errbot.core *** username = NickServ 22:40:07 DEBUG errbot.core *** text = You are now identified for botka. 22:40:07 DEBUG errbot.core Assuming 'You are now identified for botka.' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True 22:40:07 DEBUG errbot.core Command not found 22:40:07 DEBUG errbot.utils Elapsed 0.014732 since last call 22:40:07 DEBUG errbot.utils Wait 0.985268 due to rate limiting... 22:40:08 DEBUG irc.client TO SERVER: PRIVMSG NickServ :Command "You" / "You are" not found. ............afterwards 22:40:20 DEBUG irc.client FROM SERVER: :NickServ!NickServ@services. NOTICE botka :Invalid command. Use /msg NickServ help for a command listing. 22:40:20 DEBUG irc.client _dispatcher: all_raw_messages 22:40:20 DEBUG irc.client command: privnotice, source: NickServ!NickServ@services., target: botka, arguments: ['Invalid command. Use \x02/msg NickServ help\x02 for a command listing.'], tags: None 22:40:20 DEBUG irc.client _dispatcher: privnotice 22:40:20 DEBUG errbot.core *** frm = NickServ!NickServ@services. 22:40:20 DEBUG errbot.core *** username = NickServ 22:40:20 DEBUG errbot.core *** text = Invalid command. Use /msg NickServ help for a command listing. 22:40:20 DEBUG errbot.core Assuming 'Invalid command. Use /msg NickServ help for a command listing.' to be a command because BOT_PREFIX_OPTIONAL_ON_CHAT is True 22:40:20 DEBUG errbot.core Command not found 22:40:20 DEBUG errbot.utils Elapsed 0.015257 since last call 22:40:20 DEBUG errbot.utils Wait 0.984743 due to rate limiting... 22:40:21 DEBUG irc.client TO SERVER: PRIVMSG NickServ :Command "Invalid" / "Invalid command." not found. 22:40:21 DEBUG errbot.core Triggering callback_message on Flows .............skpped 22:40:21 DEBUG irc.client FROM SERVER: :NickServ!NickServ@services. NOTICE botka :Invalid command. Use /msg NickServ help for a command listing.

ModalComponent

然后,我不想具有特定的模态,但是使用诸如<div bsModal #baseModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title pull-left">Title</h4> <button type="button" class="close pull-right" (click)="hide()" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <ng-content></ng-content> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" (click)="hide()"> Cancel </button> <button type="button" class="btn btn-primary" Ok </button> </div> </div> </div> </div> @Component({ selector: 'app-modal', templateUrl: './modal.component.html', styleUrls: ['./modal.component.css'] }) export class ModalComponent implements OnInit { @ViewChild('baseModal') public modalDirective: ModalDirective; constructor() { } ngOnInit() { } public show(): void { this.modalDirective.show(); } public hide(): void { this.modalDirective.hide(); } } hide之类的基本函数:

show

然后,我使用我的特定模式:

<app-modal #modal>
   <p>Modal content</p> 
</app-modal>

@Component({
   selector: 'app-specific-modal',
   templateUrl: './specific-modal.component.html',
   styleUrls: ['./specific-modal.component.css']
})
export class SpecificModalComponent extends ModalComponent implements OnInit {

 constructor() { 
    super();
 }

  ngOnInit() {

  }

}

但是,我收到一个错误,提示<app-specific-modal #spm></app-specific-modal> <button (click)="showSpecificModal()">Show</button> @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { @ViewChild('spm') spModal:SpecificModalComponent; public showSpecificModal() { this.spModal.show(); } } 未定义。我在调试器中看到show是未定义的。如何正确实施?

DEMO

0 个答案:

没有答案