gpt4 book ai didi

javascript - 动态更改 ng-bind 和 ng-model

转载 作者:行者123 更新时间:2023-12-01 05:37:50 34 4
gpt4 key购买 nike

我需要帮助。我有一个项目,我需要动态复制 html 节点。这些节点具有 ng-bind 和 ng-model 属性,如下所示:

<input class="quest_model" type="text" data-ng-model="quest">
<span ng-bind="quest" class="quest_bind"></span>

我可以像这样使用 Jquery 更改此属性:

quest.find("span.quest_bind").attr("ng-bind", "quest" + seq);

但是,当我按下按钮来复制节点时,AngularJS(ng-bind) 的魔力并没有发生。有人可以帮助我吗?

最佳答案

使用 json 对象

$scope.quest = {
'this': 'some random value',
'that': 'some other value'
}
$scope.seq = 'this'

那么你所要做的就是在 Controller 中引用 json 对象

<span ng-bind="quest[seq]" class="quest_bind"></span>

将输入的 ng-model 设置为 $scope.seq,这将允许您控制 span 元素绑定(bind)到的内容。

<input class="quest_model" type="text" ng-model="seq">

因此,如果您在输入框中键入“that”,它会将span标签绑定(bind)到$scope.quest.that,它等于“某个随机值”

同样,如果您在输入框中键入“this”,它会将span标签绑定(bind)到$scope.quest.this,它等于“其他值”

关于javascript - 动态更改 ng-bind 和 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788068/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com