我創建了一個使用模板的指令,使用此指令後,input type = radio不再更新模型。普通文本類型可以正常工作。輸入無線電沒有更新模型
我該怎麼做才能保持模型更新?
app.directive('advformInput', function($compile) {
return {
restrict: 'A',
priority: 1002,
transclude: true,
replace: true,
template: [
'<div class="advform-input form-group">',
' <label class="advform-lbl">',
' <input class="form-control" />',
' <div class="helper" ng-show="advformInput">{{ advformInput }}</div>',
' </label>',
'</div>'
].join('\n'),
scope: {
advformInput: '@'
},
link: function ($scope, tElement, tAttrs, $ctrls) {
var ar = ['type', 'name', 'ng-model', 'value'];
var block = tElement, inp = tElement.find('input');
$scope.field = tAttrs.advformInput;
tElement.removeAttr('advform-input')
// transfer some attributes to the real input
_.each(ar, function(val, key){
inp.attr(val, block.attr(val))
block.removeAttr(val)
})
// add the type of the input to the div like a class
block.addClass('inp-' + inp.attr('type'));
//$compile(inp)($scope);
}
};
});