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