I'm trying to change the standard constructor to add myConstructor.
Based on the code here I coded the following statements:
@CustomTag('main-app')
class MainApp extends PolymerElement {
factory MainApp.custom() {
MainApp = new Element.tag('main-app');
myConstructor();
}
MainApp.created() : super.created();
void myConstructor() {
print("myConstructor Started");
}
Unfortunately the Editor shows some problems:
The Statement MainApp = new Element.tag('main-app')
shows the error:
A Value of Type 'Element' cannot be assigned to a variable of type 'Type'.
The Statement myConstructor() shows the Error:
"Instance members cannot be accessed from a factory constructor"
anyone has a suggestion how I can solve the errors?
EDIT: The current code is looking like following:
@CustomTag('main-app')
class MainApp extends PolymerElement {
@observable int counter = 0;
factory MainApp.custom() {
MainApp mainApp = new Element.tag('main-app');
mainApp.myConstructor();
return mainApp;
}
/// Constructor used to create instance of MainApp.
MainApp.created() : super.created();
MainApp ma = new MainApp.custom();
void myConstructor() {
print("myConstructor Started");
counter = 1;
}
The following error is showing up:
Exception: type 'HtmlElement' is not a subtype of type 'MainApp' of 'mainApp'.
MainApp.MainApp.custom
MainApp.MainApp.created
EDIT Version 2:
@CustomTag('main-app')
class MainApp extends PolymerElement {
Controller controller = new Controller();
@observable int counter = myConstructor();
@observable int totalGlypto = 0;
/// Constructor used to create instance of MainApp.
MainApp.created() : super.created();
static int myConstructor() {
print("myConstructor Started");
return controller.getTotal();
}
void setupCheckIn(Event e, var detail, Node target) {
print("Setup started");
controller.checkInGlypto();
counter = controller.getTotal();
}
void resetCheckIn(Event e, var detail, Node target) {
print("reset started");
}
void loadCheckIn(Event e, var detail, Node target) {
print("load started");
controller.loadData();
counter = controller.getTotal();
}
}
the code can be downloaded here
factory MainApp.custom() { MainApp mainApp = new Element.tag('main-app'); mainApp.myConstructor();} void myConstructor() { print("myConstructor Started");}
but it seems myConstructor() is not executed. – ken Jan 03 '15 at 15:39