丢失范围内的ng-include in angularJS

时间:2016-08-02 13:54:52

标签: javascript angularjs angularjs-directive scope angularjs-scope

我正在尝试将范围传递给ng-include但是当我将其插入ng-include时它似乎不起作用。当我把它放在ng-include之外时...我得到了正确的结果但是当我将它插入ng-include时我的div没有显示出来。当我将范围插入ng-include?时,我失去范围的任何原因

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

$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

<div ng-show="ddValue1.value=='value1'">
    <h1>Value 1</h1>
</div>

2 个答案:

答案 0 :(得分:2)

<div ng-include=ddValue1.url></div>

试试吧。可能是单个qoute,认为它是strinf = g而不是你的范围属性

答案 1 :(得分:0)

尝试:

ng-options="d as d.text for d in ddOptions1 track by d.value"

如果它不起作用,请告诉我。