Accessing the DOM directly in $ scope is bad practice and should be avoided at all costs. In an MVC structure such as angular, instead of accessing the DOM (view), refer to models instead of ($ scope) to get your state and data. In your case, you bind the name of your directive to the orderselection property of your parent area. Also note that the form is an instance of FormController . An instance of a form may optionally be published to a scope using the name attribute. In your case, you create a new property in the parent scope.
You can try to access the name like this if you are in your parent area:
console.log( $scope.myform.orderselection );
Or if you are in the scope of your directive.
console.log( $scope.name);
Since the property of your scope name directive is associated with the property of the parent orderselection , you need to assign a value to the property of the parent scope or it will be undefined. Like this:
$scope.myform.orderselection = "orderselection ";
If you need to check inside your directive, since you are already binding the name attribute with orderselection . You can do it as follows:
template : "<select class='form-control' ng-attr-name='{{name}}' ng-disabled='[name].$invalid' .../>
Khanh to
source share