我目前正在開發一個使用平均堆棧的web應用程序,並且使用ng-bootstrap的模態特性遇到了一些麻煩。我想要的是當用戶點擊導航欄的註冊選項時顯示註冊模式。我有一個導航欄成分並且還寄存器部件,這是我迄今爲止Ng-bootstrap模態與其他組件的內容
register.component.ts
import { Component, OnInit } from '@angular/core';
...
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
...
constructor(
...,
public registerModal: NgbActiveModal
) { }
navbar.component.ts
import { Component, OnInit } from '@angular/core';
...
import {NgbCollapseModule} from '@ng-bootstrap/ng-bootstrap';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {RegisterComponent} from '../register/register.component';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
public navCollapsed = true;
constructor(
...
private regCom: RegisterComponent
private ngbModal: NgbModal
) { }
ngOnInit() {
}
collapseOption(){
this.navCollapsed = !this.navCollapsed;
return true;
}
openRegister(){
const modalReg = this.ngbModal.open(this.regComp);
}
}
代碼
我試圖導入導航欄組件中的註冊組件,但我引發了一堆我不明白的錯誤,因爲我是在使用MEAN堆棧進行編程時的noob,所以如果你能幫助我解決這個問題,我會很感激。
出現的錯誤是這樣的:
EXCEPTION: Error in ./AppComponent class AppComponent - inline template:0:0 caused by: No provider for RegisterComponent!
預先感謝您的幫助!
平均堆棧是不是真的相關,技術上角2沒有資格作爲它的一部分。無可否認,這隻與客戶端編程有關。 –
您是否在app.module中導入了這些組件?您使用的組件應該在app.module或羽毛模塊中導入。 – ZouAlan
是的,它們全都是在app.module中導入的 –