Requirements background:When you use a component directive that you write in a form, you want to manipulate the controls in the form by using the form ' s name. such as using $invalid and so on to ng-disabled btn.
Solution Solutions:by using form. $addControl control controls are registered in a form, either using the form's name.xxx. $invalid mode.
Specific methods:
Tw.directive (' Nameforform ', function () { return { restrict: ' A ', require: "? Ngmodel", link:function ($scope, Elem, Attrs, Ngmodelctrl) { var formcontroller = elem.controller (' form ') | | { $addControl: Angular.noop }; Ngmodelctrl. $name = Attrs.workflownameforform; Formcontroller. $addControl (Ngmodelctrl); $scope. $on (' $destroy ', function () { formcontroller. $removeControl (Ngmodelctrl); }); return true; } }; });
How to use:Component:
<div class= "Btn-group select Select-block mbn" > ... <input type= "text" ng-show= "false" ng-model= "SelectedValue" ng-required= "selectrequired" name-for-form= "{{ Nameforform}} "/></div>
Note: Introduction of Nameforform in Component, and add Nameforform in scope: ' @ '
Page Use component:
<tw-select-list name-for-form= "City" .../>
Reference: Http://www.ngnice.com/posts/81c1eb92bfbde0
AngularJS Form $addControl Register control