0

I created directive for form controls, that gets created in loop. I pass name of element dynamically. Same approach I want to use to create ng-model name but its not working

HTML

<div ng-repeat="que in questions[$state.current.name]">
                        <div ng-if="que.QuestionData._fieldType === 'text'" >
                            <!-- {{answers[que.QuestionData._attributeName]}} -->
                            <text-control-dir data="que.QuestionData" default="answers.PC_1" ></text-control-dir>
                        </div>  
                        <div ng-if="que.QuestionData._fieldType === 'select'" >
                            <select-control-dir data="que.QuestionData"></select-control-dir>
                        </div>
                        <div ng-if="que.QuestionData._fieldType === 'radio'" >
                            <radio-control-dir data="que.QuestionData"></radio-control-dir>
                        </div>
                        <div ng-if="que.QuestionData._fieldType === 'hidden' && que.QuestionData._attributeName != 'CBQ'" >
                            <hidden-control-dir data="que.QuestionData"></hidden-control-dir>
                        </div>
                    </div>

controlDirective.js

        function textControlDir()
    {
        return {
            transclude: true,
            restrict: 'E',
            scope: {
                data: '=data'
            },
            template: '<div class="form-group">\n\
<label for="{{data._attributeName}}" class="col-sm-5 control-label">{{data._text}}</label>\n\
<div class="col-sm-6"><input ng-model="answers[data._attributeName]"  type="text" name="{{data._attributeName}}" class="form-control" id="{{data._attributeName}}" value="{{data._pageAttributes.defaultValue}}"></div>\n\
</div>'
            ,
            link: function (scope, element, attrs)
            {

            }
        };
    }

Here I am trying to make ng-model="answers[data._attributeName]" in text box

plunker http://plnkr.co/edit/Op1QDwUBECAosPUC7r3N?p=preview

Praveen D
  • 2,337
  • 2
  • 31
  • 43
  • See this thread http://stackoverflow.com/questions/14115701/angularjs-create-a-directive-that-uses-ng-model – spyshiv Jul 21 '16 at 11:28
  • I updatewd plunker accordigly http://plnkr.co/edit/Op1QDwUBECAosPUC7r3N?p=preview but no luck. it show object name instead of value – Praveen D Jul 21 '16 at 11:51

0 Answers0