次の Angular ディレクティブを作成しました。
angular.module('solarquote.directives', []).directive('editfield', function() {
return {
restrict: 'A',
transclude: true,
template: '<span ng-hide="editorEnabled" ng-transclude></span>' + // viewable field
'<span ng-show="editorEnabled"><input class="input-medium" ng-model="editableField"></span>', // editable field
link: function(scope, elm, attrs, ctrl) {
scope.editorEnabled = false;
scope.editableField = elm.children[0].children[0].innerText;
}
};
})
そしてhtmlのng-repeat内:
<span editfield>{{ item.fields.name }}</span>
ディレクティブのテンプレートの入力フィールドに、ng-transclude と同じ内容を事前入力したいと思います。DOM を通過してテキストを取得すると、レンダリングされたデータの代わりに {{ item.fields.name }} が生成されます: "Bob" (または任意の名前)。
トランスクルージョンされたデータにアクセスする最良の方法は何ですか?
ありがとう