如何声明动态ng模型? angularjs

时间:2016-12-16 03:33:28

标签: angularjs dynamic controller angular-ngmodel

我试图进行动态输入。是否有可能通过索引获得动态ng模型?

See scrnsht here

据推测,应将上面的条形码ng模型设置为ng-model =" barcode_0"和ng-model =" barcode_1"

我已尝试过此代码,但它无效



//controller
console.log($scope['Barcode_' + index])

<!-- HTML -->
<input type="text" ng-model="Barcode_[$index]" class="form-control" placeholder="Stock ID" >
&#13;
&#13;
&#13; 任何人?请帮助

1 个答案:

答案 0 :(得分:1)

你走在正确的轨道上,你只需要对代码进行一些改动。

Private Sub buttonCreated_itemClick(sender As Object, e As ItemClickEventArgs) If formOfTarget.ContainsKey(CType(e, ItemClickEventArgs).Item.Name) Then Try Dim targetOfButton = formOfTarget.Item(CType(e, ItemClickEventArgs).Item.Name) Dim formCreated As Type = Type.[GetType]("namespace." + targetOfButton) Dim showForm As Form = TryCast(Activator.CreateInstance(formCreated), Form) showForm.MdiParent = Me showForm.Show() showForm.BringToFront() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End If End Sub 是数组Barcode_[$index]的元素。您只需在Barcode_initialize此数组,然后就可以在controller中使用$scope.Barcode_[0]$scope.Barcode_[1]来访问变量。

保持html代码原样,并且这是你的控制器:

controller

您可以在此控制器中访问此类变量:

$scope.Barcode_ = [];//initializing the array