【问题标题】:Error encountered resolving symbol values statically. Calling function 'CreateCustomComponent', function calls are not supported静态解析符号值时遇到错误。调用函数“CreateCustomComponent”,不支持函数调用
【发布时间】:2017-07-06 11:54:27
【问题描述】:

创建自定义组件时出现以下错误。

静态解析符号值时遇到错误。调用函数“CreateCustomComponent”,不支持函数调用 d。考虑将函数或 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 { }

为什么m动态创建组件意味着我有一组jquery插件用于m动态创建组件并在jquery插件中使用这些组件输入和输出。

【问题讨论】:

    标签: angular angular2-aot angular2-custom-component


    【解决方案1】:

    升级我的 CLI 版本后,我也遇到了这个问题。它与 AOT 编译器有关。

    您可以通过将函数导出并包装到应用模块中的另一个函数(必须是应用模块)中来解决此问题,然后像这样使用导出的函数:

    export function doCreateCustomComponent(){
      return CreateCustomComponent(...);
    }
    
    @NgModule({ ... 
    declarations: [doCreateCustomComponent], 
    bootstrap: [doCreateCustomComponent]
    ... })
    export class AppModule { }
    

    (我稍微简化了你的代码)

    【讨论】:

    • 谢谢。这个解决方案可以帮助我解决我的问题
    猜你喜欢
    • 1970-01-01
    • 2017-06-07
    • 2017-07-28
    • 2018-03-04
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2018-01-03
    • 2017-09-06
    相关资源
    最近更新 更多