0

Imagine a simple variable string in a controller MyCtrl:

$scope.simpleString = 'hi i am your simple string!';

which is the the Angular model of a simple text input:

<input type="text" ng-model="simpleString">

This input now is used in two different views part1 and part2:

<div ng-controller="MyCtrl">
    <div ng-include="'part1'"></div>
    <div ng-include="'part2'"></div>
</div>

Using two different views seems to break my databinding although it is supposed to be in the MyCtrl scope.

Info: I also tried to use ui-view but it boils down to the very same thing.

DonJuwe
  • 4,477
  • 3
  • 34
  • 59

1 Answers1

1

you need to set $scope.simpleString to be an object like this:

$scope.data = {
  simpleString: 'John'
}

that'll prevent the variables from shadowing one another. I wrote an answer relating this here

Community
  • 1
  • 1
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52