![](/img/trans.png)
[英]Angular2 - Error encountered resolving symbol values statically. Calling function 'InMemoryWebApiModule', function calls are not supported.
[英]Error encountered resolving symbol values statically. Calling function 'CreateCustomComponent', function calls are not supported
創建自定義組件時出現以下錯誤。
靜態解析符號值時遇到錯誤。 調用函數“ CreateCustomComponent”,不支持函數調用。 考慮使用對導出函數的引用替換函數或lambda,以解決符號cus_input
我的文件如下。 有人可以給我一個下面代碼的答案嗎?
export class MyComponent {
constructor() {
console.log("Component created");
}
}
export function CreateCustomComponent( componentArgs: {
selector: string,
inputs: Array<string>,
template: string
}): Type<any> {
let comp = Component(componentArgs);
return comp.Class({
extends: MyComponent,
constructor: []
});
}
export let cus_input :any = CreateCustomComponent({selector: 'cus-inp',inputs : ["myinput"],template : '<input [value]="myinput" />'})
export const MY_INP_Component: any = [cus_input];
如下所示在“ app.modeule.ts”中導入
import { MY_INP_Component} from './customcomponent/core';
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(rootRouterConfig, { useHash: true })],
declarations: [AppComponent,
MY_INP_Component
],
bootstrap: [AppComponent],
})
export class AppModule { }
在這里,為什么動態創建組件意味着我為動態創建組件並在jquery插件中使用這些組件輸入和輸出設置了jquery插件集。
升級CLI版本后,我也遇到了這個問題。 它與AOT編譯器有關。
您可以通過將函數導出並包裝到應用程序模塊中的另一個函數(必須是應用程序模塊)中,然后使用導出的函數來解決此問題,如下所示:
export function doCreateCustomComponent(){
return CreateCustomComponent(...);
}
@NgModule({ ...
declarations: [doCreateCustomComponent],
bootstrap: [doCreateCustomComponent]
... })
export class AppModule { }
(我已經稍微簡化了您的代碼)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.