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










share|improve this question






















  • 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










  • 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















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










share|improve this question






















  • 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










  • 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 at 9:43









Joy

1097




1097












  • 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










  • 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


















  • 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










  • 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
















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

















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',
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
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?