AngularJS. unique field name



  • Hello. I need to call the shape fields always differently at every download of the page.

    It's a code:

    <input autocomplete="off" type="text" name="name" ng-model="model.LastName" required>
    <div ng-show="form.name.$invalid && form.name.$dirty">
        error
    </div>
    

    Trying to give names like name{{unique}} and name[{{unique}}] - Then the block doesn't show up after the input. How can such behaviour be realized?

    More grateful.

    UPDATE

    js (directive):

    app.directive('fioData', [function () {
    return {
        templateUrl: '/path/to/fioForm.html',
        replace: false,
        transclude: true,
        restrict: 'A',
        scope: {
            model: '=',
            formId: '@',
        },
        link: function ($scope, element, attrs) {
        }
    };
    }]);
    

    html:

    <div fio-data model="Data.Applicant" form-id="applicant"></div>
    


  • Use it. name{{unique}} a ng-show is such a design:

    form['name' + unique].$invalid
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2