[英]Losing scope inside ng-include in angularJS
I am trying to pass a scope into ng-include but it doesn't seem to work when I insert it into ng-include. 我正在尝试将范围传递给ng-include,但是当我将其插入ng-include时似乎不起作用。 when I put it outside the ng-include... I get the right result but my div doesn't show up when I insert it into ng-include. 当我将其放在ng-include之外时...我得到了正确的结果,但是当我将其插入ng-include时却没有显示div。 Any reason why I am losing the scope when I insert the scope inside ng-include? 在ng-include内插入范围时,为什么会丢失范围?
Index.html: Index.html:
<select ng-model="ddValue1"
ng-options="d.text for d in ddOptions1 track by d.value">
</select>
<div ng-include="'{{ddValue1.url}}'"></div>
JS: JS:
$scope.ddOptions1 = [
{value: 'value1', text: 'Text1', url: 'file path here'},
{value: 'value2', text: 'Text2', url: 'file path here'}
];
$scope.ddValue1 = {};
$scope.ddValue1.value = $scope.ddOptions1[0].value;
Newdiv.html Newdiv.html
<div ng-show="ddValue1.value=='value1'">
<h1>Value 1</h1>
</div>
<div ng-include=ddValue1.url></div>
Try it. 试试吧。 May be single qoute considering it as strinf=g rather than your scope propery 可能是单个qoute,将其视为strinf = g而不是您的范围属性
Try: 尝试:
ng-options="d as d.text for d in ddOptions1 track by d.value"
Let me know if it does not work. 让我知道它是否无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.