再利用可能なコントロールを作成するために、AngularJS ディレクティブに OOP 継承を実装しようとしています。継承にはBase2 の Class 定義を使用しています。私が考えていたのは、このようなディレクティブを実装することでした
<control-input type="text" name="vendor_name"></control-input>
次にBaseControl
、共通機能のクラスを作成します
angular.module('base',[]).factory('BaseControl', function() {
return Base.extend({
'restrict': 'E',
'require': '^parentForm'
/* ... */
};
});
そして、特定のコントロールを作成します
angular.module('controls',['base']).factory('TextControl', function(BaseControl) {
return BaseControl.extend({
/* specific functions like templateUrl, compile, link, etc. */
};
});
問題は、単一のディレクティブを使用して属性でタイプを指定したいということですcontrol-input
が、問題は、ディレクティブを作成するときに、タイプを取得する方法がわからないことです
angular.module('controls',['controls']).directive('control-input', function(TextControl) {
/* here it should go some code like if (type === 'text') return new TextControl(); */
});
何か案は?