gpt4 book ai didi

Angularjs:2路绑定(bind)在包含的模板中不起作用

转载 作者:行者123 更新时间:2023-12-03 14:35:26 25 4
gpt4 key购买 nike

我想我在这里遗漏了一些简单(且重要)的东西。我正在使用一个包含的模板,其中包含一个映射到某个值的输入:

<div ng-controller="Ctrl">
<div ng-include src="'template.html'"></div>
</div>

<!-- template -->
<script type="text/ng-template" id="template.html">
<input ng-model="testvalue" />
</script>

Controller :
function Ctrl($scope) {    
$scope.testvalue= "initial value";
}​

提醒 $scope.testvalue 的值始终显示初始值,而不是更新后的值(当您输入输入时)。帮帮我欧比旺。你是我们唯一的希望。

fiddle : http://jsfiddle.net/h5aac/

最佳答案

这是绑定(bind)到基元而不是对象的常见做法。字符串的值被传递而不是对对象的引用。如果您使用对象而不是原语,它可以正常工作。在你的范围内有这样的东西。

$scope.foo = {testvalue: "initial value"};

http://jsfiddle.net/h5aac/2/

还:

Using `ng-model` within a transcluded directive in AngularJS

binding issue when a directive in a ngRepeat

AngularJS - updating scope value with asynchronous response

我敢肯定还有更多...

关于Angularjs:2路绑定(bind)在包含的模板中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13848071/

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