How to send field value in custom directive?
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 |
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 '18 at 9:49
what is better solutiom
– Joy
Nov 13 '18 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 '18 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
please share an example
– Joy
Nov 13 '18 at 16:28
add a comment |
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 '18 at 9:43
JoyJoy
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 '18 at 9:49
what is better solutiom
– Joy
Nov 13 '18 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 '18 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
please share an example
– Joy
Nov 13 '18 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 '18 at 9:49
what is better solutiom
– Joy
Nov 13 '18 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 '18 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
please share an example
– Joy
Nov 13 '18 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 '18 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 '18 at 9:49
what is better solutiom
– Joy
Nov 13 '18 at 16:03
what is better solutiom
– Joy
Nov 13 '18 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 '18 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 '18 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
please share an example
– Joy
Nov 13 '18 at 16:28
please share an example
– Joy
Nov 13 '18 at 16:28
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 at 9:49
what is better solutiom
– Joy
Nov 13 '18 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 '18 at 16:06
can you share you plunker with better solution
– Joy
Nov 13 '18 at 16:19
please share an example
– Joy
Nov 13 '18 at 16:28