I can not instantiate class with parameters compiling with aot

1

Versions.

TUDO ATUALIZADO NA DATA DE HOJE (2017-08-23)
@angular/cli: 1.3.1
node: 8.3.0
os: win32 x64
@angular/animations: 4.3.5
@angular/common: 4.3.5
@angular/compiler: 4.3.5
@angular/core: 4.3.5
@angular/forms: 4.3.5
@angular/http: 4.3.5
@angular/platform-browser: 4.3.5
@angular/platform-browser-dynamic: 4.3.5
@angular/router: 4.3.5
@angular/cli: 1.3.1
@angular/compiler-cli: 4.3.5
@angular/language-service: 4.3.5
Method 1 COM Parameters - Compile COM ERROR Using

ng build --prod ( with aot )

and SEM ERROR when compiling using

ng build --prod --aot=false (sem aot)

no service:

@Injectable()
export class MvsTest {
    public Test: string = "";
    constructor(param: string) { 
        this.Test = param; 
    }
}

in the other service

@Injectable()
export class ApplicationService {
    public test1 = new MvsTest ('New1');
    public test2 = new MvsTest ('New2');
    constructor() { }
}

Method 2 WITHOUT parameter - Compile WITHOUT ERROR using ng build --prod (with aot) and WITHOUT ERROR when compiling using ng build --prod --aot=false

no service:

@Injectable()
export class MvsTest {
    public Test: string = "";
    constructor() { }
}

in the other service

@Injectable()
export class ApplicationService {
    public test1 = new MvsTest ();
    public test2 = new MvsTest ();
    constructor() {
        this.test1.Test= 'New1';
        this.test2.Test= 'New2';
    }
}

Error log.

ERROR in Can't resolve all parameters for MvsTest in C:/DEVELOPER/_SHARED/mvs-test/mvs-test.service.ts: (?).
    ERROR in ./src/main.ts..... etc...etc...etc... 
    ERROR in Can't resolve all parameters for MvsTest in C:/DEVELOPER/src/app/_SHARED/mvs-test/mvs-test.service.ts: (?).
    ERROR in ./src/main.ts
    Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\DEVELOPER\src'
    resolve './$$_gendir/app/app.module.ngfactory' in 'C:\DEVELOPER\src'
      using description file: C:\DEVELOPER\package.json (relative path: ./src)
        Field 'browser' doesn't contain a valid alias configuration
      after using description file: C:\DEVELOPER\package.json (relative path: ./src)
        using description file: C:\DEVELOPER\package.json (relative path: ./src/$$_gendir/app/app.module.ngfactory)
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory.ts doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory.js doesn't exist
          as directory
            C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory doesn't exist
    [C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory]
    [C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory.ts]
    [C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory.js]
    [C:\DEVELOPER\src\$$_gendir\app\app.module.ngfactory]
     @ ./src/main.ts 3:0-74
     @ multi ./src/main.ts

Desired functionality.

I need to instantiate the class with parameters because it is more laborious to have to instantiate without the parameter and then set the parameter. When we create many inherited classes, the code doubles in size if you have to create and then set. There will be many instances and I wish the code very clean. I want to compile with aot.

I know I can create and set the property later but I would really like a solution where I can instantiate the class already with the parameter.

But ... this does not solve what I really need, but does it exist provisionally as I create something like this hypothetical example ?:

public test1 = new MvsTest().Test = 'Test1';  // **(hypothetical example)**

Thank you very much

    
asked by anonymous 23.08.2017 / 15:46

0 answers