I am encountering a problem with the ng-model
value in an element that uses AngularStrap's bs-typeahead
. It seems to not be accessible within the scope, but it works fine when accessed using {{ var }}
in the HTML.
Here is the HTML code:
<input type="text" placeholder="add a destination" ng-options="item as item for item in modelTypeahead" ng-model="selectedDestination" bs-typeahead data-template="templates/SrcDstTypeaheadTemplate.html">
I set the initial value for the variable in my controller:
$scope.selectedDestination = "";
When I place {{ selectedDestination }}
elsewhere in the HTML, it displays as expected.
However, if I
console.log($scope.selectedDestination);
in my controller, it shows an empty string.
If I change the initialization to something like:
$scope.selectedDestination = "abc123";
... both the <input>
field and the {{ selectedDestination }}
display the updated value. The console.log
also shows the correct value. However, if I update the typeahead, the {{ selectDestination }}
updates but the console.log
still shows 'abc123'.
Could there be a scope issue that I am overlooking? I am confused as to why {{ selectedDestination }}
displays correctly but the console.log
shows something different. It almost seems like the binding is one-way, even though AngularStrap's bs-typeahead
should be two-way based on the examples.