ng-model

80 views
Skip to first unread message

Jeff Gardner

unread,
Aug 23, 2013, 5:46:26 PM8/23/13
to ang...@googlegroups.com
Hi I am trying to generate a form based on a model like 

<form ng-controller="SpotCtrl">
        <div ng-repeat="f in fields">
            <ng-form name="signFormIn">
                <input ng-show="f.type=='String'" type="text" ng-model="f.modelValue" ng-focus="onFocus()" ng-blur="onBlur()" ng-change="inputTextChange()" /><span ng-show="f.type=='String'">{{model.firstNameEditedBy}}</span>
                <input ng-show="f.type=='Boolean'" ng-model="f.modelValue" type="checkbox" ng-change="inputTextChange()">
                <input ng-show="f.type=='Enum'" id="radioA" ng-model="f.modelValue" ng-change="inputTextChange()" type="radio" name="f.name" value="A"><label ng-show="f.type=='Enum'">A</label>
                <select ng-show="f.type=='List'" ng-model="f.modelValue" ng-change="inputTextChange()" ng-options="option for option in question.Options" />
            </ng-form>
        </div>


$scope.fields = [
        { name: 'firstName', isRequired: true, type: "String", modelValue: "model.firstName"},
        { name: 'checkbox', isRequired: true, type: "Boolean", modelValue: "model.checkbox"},
        { name: 'comboBox', isRequired: false, type: "List", modelValue: "model.comboBox"},
        { name: 'radio', isRequired: false, type: "Enum", modelValue: "model.radio"},
        { name: 'dependentComboBox', isRequired: false, type: "List", modelValue: "model.dependentComboBox"}
    ];

where the model.value is set dynamically based on the data in the fields object.  However when I do this it doesn't bind to the model.  Is there something else I need to do.

Jeff Gardner

unread,
Aug 23, 2013, 6:40:04 PM8/23/13
to ang...@googlegroups.com
Let me clarify a little

so in my controller I have an object model which has a field firstName.  So if I create  an <input with ng-bind="model.firstname"> then the firstName property is changed as I type.  However if if I do an ng-repeat and set ng-bind=f.modelValue the input text is cound to f.modelValue not model.firstname.  Which the string modelValue = model.firstName.  Any ideas how to make this work?

Jeff Gardner

unread,
Aug 23, 2013, 7:35:11 PM8/23/13
to ang...@googlegroups.com
What I am trying to achieve is to create a dynamic form.
Reply all
Reply to author
Forward
0 new messages