Для input
.directive('useFormData', function ($parse) {
return {
link: function (scope, element, attrs) {
if (attrs.ngModel && attrs.value) {
$parse(attrs.ngModel).assign(scope, attrs.value);
}
}
};
});
<input type="text" ng-model="title" value="default value" use-form-data />
Для textarea
.directive('useFormData', function ($parse) {
return {
link: function (scope, element, attrs) {
if (attrs.ngModel && element[0].defaultValue) {
$parse(attrs.ngModel).assign(scope, element[0].defaultValue);
}
}
};
});