user4756836
user4756836

Reputation: 1337

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. 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. Any reason why I am losing the scope when I insert the scope inside 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>

Upvotes: 0

Views: 177

Answers (2)

Akash Bhandwalkar
Akash Bhandwalkar

Reputation: 901

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

Try it. May be single qoute considering it as string rather than your scope propery

Upvotes: 2

YOU
YOU

Reputation: 123927

Try:

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

Let me know if it does not work.

Upvotes: 0

Related Questions