How to send field value in custom directive?
up vote
0
down vote
favorite
I have two field first and second.I added a custom directive in first field .But I able to get first field value in directive .I want “last” field value in same directive. I used attributes but it will not work here is my code
I added custom directive in "First field"
.directive("testfirst", function() {
return {
restrict: "A",
require: 'ngModel',
link: function(scope, element, attributes, modelVal) {
modelVal.$validators.testfirst= function(val) {
if(val.length > 0 && !(attributes.last && attributes.last.length < 4)){
return false
}
return true
};
scope.$watch("val", function() {
modelVal.$validate();
});
}
};
})
I want "last field value" here is custom directive .I used attribute but it not work
here is my code
http://plnkr.co/edit/EYsUDkG3Kne1mEfEI8GT?p=preview
javascript angularjs
add a comment |
up vote
0
down vote
favorite
I have two field first and second.I added a custom directive in first field .But I able to get first field value in directive .I want “last” field value in same directive. I used attributes but it will not work here is my code
I added custom directive in "First field"
.directive("testfirst", function() {
return {
restrict: "A",
require: 'ngModel',
link: function(scope, element, attributes, modelVal) {
modelVal.$validators.testfirst= function(val) {
if(val.length > 0 && !(attributes.last && attributes.last.length < 4)){
return false
}
return true
};
scope.$watch("val", function() {
modelVal.$validate();
});
}
};
})
I want "last field value" here is custom directive .I used attribute but it not work
here is my code
http://plnkr.co/edit/EYsUDkG3Kne1mEfEI8GT?p=preview
javascript angularjs
is there a good reason to useng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due tong-repeat
)
– Aleksey Solovey
Nov 13 at 9:49
what is better solutiom
– Joy
Nov 13 at 16:03
there is just a lot of dependancies and specific rules that makes it very difficult to work with usingng-repeat
. But it's up to you to design it
– Aleksey Solovey
Nov 13 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
please share an example
– Joy
Nov 13 at 16:28
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two field first and second.I added a custom directive in first field .But I able to get first field value in directive .I want “last” field value in same directive. I used attributes but it will not work here is my code
I added custom directive in "First field"
.directive("testfirst", function() {
return {
restrict: "A",
require: 'ngModel',
link: function(scope, element, attributes, modelVal) {
modelVal.$validators.testfirst= function(val) {
if(val.length > 0 && !(attributes.last && attributes.last.length < 4)){
return false
}
return true
};
scope.$watch("val", function() {
modelVal.$validate();
});
}
};
})
I want "last field value" here is custom directive .I used attribute but it not work
here is my code
http://plnkr.co/edit/EYsUDkG3Kne1mEfEI8GT?p=preview
javascript angularjs
I have two field first and second.I added a custom directive in first field .But I able to get first field value in directive .I want “last” field value in same directive. I used attributes but it will not work here is my code
I added custom directive in "First field"
.directive("testfirst", function() {
return {
restrict: "A",
require: 'ngModel',
link: function(scope, element, attributes, modelVal) {
modelVal.$validators.testfirst= function(val) {
if(val.length > 0 && !(attributes.last && attributes.last.length < 4)){
return false
}
return true
};
scope.$watch("val", function() {
modelVal.$validate();
});
}
};
})
I want "last field value" here is custom directive .I used attribute but it not work
here is my code
http://plnkr.co/edit/EYsUDkG3Kne1mEfEI8GT?p=preview
javascript angularjs
javascript angularjs
asked Nov 13 at 9:43
Joy
1097
1097
is there a good reason to useng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due tong-repeat
)
– Aleksey Solovey
Nov 13 at 9:49
what is better solutiom
– Joy
Nov 13 at 16:03
there is just a lot of dependancies and specific rules that makes it very difficult to work with usingng-repeat
. But it's up to you to design it
– Aleksey Solovey
Nov 13 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
please share an example
– Joy
Nov 13 at 16:28
add a comment |
is there a good reason to useng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due tong-repeat
)
– Aleksey Solovey
Nov 13 at 9:49
what is better solutiom
– Joy
Nov 13 at 16:03
there is just a lot of dependancies and specific rules that makes it very difficult to work with usingng-repeat
. But it's up to you to design it
– Aleksey Solovey
Nov 13 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
please share an example
– Joy
Nov 13 at 16:28
is there a good reason to use
ng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due to ng-repeat
)– Aleksey Solovey
Nov 13 at 9:49
is there a good reason to use
ng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due to ng-repeat
)– Aleksey Solovey
Nov 13 at 9:49
what is better solutiom
– Joy
Nov 13 at 16:03
what is better solutiom
– Joy
Nov 13 at 16:03
there is just a lot of dependancies and specific rules that makes it very difficult to work with using
ng-repeat
. But it's up to you to design it– Aleksey Solovey
Nov 13 at 16:06
there is just a lot of dependancies and specific rules that makes it very difficult to work with using
ng-repeat
. But it's up to you to design it– Aleksey Solovey
Nov 13 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
please share an example
– Joy
Nov 13 at 16:28
please share an example
– Joy
Nov 13 at 16:28
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278060%2fhow-to-send-field-value-in-custom-directive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is there a good reason to use
ng-repeat
? It seems like it's making a mess in your case. I think you want to pass the model of the last input field into the first with an attribute, but they share the same model name (due tong-repeat
)– Aleksey Solovey
Nov 13 at 9:49
what is better solutiom
– Joy
Nov 13 at 16:03
there is just a lot of dependancies and specific rules that makes it very difficult to work with using
ng-repeat
. But it's up to you to design it– Aleksey Solovey
Nov 13 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 at 16:19
please share an example
– Joy
Nov 13 at 16:28