Skip to main content
added 11 characters in body
Source Link

My goal was to use dependency injection of a constant value (the base URL) to use in defining the component's templateUrl property. Nothing so far has worked, including a pattern we use for our controllers (shown in. The code below). is in Typescript

Some explanation: app.core.Iconstants holds the baseUrl value. app.core.AngularGlobals.appCoreConstants is the string representing "app.core.Constants".

Mind you, I'm just cutting my teeth of Angular. Code follows I'm aware that I probably can't use a function call in the module assignment as opposed to new'ing up the class and relying on the constructor, but desperate measures call for...well, you know the rest.

namespace donationEntry.Components{ "use strict";

class test1 implements ng.IComponentOptions {
    public static id: string = AngularGlobals.donationEntry + ".test1";
    bindings: any;
    controller: any;
    templateUrl: string;
    
    constructor(private clientContext: app.core.IConstants) {
        this.bindings = {
            textBinding: '@',
            dataBinding: '<',
            functionBinding: '&'
        };
        this.controller = TestController;
        this.templateUrl = clientContext.baseUrl + "Areas/ng/app/fundraising/donationEntry/components/test1/test1.html";
    }

    public static injection(): any[] {
        return [app.core.AngularGlobals.appCoreConstants, (c) => new test1(c)];
    }
}

// register the controller with app
angular.module(AngularGlobals.donationEntry)
    .component("test1", test1[app.injectioncore.AngularGlobals.appCoreConstants, (c) => new test1(c)]);

}

When I run this, I end up with the following error:

angular.js:61 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module donationEntry due to: TypeError: t.charAt is not a function

My goal was to use dependency injection of a constant value (the base URL) to use in defining the component's templateUrl property. Nothing so far has worked, including a pattern we use for our controllers (shown in code below).

Some explanation: app.core.Iconstants holds the baseUrl value. app.core.AngularGlobals.appCoreConstants is the string representing "app.core.Constants".

Mind you, I'm just cutting my teeth of Angular. Code follows I'm aware that I probably can't use a function call in the module assignment as opposed to new'ing up the class and relying on the constructor, but desperate measures call for...well, you know the rest.

namespace donationEntry.Components{ "use strict";

class test1 implements ng.IComponentOptions {
    public static id: string = AngularGlobals.donationEntry + ".test1";
    bindings: any;
    controller: any;
    templateUrl: string;
    
    constructor(private clientContext: app.core.IConstants) {
        this.bindings = {
            textBinding: '@',
            dataBinding: '<',
            functionBinding: '&'
        };
        this.controller = TestController;
        this.templateUrl = clientContext.baseUrl + "Areas/ng/app/fundraising/donationEntry/components/test1/test1.html";
    }

    public static injection(): any[] {
        return [app.core.AngularGlobals.appCoreConstants, (c) => new test1(c)];
    }
}

// register the controller with app
angular.module(AngularGlobals.donationEntry)
    .component("test1", test1.injection());

}

My goal was to use dependency injection of a constant value (the base URL) to use in defining the component's templateUrl property. Nothing so far has worked. The code below is in Typescript

Some explanation: app.core.Iconstants holds the baseUrl value. app.core.AngularGlobals.appCoreConstants is the string representing "app.core.Constants".

Mind you, I'm just cutting my teeth of Angular.

namespace donationEntry.Components{ "use strict";

class test1 implements ng.IComponentOptions {
    public static id: string = AngularGlobals.donationEntry + ".test1";
    bindings: any;
    controller: any;
    templateUrl: string;
    
    constructor(clientContext: app.core.IConstants) {
        this.bindings = {
            textBinding: '@',
            dataBinding: '<',
            functionBinding: '&'
        };
        this.controller = TestController;
        this.templateUrl = clientContext.baseUrl + "Areas/ng/app/fundraising/donationEntry/components/test1/test1.html";
    }
}

// register the controller with app
angular.module(AngularGlobals.donationEntry)
    .component("test1", [app.core.AngularGlobals.appCoreConstants, (c) => new test1(c)]);

}

When I run this, I end up with the following error:

angular.js:61 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module donationEntry due to: TypeError: t.charAt is not a function

Source Link

Angular 1.5 Component - dependency injection

My goal was to use dependency injection of a constant value (the base URL) to use in defining the component's templateUrl property. Nothing so far has worked, including a pattern we use for our controllers (shown in code below).

Some explanation: app.core.Iconstants holds the baseUrl value. app.core.AngularGlobals.appCoreConstants is the string representing "app.core.Constants".

Mind you, I'm just cutting my teeth of Angular. Code follows I'm aware that I probably can't use a function call in the module assignment as opposed to new'ing up the class and relying on the constructor, but desperate measures call for...well, you know the rest.

namespace donationEntry.Components{ "use strict";

class test1 implements ng.IComponentOptions {
    public static id: string = AngularGlobals.donationEntry + ".test1";
    bindings: any;
    controller: any;
    templateUrl: string;
    
    constructor(private clientContext: app.core.IConstants) {
        this.bindings = {
            textBinding: '@',
            dataBinding: '<',
            functionBinding: '&'
        };
        this.controller = TestController;
        this.templateUrl = clientContext.baseUrl + "Areas/ng/app/fundraising/donationEntry/components/test1/test1.html";
    }

    public static injection(): any[] {
        return [app.core.AngularGlobals.appCoreConstants, (c) => new test1(c)];
    }
}

// register the controller with app
angular.module(AngularGlobals.donationEntry)
    .component("test1", test1.injection());

}