私の目標は、コンポーネントのtemplateUrlプロパティの定義に使用する定数値(ベースURL)の依存性注入を使用することでした。これまでのところ何も働いていません。下のコードはTypescriptにあります角度1.5コンポーネント依存性注入
説明:app.core.IconstantsはbaseUrl値を保持しています。 app.core.AngularGlobals.appCoreConstantsは、「app.core.Constants」を表す文字列です。
私はちょうどあなたの歯を角切りしています。
名前空間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)]);
}
私はこれを実行すると、私は次のエラーで終わる:
angular.js:61不明なエラー:[$インジェクター:modulerr]は起因するモジュールのアプリをインスタンス化に失敗しました: エラー:[$インジェクター:modulerr]起因するモジュールdonationEntryをインスタンス化できませんでした: 例外TypeError:私は答えの最も雄弁にそれを呼び出すことはありませんけれどもt.charAtは関数ではありません
は、あなたがのcharAtを持っていないオブジェクト上のcharAtを呼び出す言うが、私はどこかのcharAtが表示されませんあなたが提供したスニペットでは、これが問題のどこにあるのでしょうか? –
問題を回避して、私は深く掘り下げたことはありませんが、私が使用したショートカットインジェクション構文に関連しているようです。 –