>Edit
如何设置此<input ng-model="this['newPlayer']['personal_info']['first_name']">
['newPlayer']['personal_info']['first_name']
动态地从变量?
像这样的东西:<input ng-model="this[variable]">
您不必从属性中获取它,只需将其添加到您的指令中即可require: 'ngModel'
喜欢这个
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]);
}
}
});
并且您在链接函数中为每个文本输入实例提供了不同的ngModel