1

値がディレクティブで機能する方法について質問があります。テンプレートを持つ 1 つのディレクティブがあり、同じテンプレートで (グローバルに定義された) JavaScript 関数を呼び出し、その JavaScript 関数にディレクティブから取得した値を渡したい(少し混乱するかもしれません)。これがサンプルコードです。

angular.module("Shell").directive("myFormField", function () {
return {
    scope: {
        text: "@",
        required: "@",
    },
    transclude: true,
    replace: true,
    template:
        '<div>' +
        '<label style="white-space: nowrap;font-weight: normal;width: 100% !important">'+globalLoadText(text)+
        '<div style="margin-top: 1.5px;" ng-transclude />' +
        '</label>' +
        '</div>'
};
});

globalLoadText() は、Angular の外側 (ルート スコープにある通常の js ファイル内) で定義されたグローバル メソッドです。テキストは、ディレクティブから取得する値になります。

私の質問を明確に書き留めていただければ幸いです。どんな助けでも大歓迎です。ありがとう!!

4

1 に答える 1