Angular stuff how to add attribute to md-text-float directive
I am using material.angular for my custom form, the "name" is like this:
<md-text-float label="Username" ng-model="userEdit.user.nickname"></md-text-float>
And I want to add the "required" attribute to the previously created input, but it seems tricky, the stuff allows me to specify the type or the "disabled" attr, but nothing else.
Can I add an attribute after creating a field?
source to share
Now you can use the 'required' attribute on the element <md-text-float>
,
Working on version v0.6.1-master-fc723d4
If you need to pass other attributes to your element <input>
, you can use the following:
<md-input-group class="md-default-theme">
<label for="">something </label>
<md-input ng-model="myValue" ng-change="doSomethingOnChange()" ng-blur="doSomethingOnBlur()" autocapitalize="off" type=""></md-input>
</md-input-group>
working codepen
see this discussion on github
source to share
Until this problem is fixed, you can add attributes using a function link
inside your own directive.
Assuming you've created a directive myDirective
with a template containing an element md-text-float
, you can do the following:
angular.module ('myModule', [])
.directive ('myDirective', function () {
return {
// your own directive parameters
// ...
link: function (scope, element, attrs) {
element.find ('input').attr ('required', 'true');
}
};
});
source to share