我在應用程序的'index'頁面上使用AngularUI Typeahead時,「錯誤:模板必須只有一個根元素」。我沒有做任何幻想 - 實際上,我只是試圖讓他們有在他們的UI現場工作的例子,我得到這個錯誤:AngularJS - 當使用Angular-UI Typeahead
Error: Template must have exactly one root element
我不知道這意味着什麼,但它只是發生時,我有以下代碼:
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue">
如果相關,我控制我的主頁(這是通過$routeProvider
呼籲/
索引目錄):
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'];
}
請注意,頁面上的其他控制器工作得很好,這只是造成問題的$scope.selected/$scope.states
。我無法弄清楚錯誤的含義,所以排除故障相當困難!
任何想法?
編輯這裏是我的HTML模板:
<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>
這肯定與OT的typeahead
劇本,我可以刪除typeahead="state for state in states | filter:$viewValue"
和腳本作品(雖然很明顯的typeahead
功能不...)
什麼是'輸入(類型=「文本」,NG-模型=「選擇」,提前鍵入=「|:$ viewValue過濾器狀態狀態狀態」中受益)',是不是''? –
@YeLiu哦,道歉,這是ExpressJS使用的'Jade'模板引擎的一部分。它就像你說的那樣呈現,我會更新這個問題來反映這一點。 – Jascination
發佈您的HTML /模板,因爲錯誤是關於模板。 –