我正在努力解决AngularJS指令的问题。
我尝试将所有相关代码复制到JSFiddle:http://jsfiddle.net/roger21/07mje0uw/1/,但发现它只适用于Chrome。
该指令具有如下定义的隔离范围:
this.scope = {
values: "=",
min: "@",
max: "@",
step: "@"
};
控制器范围包含它绑定的值:
$scope.response = [
{
"Day": "Monday",
"Times":
[
{ "Time": "06:00:00", "Temperature": 16.5 },
{ "Time": "08:00:00", "Temperature": 21.0 },
{ "Time": "18:00:00", "Temperature": 21.0 },
{ "Time": "22:00:00", "Temperature": 16.5 }
]
},
{
"Day": "Tuesday",
"Times":
[
{ "Time": "06:00:00", "Temperature": 16.5 },
{ "Time": "08:00:00", "Temperature": 21.0 },
{ "Time": "18:00:00", "Temperature": 21.0 },
{ "Time": "22:00:00", "Temperature": 16.5 }
]
}];
然后按如下方式创建指令:
<div data-slider data-values="response[0].Times" data-min="0" data-max="1440" data-step="5"></div>
移动滑块时,它会更新指令中的values
属性,然后按预期更新控制器中的对象。
但是现在我添加了该指令的第二个实例:
<div data-slider data-values="response[0].Times" data-min="0" data-max="1440" data-step="5"></div>
<div data-slider data-values="response[1].Times" data-min="0" data-max="1440" data-step="5"></div>
现在当我移动时,第一个滑块实际上是绑定到response[1].Times
的值,它会更新该对象的值!
在这里隔离范围我必须缺少一些东西吗?