diff --git a/docs/content/guide/di.ngdoc b/docs/content/guide/di.ngdoc index f0ac64c8c290..b59873f8042b 100644 --- a/docs/content/guide/di.ngdoc +++ b/docs/content/guide/di.ngdoc @@ -14,7 +14,8 @@ and providing them to other components as requested. ## Using Dependency Injection -Dependency Injection is pervasive throughout AngularJS. You can use it when defining components +Dependency Injection is pervasive throughout AngularJS. +You can use it when defining components or when providing `run` and `config` blocks for a module. - {@link angular.Module#service Services}, {@link angular.Module#directive directives}, @@ -283,9 +284,13 @@ Here is an example of using the injector service: // Provide the wiring information in a module var myModule = angular.module('myModule', []); ``` +Notice that `myModule` depends upon no other modules as the second parameter is an empty array. +Dependent is always need dependency object to be injected inside it. +Notice that `myModule` depends upon no other modules as the second parameter is an empty array. Teach the injector how to build a `greeter` service. Notice that `greeter` is dependent on the `$window` service. The `greeter` service is an object that contains a `greet` method. +so, injector now injects `$window` dependency inside `greeter` service. ```js myModule.factory('greeter', function($window) { diff --git a/src/ng/directive/validators.js b/src/ng/directive/validators.js index 5c1649ecf74e..e929da660af0 100644 --- a/src/ng/directive/validators.js +++ b/src/ng/directive/validators.js @@ -68,9 +68,11 @@ var requiredDirective = ['$parse', function($parse) { require: '?ngModel', link: function(scope, elm, attr, ctrl) { if (!ctrl) return; - var value = attr.required || $parse(attr.ngRequired)(scope); + var value = 'required' in attr || $parse(attr.ngRequired)(scope); - attr.required = true; // force truthy in case we are on non input element + if (!attr.ngRequired) { + attr.required = true; + } // force truthy in case we are on non input element ctrl.$validators.required = function(modelValue, viewValue) { return !value || !ctrl.$isEmpty(viewValue);