angularjs - Conditionally require fields within a directive -


i have list of credit cards user can choose edit. credit card form bound list , form shown if select edit on given card. credit card form custom directive. user can add new card. usual fields required if credit card form visible, should not required/validated if it's not visible. visibility managed ng-show.

here simplified version of directive usage. directive simple you'd expect.

<div data-ng-repeat="profile in paymentprofiles" data-ng-show="profile.paymentprofileguid == selectedpaymentprofile && options.enablecreditcardedit">     <creditcard-widget title="enter card information"            card="profile" isrequired="profile.paymentprofileguid == selectedpaymentprofile && options.enablecreditcardedit"></creditcard-widget> </div> 

i've tried binding isrequired in two-way, one-way, , text. works text , if pass value instead of expression. how can pass flag directive @ least one-way data bound?

edit i've tried passing param "@", "&", , "=". i'm trying reduce things enough post jsfiddle or plukr link. here directive js:

.directive('creditcardwidget', function () {     return {         controller: 'creditcardwidgetcontroller',         restrict: 'e, a',         templateurl: '/app/views/partials/creditcardwidget.html',         scope: {             card: "=card",             types: "=",             months: "=months",             years: "=years",             title: "@",             opt: "&",             prefix: "@",             isrequired: "&"         }     }; }); 

edit 2

here simplified plnkr

here working fiddle uses &. see different have.

app.directive('creditcardwidget', function () {     return {         restrict: 'ea',         template: '<div>isrequired={{isrequired()}}</div>',         scope: {             // ...             isrequired: "&"         },         link: function(scope, element, attrs) {             console.log('link: isrequired=', scope.isrequired());         }     }; }); 

function myctrl($scope) {     $scope.paymentprofiles = [        { paymentprofileguid: 22}     ];     $scope.selectedpaymentprofile = 22;     $scope.options = {enablecreditcardedit: true}; } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

javascript - addthis share facebook and google+ url -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -