Reputation: 2183
In an angular directive can you require form^ AND ngModel? Is it possible to access the form and controller within the linking function?
angular.module('myApp')
.directive('passwordValidation', passwordValidation)
function passwordValidation(){
return {
replace: true,
require: 'ngModel', // also 'form^' ?
scope: {
userName: '@'
},
link: function(scope, elem, attr, ctrl, form) {
...
Upvotes: 1
Views: 819
Reputation: 7156
Yes its possible by providing an array in require property. Using this, you will be provided with array of controllers as 4th argument in link function.
angular.module('myApp')
.directive('passwordValidation', passwordValidation)
function passwordValidation(){
return {
replace: true,
require: ['ngModel','^form'], // also 'form^' ?
scope: {
userName: '@'
},
link: function(scope, elem, attr, controllers) {
var ngModelCtrl = controllers[0],formCtrl = controllers[1];
}
}}
Upvotes: 3