我想在valor-software
庫ng2-select
解決的問題後,安裝在我的node_modules(npm install --save ng2-select
),我想注入SelectComponent
如使用@ViewChild
孩子,但我總是得到不確定的。它看起來真的很微不足道,我已經看到了該項目的github中的評論,它似乎爲許多人工作。 我在angular/CLI project
如果我要添加更多的信息,請在評論中提及它。謝謝 。無法導入NG2選SelectComponent
node_modules
|
+ --ng2-select
|
+--ng2-select.d.ts
|
+--select/
|
+--select.d.ts
|
+-- ...
態氮,select.d.ts內容
export * from './select/common';
export * from './select/off-click';
export * from './select/select.module';
export * from './select/select';
export * from './select/select-interfaces';
export * from './select/select-item';
export * from './select/select-pipes';
選擇/ select.d.ts
的內容export declare class SelectComponent implements OnInit, ControlValueAccessor {
private sanitizer;
.....
}
myComponent的:
import { Component, OnInit, ViewChild } from '@angular/core';
import { SelectComponent } from 'ng2-select';
export class SubSystemComponent implements OnInit {
@ViewChild('SelectComponent')
private sysSearchInput: SelectComponent;
constructor(private sysService : SubSysService) { }
ngOnInit() {
console.log(this.sysSearchInput);
}
你應該實現'AfterViewInit'而不是'OnInit'。 (或兩者都有,但直到AfterViewInit後才能訪問它)。 [doc非常清楚](https://angular.io/docs/ts/latest/api/core/index/ViewChild-decorator.html)。 – n00dl3
我應該在'AfterViewInit'方法中檢查'this.sysSearchInput'的值嗎? – mustafa918
肯定,是的。 – n00dl3