I am using AngularUI Typeahead on the index page of my application. I am not doing anything unusual - in fact, I'm just trying to get the example that they got on the UI workstation, and I get this error:
Error: Template must have exactly one root element
I have no idea what this means, but this only happens when I have the following code:
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue">
If appropriate, my controller for my main page (which is called via $routeProvider for the / index directory):
function indexCtrl($scope, $location, $resource) { $scope.selected = undefined; $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']; }
Note that the rest of the controller on the page is working perfectly, and just $scope.selected/$scope.states is causing problems. I canโt understand what the error means, so troubleshooting is quite difficult!
Any ideas?
EDIT Here is my HTML template:
<html ng-app="myApp" class="ng-scope"> <head> // Head stuff, probably irrelevant </head> <body> <div class="container"> <div ng-view="" class="row-fluid"> <form class="row-fluid"> <div class="container-fluid"> <input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue"> </div> </form> </div> </div> // A bunch of Angular scripts are here </body> </html>
It is definitely associated with a typeahead script, I can remove typeahead="state for state in states | filter:$viewValue" , and the script works (although, obviously, the typeahead function typeahead not ...)