Error encountered resolving symbol values statically. Calling function 'CreateCustomComponent', function calls are not supported

和自甴很熟 提交于 2019-12-08 02:01:53

问题


I am getting below error when creating my custom component.

Error encountered resolving symbol values statically. Calling function 'CreateCustomComponent', function calls are not supporte d. Consider replacing the function or lambda with a reference to an exported function, resolving symbol cus_input

my file like as below. Any one please give me a answer for below my code ?

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];

Importing like as below in "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 { }

Here why m creating component dynamically means i have set of jquery plugins for that m creating component dynamically and using these component inputs and outputs in jquery plugin.


回答1:


I had this problem too after upgrading my CLI version. It has something to do with the AOT compiler.

You can fix this by exporting and wrapping your function in another function in your app module (must be app module), and then using the exported function like so:

export function doCreateCustomComponent(){
  return CreateCustomComponent(...);
}

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

(I've simplified your code slightly)



来源:https://stackoverflow.com/questions/42289737/error-encountered-resolving-symbol-values-statically-calling-function-createcu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!