Angularjs:2路绑定不包含模板工作

问题描述:

我想我失去了一些东西简单(重要)在这里。我使用包含的映射到某一值输入一个包含的模板:

I think I'm missing something simple (and important) here. I'm using an included template that contains an input that's mapped to some value:

<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>

控制器:

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

警报的$ scope.testvalue值始终显示初始值,而不是更新后的值(当你在输入型)。帮助我欧比旺。你是我们唯一的希望。

Alerting the value of $scope.testvalue always shows the initial value, not the updated value (when you type in the input). Help me Obi-Wan. You're our only hope.

小提琴: http://jsfiddle.net/h5aac/

这是太常见结合到原始的,而不是一个对象。字符串的值被围而不传递给一个对象的引用。如果您使用的对象,而不是原始的,它工作正常。像这样的事情在你的范围。

This is the all too common of binding to a primitive instead of an object. The value of the string gets passed around and not a reference to an object. If you use an object instead of a primitive, it works fine. Something like this in your scope.

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

请参阅 http://jsfiddle.net/h5aac/2/

还有:

Using在AngularJS

binding问题,当在ngRepeat 指令

AngularJS - 与异步响应更新范围值

我敢肯定有更多...

I'm sure there are more...