0

Edit

How to set for this <input ng-model="this['newPlayer']['personal_info']['first_name']"> the ['newPlayer']['personal_info']['first_name'] dynamically from variable?

Something like this: <input ng-model="this[variable]">

4
  • didn't understand what do you mean by 'hardcoded' Commented Oct 19, 2018 at 9:41
  • I have edited the question Commented Oct 19, 2018 at 10:12
  • so you don't need this to be in scope of custom component anymore, do you? Commented Oct 19, 2018 at 10:13
  • I need - but I know how I can send the name of the model I need to the child directive/component. I just don't know how to apply it in the html... I can to console.log($attrs.whatEverISent) and it will be results just okay. But how to send the whatEverISent to the ng-model directive in the actual input tag? Commented Oct 19, 2018 at 10:15

1 Answer 1

2

You don't have to get it from the attributes just add this to your directive require: 'ngModel' like this

app.directive("textInput", () => {
  return {
    templateUrl: "/text-input.html",
    require: 'ngModel'
    scope: true,
    link: function($scope, $element, $attrs, ngModel) {
      angular.element($element).append($scope[$attrs.myModel]);
    }
  }
});

and you have your different ngModel for each textInput instance in link function

Sign up to request clarification or add additional context in comments.

3 Comments

No.. this is not the problem - What to write in the HTML of the directive?
I got the data via $attrs and via the required key anyway - but how to assign the value to the ng-model?
check this article on using ngModel in your custom components: codelord.net/2017/07/28/youre-not-using-ng-model-enough

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.